Skip to content
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

(Android) Incorrect key reported from TextInput onKeyPress event #18262

Closed
lxcid opened this issue Mar 8, 2018 · 7 comments
Closed

(Android) Incorrect key reported from TextInput onKeyPress event #18262

lxcid opened this issue Mar 8, 2018 · 7 comments
Labels
Bug Component: TextInput Related to the TextInput component. Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. Platform: Android Android applications. Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.

Comments

@lxcid
Copy link

lxcid commented Mar 8, 2018

There are cases where <TextInput /> onKeyPress() event report incorrect keys.

If you place your selection cursor at the start of the line and press enter, instead of receiving Enter key on key press event, you receive Backspace and e.

It only happen if you do this on the start of the line. If I move selection cursor to end of line and press enter, it function correctly.

Notice also how the order of events are different for happy case and edge case, which is related to #18221.

Environment

Environment:
  OS: macOS High Sierra 10.13.3
  Node: 9.2.0
  Yarn: 1.3.2
  npm: 5.5.1
  Watchman: 4.9.0
  Xcode: Xcode 9.2 Build version 9C40b
  Android Studio: 3.0 AI-171.4443003

Packages: (wanted => installed)
  react: 16.2.0 => 16.2.0
  react-native: 0.53.3 => 0.53.3

Expected Behavior

Report the correct key press, in my case, Enter.

Actual Behavior

It only happen if you do this at the start of the line. Instead of receiving Enter key on key press event, you will receive Backspace and e.

Steps to Reproduce

  • Clone and run this repo https://github.com/lxcid/ReactNative-AndroidKeyPress
  • Make sure you have an Android device attached for debugging.
  • react-native run-android
  • react-native log-android if you need to see the log yourself
  • Placing selection cursor at start of line
  • Press enter several times

Output (comments describe the user input event)

03-08 11:59:00.891 21082 23563 I ReactNativeJS: Running application "AndroidKeyPress" with appParams: {"rootTag":31}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF
03-08 11:59:03.853 21082 23563 I ReactNativeJS: 'onSelectionChange', { start: 80, end: 80 }
# Placing selection cursor at start of line
03-08 11:59:06.413 21082 23563 I ReactNativeJS: 'onSelectionChange', { start: 0, end: 0 }
# Press Enter
03-08 11:59:07.888 21082 23563 I ReactNativeJS: 'onKeyPress', 'Backspace'
03-08 11:59:07.895 21082 23563 I ReactNativeJS: 'onChangeText', '\nDouble tap R on your keyboard to reload,\nShake or press menu button for dev menu'
03-08 11:59:07.913 21082 23563 I ReactNativeJS: 'onSelectionChange', { start: 7, end: 7 }
03-08 11:59:07.915 21082 23563 I ReactNativeJS: 'onSelectionChange', { start: 1, end: 1 }
# Press Enter again
03-08 11:59:07.915 21082 23563 I ReactNativeJS: 'onKeyPress', 'e'
03-08 11:59:08.964 21082 23563 I ReactNativeJS: 'onKeyPress', 'Backspace'
03-08 11:59:08.969 21082 23563 I ReactNativeJS: 'onChangeText', '\n\n tap R on your keyboard to reload,\nShake or press menu button for dev menu'
03-08 11:59:08.983 21082 23563 I ReactNativeJS: 'onSelectionChange', { start: 2, end: 2 }
03-08 11:59:08.989 21082 23563 I ReactNativeJS: 'onChangeText', '\n\nDouble tap R on your keyboard to reload,\nShake or press menu button for dev menu'
03-08 11:59:09.001 21082 23563 I ReactNativeJS: 'onSelectionChange', { start: 2, end: 2 }
# Press Enter yet again
03-08 11:59:09.002 21082 23563 I ReactNativeJS: 'onKeyPress', 'e'
03-08 11:59:09.737 21082 23563 I ReactNativeJS: 'onKeyPress', 'Backspace'
03-08 11:59:09.741 21082 23563 I ReactNativeJS: 'onChangeText', '\n\n\nDouble tap R on your keyboard to reload,\nShake or press menu button for dev menu'
03-08 11:59:09.754 21082 23563 I ReactNativeJS: 'onSelectionChange', { start: 3, end: 3 }
03-08 11:59:09.755 21082 23563 I ReactNativeJS: 'onKeyPress', 'e'
# Move selection cursor to the end
03-08 12:11:31.936 21082 23563 I ReactNativeJS: 'onSelectionChange', { start: 83, end: 83 }
# Press Enter
03-08 12:11:32.998 21082 23563 I ReactNativeJS: 'onChangeText', '\n\n\nDouble tap R on your keyboard to reload,\nShake or press menu button for dev menu\n'
03-08 12:11:33.024 21082 23563 I ReactNativeJS: 'onSelectionChange', { start: 84, end: 84 }
03-08 12:11:33.025 21082 23563 I ReactNativeJS: 'onKeyPress', 'Enter'
@joshjhargreaves joshjhargreaves added Android Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. Good first issue Interested in collaborating? Take a stab at fixing one of these issues. labels Mar 8, 2018
@joshjhargreaves
Copy link
Contributor

Thank you for reporting this, as I'm sure you know, this is a new feature on Android & it's a hard thing to get right on the first attempt!
Can you find any other cases where the output is inconsistent between iOS & Android?

I'll have to think about the event order inconsistency separately as there's more implementation dependent on either platform.

@lxcid
Copy link
Author

lxcid commented Mar 10, 2018

I'll be sure to report more if I find them! 👍 Thanks for the reply!

@react-native-bot react-native-bot added Ran Commands One of our bots successfully processed a command. Component: TextInput Related to the TextInput component. labels Mar 16, 2018
@react-native-bot

This comment has been minimized.

@react-native-bot react-native-bot added Old Version ⏪ Ran Commands One of our bots successfully processed a command. labels Mar 16, 2018
@react-native-bot react-native-bot added Platform: Android Android applications. Ran Commands One of our bots successfully processed a command. labels Mar 18, 2018
@react-native-bot react-native-bot added the Platform: macOS Building on macOS. label Mar 20, 2018
@hramos hramos removed the Platform: macOS Building on macOS. label Mar 29, 2018
@lamnguyen2307
Copy link

lamnguyen2307 commented Apr 11, 2018

@joshyhargreaves
I face the same issue with onKeyPress on android.
onKeyPress can trigger key event properly if the keyboardType="default",
otherwise, when I use the "numeric" keyboardType, onKeyPress cannot trigger the number key events.
It only works with backspace, dot, comma, key events.

Could anyone help with this issue?

Here is my react-native info:

Environment:
OS: macOS High Sierra 10.13.4
Node: 8.11.1
Yarn: 1.5.1
npm: 5.6.0
Watchman: 4.9.0
Xcode: Xcode 9.3 Build version 9E145
Android Studio: 3.1 AI-173.4697961

Packages: (wanted => installed)
react: ^16.3.0-alpha.1 => 16.3.0-alpha.3
react-native: 0.54.2 => 0.54.2

@morenoh149
Copy link
Contributor

morenoh149 commented Jun 6, 2018

@joshyhargreaves you say

I'll have to think about the event order inconsistency separately as there's more implementation dependent on either platform.

Does that mean the bug is likely in the c++ code? looking into this.

@omeryounus
Copy link

Yess, I believe its because native compiler

@hramos hramos removed the Bug Report label Feb 6, 2019
@grabbou grabbou removed the Good first issue Interested in collaborating? Take a stab at fixing one of these issues. label Mar 19, 2019
@grabbou
Copy link
Contributor

grabbou commented Mar 19, 2019

This issue has been open and reproduced on a really old version of React Native. We have contributed a lot of improvements to TextInput on Android since then.

I am going to close it hoping it doesn't happen anymore. In case it does happen on 0.59, please let me know and let's reopen.

@grabbou grabbou closed this as completed Mar 19, 2019
@facebook facebook locked as resolved and limited conversation to collaborators Mar 19, 2020
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Mar 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Component: TextInput Related to the TextInput component. Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. Platform: Android Android applications. Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

9 participants