scrollDismissesKeyboard
Configures the behavior in which scrollable content interacts with the software keyboard.
Declaration
compose().scrollDismissesKeyboard(
mode: SwiftUI.ScrollDismissesKeyboardMode
)nonisolated func scrollDismissesKeyboard(
_ mode: ScrollDismissesKeyboardMode
) -> some ViewParameters
The keyboard dismissal mode that scrollable content uses.
Return value
A view that uses the specified keyboard dismissal mode.
Discussion
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, a TextEditor is interactive while other kinds
of scrollable content always dismiss the keyboard on a scroll
when linked against iOS 16 or later. Pass a value of
ScrollDismissesKeyboardMode.never to indicate that scrollable
content should never automatically dismiss the keyboard.
See also
More in Input and interaction.
- allowsHitTestingConfigures whether this view participates in hit test operations.
- allowsWindowActivationEventsConfigures whether gestures in this view hierarchy can handle events that activate the containing window.
- buttonRepeatBehaviorSets whether buttons in this view should repeatedly trigger their actions on prolonged interactions.
- disabledAdds a condition that controls whether someone can interact with this view.
- handlesExternalEventsSpecifies the external events that the view's scene handles if the scene is already open.
- helpAdds help text to a view using a localized string resource that you provide.
- invalidatableContentMark the receiver as their content might be invalidated.
- keyboardShortcutAssigns a keyboard shortcut to the modified control.
- scrollClipDisabledSets whether a scroll view clips its content to its bounds.
- scrollDisabledDisables or enables scrolling in scrollable views.
- sensoryFeedbackPlays the specified feedback when the provided trigger value changes.
- userActivityAdvertises a user activity type.