-
Notifications
You must be signed in to change notification settings - Fork 24.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TextInput] Implements onKeyPress
#2082
Conversation
Nice work! You're going to have to rebase some conflicts once my diffs sync out though. |
@sahrens Not a problem. :) |
😍 awesome @dsibiski |
I will need to implement an example for the UIExplorer, but I wanted to get some opinions on what's happening here (and the changes they are doing internally at FB) before knocking that out. |
@dsibiski - in your example I see:
imo this should be |
@brentvatne I had piggy-backed off of the As for the firing order, in my testing, I noticed that |
Ok, I rebased @sahrens's recent changes. I made Now, I just need to implement @brentvatne's suggestion for the nativeEvent & a UIExplorer example. |
/cc @brentvatne @sahrens |
{ | ||
NSString *keyValue = kBackspaceKeyValue; | ||
|
||
BOOL keyNotBackspace = ![text isEqualToString:@""]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you consolidate this with the enter logic into one if else chain?
I'm going on PTO - nick, can you help out with this one? |
Build failed because of: #2134 |
@sahrens @nicklockwood What do you guys think about this? Just rebased the latest master to get rid of the conflicts... |
Note to self: Once this commit (vjeux@48548fe) lands, I'll need to move most (or all) of this into the |
@sahrens @nicklockwood I rebased the current changes and was able to remove some of the 'backspace' press detection hacks. Can you guys check this out when you get a chance? I think that the "paste" detecting is a little wonky, let me know what you think. |
Checking in - Is this happening? |
@nicklockwood @sahrens Hey guys, do you guys want me to add Android support to this as well? I imagine that might be the reason for the hold up... |
@"eventCount": @(eventCount), | ||
@"target": reactTag | ||
}]; | ||
|
||
if (text) { | ||
[body addEntriesFromDictionary:@{@"text": text}]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can just be:
if (text) {
body[@"text"] = text;
}
Android support would be great, but it's OK to just mark the prop with |
extern NSString *const RCTNewlineRawValue; | ||
|
||
extern NSString *const RCTBackspaceKeyValue; | ||
extern NSString *const RCTEnterKeyValue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Files should end with a blank line.
@dsibiski updated the pull request. |
Hmm, somehow the newline at the end of the file didn't come through...it seems to still be there in Xcode... @nicklockwood Do you know if that is something with git? (Edit) Perhaps it's there and just GitHub doesn't see it... |
@facebook-github-bot import |
Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/946196175402219/int_phab to review. |
Oops, I better squash my commits... |
- When a key is pressed, it's `key value` is passed as an argument to the callback handler
Summary: - When a key is pressed, it's `key value` is passed as an argument to the callback handler. - For `Enter` and `Backspace` keys, I'm using their `key value` as defined [here](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key#Key_values). As per JonasJonny & brentvatne's [suggestion](facebook#1882 (comment)). - Example ```javascript _handleKeyPress: function(e) { console.log(e.nativeEvent.key); }, render: function() { return ( <View style={styles.container}> <TextInput style={{width: 150, height: 25, borderWidth: 0.5}} onKeyPress={this._handleKeyPress} /> <TextInput style={{width: 150, height: 100, borderWidth: 0.5}} onKeyPress={this._handleKeyPress} multiline={true} /> </View> ); } ``` - Implements [shouldChangeCharactersInRange](https://developer.apple.com/library/prerelease/ios/documentat Closes facebook#2082 Reviewed By: javache Differential Revision: D2280460 Pulled By: nicklockwood fb-gh-sync-id: 1f824f80649043dc2520c089e2531d428d799405
Summary: - When a key is pressed, it's `key value` is passed as an argument to the callback handler. - For `Enter` and `Backspace` keys, I'm using their `key value` as defined [here](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key#Key_values). As per JonasJonny & brentvatne's [suggestion](facebook#1882 (comment)). - Example ```javascript _handleKeyPress: function(e) { console.log(e.nativeEvent.key); }, render: function() { return ( <View style={styles.container}> <TextInput style={{width: 150, height: 25, borderWidth: 0.5}} onKeyPress={this._handleKeyPress} /> <TextInput style={{width: 150, height: 100, borderWidth: 0.5}} onKeyPress={this._handleKeyPress} multiline={true} /> </View> ); } ``` - Implements [shouldChangeCharactersInRange](https://developer.apple.com/library/prerelease/ios/documentat Closes facebook#2082 Reviewed By: javache Differential Revision: D2280460 Pulled By: nicklockwood fb-gh-sync-id: 1f824f80649043dc2520c089e2531d428d799405
Any plan to have onKeyPress event for Android? |
Probably a feature someone will have to contribute @MatiasCba. I'm currently in need, but I haven't scoped out what it looks like under the hood for Android. If it's already set up similarly, it shouldn't be too bad. |
+1 for onKeyPress in Android |
Working on a fork at the moment, if I finish up I'll refer from here |
@ajwhite Awesome, thanks for the update |
@ajwhite Any updates on this or work you've done to date? |
I haven't any updates at this time, I likely cannot visit this for another couple weeks. Busy bee at work! |
@ajwhite , any update on Android support? |
I don't, sorry folks! It became a bit of a rabbit hole and was deprioritized in our project in lieu of a workaround. |
key value
is passed as an argument to the callback handler.Enter
andBackspace
keys, I'm using theirkey value
as defined here. As per @JonasJonny & @brentvatne's suggestion.keyboardInputShouldDelete
and deleteBackward forRCTTextField
keyboardInputShouldDelete
anddeleteBackward
were implemented becauseUITextField
doesn't triggershouldChangeCharactersInRange
when the field is empty, preventing us from having a truekeyPress
event.keyboardInputShouldDelete
is not documented as alluded to in this StackOverflow answer. However, I'm only using it because of a bug in iOS 8.0 to 8.2 where thedeleteBackward
method doesn't trigger. This might cause this whole feature to be a no-op, though. :(RCTTextView
UITextViews
(used for multi-line TextInputs) trigger this method even when the textView is empty.