-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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' for Android #10665
Conversation
By analyzing the blame information on this pull request, we identified @janicduplessis and @rigdern to be potential reviewers. |
Thank you for your pull request. We require contributors to sign our Contributor License Agreement, and yours has expired. Before we can review or merge your code, we need you to email cla@fb.com with your details so we can update your status. |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ |
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 header should be at the top of the file.
int diff = count - before; | ||
if(diff == 1) { | ||
// Mirrors behaviour of iOS | ||
String key = ""+s.charAt(start+count-1); |
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.
spaces around +
private WritableMap serializeEventData() { | ||
WritableMap eventData = Arguments.createMap(); | ||
|
||
//WritableMap selectionData = Arguments.createMap(); |
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.
space after //
//WritableMap selectionData = Arguments.createMap(); | ||
eventData.putString("key", mKey); | ||
|
||
//eventData.putMap("selection", selectionData); |
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.
space after //
|
||
public ReactKeyDownEvent( | ||
int viewId, | ||
String key) { |
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.
single line
Oh Android 😐 |
// If the string is only 1 character longer, we interpret it as a key press. It also triggers | ||
// if only 1 character was pasted, but there is no way to monitor soft/virtual key presses | ||
int diff = count - before; | ||
if(diff == 1) { |
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.
space after "if"
} | ||
// If the text is shorter we interpret as a backspace press (could also be a Cut from a | ||
// selection) | ||
if(diff < 0) { |
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.
space after "if"
Do we need to change the docs for this? Also do we need to communicate a breaking change - is this breaking the behavior of existing stuff, or just adding a new event? Could you add a test to ensure this behavior is working properly? |
Yes, right now this event is marked as iOS only. It is also maybe worth mentioning the limitation of key events on Android?
I have simply just added a new event, and triggers in the appropriate places.
Sure, could you give me a small pointer in the right direction? Which file(s) should I look at for inspiration? |
Are we testing other similar events at all? I'm not quite sure what the right way to test this is, but we really need to figure that out to reduce the rate of React Native accidental breakage. |
@petergarnaes I would try adding an Android integration test here, since this changes both js and java. Check out |
Ping @petergarnaes are you still working on this PR? |
It seems like this PR has gone stale so I am going to close it. Please feel free to reopen if you are still working on this! |
An attempt at the Android implementation. Attempted to mirror the iOS implementation by supporting 'Enter' and 'Backspace'.
The implementation utilises the TextWatcher, because the [documentation](https://developer.android.com/reference/android/view/View.OnKeyListener.html#onKey(android.view.View, int, android.view.KeyEvent)) for OnKeyListener->onKey states:
Because of this, in my implementation pressing backspace in an empty text field will not trigger onKeyPress. Using cut on selected text and pasting a single character will be interpreted as key presses.