Add a way to dismiss the keyboard on iOS
NumericField's .decimalPad/.numberPad keyboards have no Return/Done key of their own, and there was previously no way to dismiss them once shown. Tried .scrollDismissesKeyboard(.interactively) alone first, but it's unreliable in a Form: sections without .onMove/ .onDelete (Price Source, Bitcoin) don't consistently wire up the drag-to-dismiss gesture, so it only worked when dragging within the Currencies section. Adds a "Done" button to the keyboard toolbar as a deterministic fallback that works from any field, keeping the scroll dismissal too since it's a free bonus where it does work. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FXcrACM5sok3M1KQJ8kByy
This commit is contained in:
@@ -26,7 +26,29 @@ struct ContentView: View {
|
||||
EditButton()
|
||||
}
|
||||
}
|
||||
// NumericField's .decimalPad/.numberPad keyboards have no Return/Done key of
|
||||
// their own (unlike a standard text keyboard). `.scrollDismissesKeyboard` alone
|
||||
// isn't a reliable substitute here — Form's sections without .onMove/.onDelete
|
||||
// (Price Source, Bitcoin) don't consistently wire up the drag-to-dismiss gesture,
|
||||
// so it only ever worked when dragging within the Currencies section. This is a
|
||||
// deterministic fallback that works regardless of which field is focused.
|
||||
ToolbarItemGroup(placement: .keyboard) {
|
||||
Spacer()
|
||||
Button {
|
||||
UIApplication.shared.sendAction(
|
||||
#selector(UIResponder.resignFirstResponder),
|
||||
to: nil,
|
||||
from: nil,
|
||||
for: nil
|
||||
)
|
||||
} label: {
|
||||
Text(IosLocalizationKt.localizedString(resource: MR.strings.shared.done))
|
||||
}
|
||||
}
|
||||
}
|
||||
// Kept alongside the Done button above: a free bonus in the Currencies section,
|
||||
// where it does work reliably (see the toolbar comment for where it falls short).
|
||||
.scrollDismissesKeyboard(.interactively)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user