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

TextInput onChangeText is firing at wrong time when type with Chinese input keyboard in iOS #30578

Open
hermanho opened this issue Dec 12, 2020 · 6 comments
Labels
API: Keyboard Component: TextInput Related to the TextInput component. Needs: Triage 🔍 Never gets stale Prevent those issues and PRs from getting stale Platform: iOS iOS applications.

Comments

@hermanho
Copy link

Description

TextInput onChangeText is firing at wrong time. Here is the gif to show the problem.
RPReplay_Final1607783480

I am typing the Chinese wording "你好" with a Chinese input keyboard in iOS.

  1. The char "你" is inputted by the code "人火".
  2. I type with the code "人火" and these two codes are highlighted in grey in the textbox. The input method is still not completed yet. The code "人火" should not be considered as a text change event. However, onChangeText is triggered.
    螢幕截圖 2020-12-12 下午11 10 33
  3. After I select the char "你" in Chinese input keyboard, onChangeText is triggered twice.
    螢幕截圖 2020-12-12 下午10 56 30

React Native version:

System:
    OS: macOS 11.0.1
    CPU: (8) x64 Intel(R) Core(TM) i7-8557U CPU @ 1.70GHz
    Memory: 751.11 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.15.1 - /usr/local/bin/node
    Yarn: Not Found
    npm: 6.14.8 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.10.0 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 14.2, DriverKit 20.0, macOS 11.0, tvOS 14.2, watchOS 7.1
    Android SDK: Not Found
  IDEs:
    Android Studio: 4.1 AI-201.8743.12.41.6953283
    Xcode: 12.2/12B45b - /usr/bin/xcodebuild
  Languages:
    Java: Not Found
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.13.1 => 16.13.1 
    react-native: https://github.com/expo/react-native/archive/sdk-40.0.1.tar.gz => 0.63.2 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

  1. Open https://snack.expo.io/@hkhermanho/textinput-with-chinese
  2. Type any Chinese characters with Chinese input method

Expected Results

onChangeText should not be fire before the input method is done. It should be fired 2 times for 2 Chinese characters instead of 8 times.
螢幕截圖 2020-12-12 下午11 02 07

Snack, code example, screenshot, or link to a repository:

https://snack.expo.io/@hkhermanho/textinput-with-chinese

@react-native-bot react-native-bot added API: Keyboard Component: TextInput Related to the TextInput component. Platform: iOS iOS applications. labels Dec 12, 2020
@rnike
Copy link
Contributor

rnike commented Apr 17, 2021

This can be fixed by applying the following diff to react-native source code

diff --git a/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m b/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m
--- a/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m
+++ b/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m
@@ -107,6 +107,12 @@ - (BOOL)textFieldShouldReturn:(__unused UITextField *)textField

 - (void)textFieldDidChange
 {
+  UITextRange *markedTextRange = _backedTextInputView.markedTextRange;
+
+  if (markedTextRange != nil && !markedTextRange.empty) {
+      return;
+  }
+
   _textDidChangeIsComing = NO;
   [_backedTextInputView.textInputDelegate textInputDidChange];

the result will be

after_applied.mov

but we will not able to handle the "ongoing text" ( ㄋㄧ ˇㄏㄠˇ in my video) anymore.

So I tried using onSelectionChange to see if we can handle onTextChanged only if no text selected, but react-native doesn't consider the "ongoing text" as a text selection, see the image below, the selection start,end should be 0,3 but 3,3

check-selection


Seems like the "ongoing text" is not currently well handled by react-native, I'll stick to the diff solution mentioned above and make a pull request.

@urtheone
Copy link

still happen in 0.64.2

@ouabing
Copy link

ouabing commented Apr 28, 2022

Seems like @rnike 's workaround doesn't work any more in RN 0.67.4. Does anyone figure out how to solve this problem? I'm not an iOS developer but would like to help test.

@rnike
Copy link
Contributor

rnike commented May 31, 2022

@ouabing no my workaround is still working on react-native 0.68.2

sc.mov

I think it's just because my pr #31376 is still opening and not merged

@github-actions
Copy link

github-actions bot commented Oct 3, 2023

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Oct 3, 2023
@hermanho
Copy link
Author

hermanho commented Oct 5, 2023

Not stale. The pr #31376 is still opening and not merged

@cortinico cortinico added Never gets stale Prevent those issues and PRs from getting stale and removed Stale There has been a lack of activity on this issue and it may be closed soon. labels Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API: Keyboard Component: TextInput Related to the TextInput component. Needs: Triage 🔍 Never gets stale Prevent those issues and PRs from getting stale Platform: iOS iOS applications.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants