-
-
Notifications
You must be signed in to change notification settings - Fork 50
#188: Add support to swiping to dismiss keyboard for UIKitBackend #193
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
066a977
#188: Add support to swiping to dismiss keyboard for UIKitBackend
6b4dfcf
#188: Make the method only executable on iOS
e5b7789
#188: Add support to swiping to dismiss keyboard for ScrollView
a651758
#188: Add .automatic case, remove unused variables, and apply minor a…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
28 changes: 28 additions & 0 deletions
28
Sources/SwiftCrossUI/Values/ScrollDismissesKeyboardMode.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/// The ways that scrollable content can interact with the software keyboard. | ||
/// | ||
/// Use this type in a call to the ``View/scrollDismissesKeyboard(_:)`` | ||
/// modifier to specify the dismissal behavior of scrollable views. | ||
public enum ScrollDismissesKeyboardMode: Sendable { | ||
stackotter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// Determine the mode automatically based on the surrounding context. | ||
/// | ||
/// Currently, this behaves the same as ``ScrollDismissesKeyboardMode/interactively``. | ||
/// In the future, it may adapt dynamically based on the context, similar to how | ||
/// SwiftUI's `.automatic` works (e.g., using `.interactively` in some views and | ||
/// `.immediately` in others). Using this value avoids source-breaking changes later on. | ||
case automatic | ||
|
||
/// Dismiss the keyboard as soon as scrolling starts. | ||
case immediately | ||
|
||
/// Enable people to interactively dismiss the keyboard as part of the | ||
/// scroll operation. | ||
/// | ||
/// The software keyboard's position tracks the gesture that drives the | ||
/// scroll operation if the gesture crosses into the keyboard's area of the | ||
/// display. People can dismiss the keyboard by scrolling it off the | ||
/// display, or reverse the direction of the scroll to cancel the dismissal. | ||
case interactively | ||
|
||
/// Never dismiss the keyboard automatically as a result of scrolling. | ||
case never | ||
} |
41 changes: 41 additions & 0 deletions
41
Sources/SwiftCrossUI/Views/Modifiers/ScrollDismissesKeyboardModifier.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
extension View { | ||
/// Configures the behavior in which scrollable content interacts with | ||
/// the software keyboard. | ||
/// | ||
/// You use this modifier to customize how scrollable content interacts | ||
/// with the software keyboard. For example, you can specify a value of | ||
/// ``ScrollDismissesKeyboardMode/immediately`` to indicate that you | ||
/// would like scrollable content to immediately dismiss the keyboard if | ||
/// present when a scroll drag gesture begins. | ||
/// | ||
/// @State private var text = "" | ||
/// | ||
/// ScrollView { | ||
/// TextField("Prompt", text: $text) | ||
/// ForEach(0 ..< 50) { index in | ||
/// Text("\(index)") | ||
/// .padding() | ||
/// } | ||
/// } | ||
/// .scrollDismissesKeyboard(.immediately) | ||
/// | ||
/// You can also use this modifier to customize the keyboard dismissal | ||
/// behavior for other kinds of scrollable views, like a ``List`` or a | ||
/// ``TextEditor``. | ||
/// | ||
/// By default, scrollable content dismisses the keyboard interactively as the user scrolls. | ||
/// Pass a different value of ``ScrollDismissesKeyboardMode`` to change this behavior. | ||
/// For example, use ``ScrollDismissesKeyboardMode/never`` to prevent the keyboard from | ||
/// dismissing automatically. Note that ``TextEditor`` may still use a different | ||
/// default to preserve expected editing behavior. | ||
/// | ||
/// - Parameter mode: The keyboard dismissal mode that scrollable content | ||
/// uses. | ||
/// | ||
/// - Returns: A view that uses the specified keyboard dismissal mode. | ||
public func scrollDismissesKeyboard(_ mode: ScrollDismissesKeyboardMode) -> some View { | ||
EnvironmentModifier(self) { environment in | ||
environment.with(\.scrollDismissesKeyboardMode, mode) | ||
} | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.