mirror of
https://github.com/rensbreur/SwiftTUI.git
synced 2026-04-03 00:18:31 -06:00
Implement OnKeyPress #6
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @DandyLyons on 10/31/2024
This PR resolves issue #41 .
It attempts to mimic the
onKeyPressAPI from the original SwiftUI API. See https://developer.apple.com/documentation/swiftui/view/onkeypress(_:action:)So far it is a proof of concept. It has not been tested extensively.
Certain design decisions have not been made. For example, if multiple views subscribe to the same
onKeyPressthen should they both work, one of them, which should have precedence.Known Limitation
It is not recommended to bind
onKeyPressto any of the following keys because they will conflict with the already existing implementation ofButton:" ")"\n")Room For Improvement
The SwiftUI API includes a convenience type named
KeyEquivalentwhich is a simple name space definingCharacterconstants. See https://developer.apple.com/documentation/swiftui/keyequivalentI thought it unnecessary to add this type to SwiftTUI since it already includes its own Character constant type (
ASCII) and their's no need to conflict with that.In the future it might be worth considering unifying the API by either changing
onKeyPress(:,action:)to accept anASCIIor to renameASCIItoKeyEquivalentso that it better matches the SwiftUI API.