-
Notifications
You must be signed in to change notification settings - Fork 11
SUBottomModal and SUCenterModal #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…osed using `isPresented` or `item` bindings
VislovIvan
approved these changes
Dec 2, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces the implementation of center and bottom modals for SwiftUI.
Shared Components
ModalOverlayA reusable view that displays the overlay behind the modal, supporting styles like dimming or transparency.
ModalContentA reusable view that structures and displays the content of the modal, including optional header, body, and footer sections.
Center Modal
SUCenterModalImplements a modal view that aligns its content in the center of the screen.
View Modifiers:
func centerModal(isPresented:model:onDismiss:)Public API for displaying a center modal. The presentation state is controlled using a
Boolbinding.func centerModal(item:model:onDismiss:)Public API for displaying a center modal when an optional
itemis non-nil.Bottom Modal
SUBottomModalImplements a modal view that aligns its content at the bottom of the screen. Unlike
SUCenterModal, it includes a gesture recognizer to allow users to drag the modal vertically.View Modifiers:
func bottomModal(isPresented:model:onDismiss:)Public API for displaying a bottom modal. The presentation state is controlled using a
Boolbinding.func bottomModal(item:model:onDismiss:)Public API for displaying a bottom modal when an optional
itemis non-nil.Presentation Modifiers
To present modals,
fullScreenCoveris used without animation, combined with custom animations for the modal itself. This introduces two properties that manage the modal's presentation state:isVisibleIndicates whether the modal is currently visible, controlling the modal's internal animation.
isPresentedIndicates whether the
fullScreenCoverpresenting the modal is active.Lifecycle:
isVisibleandisPresentedaretrue.isVisiblechanges tofalseto trigger the dismissal animation.isPresentedis set tofalse, hiding thefullScreenCover.To abstract these implementation details, two reusable presentation modifiers are introduced:
ModalPresentationModifierModalPresentationWithItemModifierThese modifiers encapsulate the complexity, exposing only the
isVisiblevalue to users.How to Test
Testing with an Optional Item
You can test the API that uses an optional item with the following example:
You can use a similar example to test the center modal.
Testing with
isPresentedThe
isPresentedAPI can be tested by using the updated previews included in this PR.