Open
Conversation
sisoje
approved these changes
Mar 7, 2025
rosswaredev
added a commit
to rosswaredev/SwiftTUI
that referenced
this pull request
Jan 5, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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.