scrollDismissesKeyboard(_:)
Configures the behavior in which scrollable content interacts with the software keyboard.
Declaration
nonisolated func scrollDismissesKeyboard(_ mode: ScrollDismissesKeyboardMode) -> some View
Parameters
- mode:
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 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 never to indicate that scrollable content should never automatically dismiss the keyboard.