react-native: Changing TextInput selection after setting text crash
When TextInput selection is updated after changing the text (using InteractionManager.runAfterInteractions to wait for the change to apply) RN crashes. You get error like “setSpan(4 … 4) ends beyond length” which indicates that the text field text has not changed like you would expect when using runAfterInteractions. React Native version:
info React Native Environment Info: System: OS: macOS 10.14.4 CPU: (8) x64 Intel® Core™ i7-7700HQ CPU @ 2.80GHz Memory: 34.23 MB / 16.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 10.16.0 - ~/.nvm/versions/node/v10.16.0/bin/node Yarn: 1.12.3 - /usr/local/bin/yarn npm: 6.9.0 - ~/.nvm/versions/node/v10.16.0/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1 Android SDK: API Levels: 24, 25, 26, 27, 28 Build Tools: 23.0.1, 25.0.0, 25.0.2, 26.0.1, 26.0.2, 26.0.3, 27.0.3, 28.0.3 System Images: android-25 | Google Play Intel x86 Atom, android-26 | Google APIs Intel x86 Atom IDEs: Android Studio: 3.4 AI-183.6156.11.34.5522156 Xcode: 10.1/10B61 - /usr/bin/xcodebuild npmPackages: react: 16.8.3 => 16.8.3 react-native: 0.59.9 => 0.59.9
Steps To Reproduce
- Change controlled TextInput value in code
- Change TextInput selection to be after the inserted text using InteractionManager.runAfterInteractions
or just run the example in repo I linked and press the button.
Describe what you expected to happen: Selection changes to place after inserted text
Snack, code example, or link to a repository: https://github.com/Vaintti/RNTextInputBug
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 8
- Comments: 18 (1 by maintainers)
Commits related to this issue
- Fix Chat Input Crashes on Android The input was crashing when you sent messages that had modified the native selection props. It crashed when you cleared the text because it would set the text to emp... — committed to keybase/client by MarcoPolo 5 years ago
- Fix Chat Input Crashes on Android The input was crashing when you sent messages that had modified the native selection props. It crashed when you cleared the text because it would set the text to emp... — committed to keybase/client by MarcoPolo 5 years ago
- Fix Chat Input Crashes on Android (#20058) * Fix Chat Input Crashes on Android The input was crashing when you sent messages that had modified the native selection props. It crashed when you clea... — committed to keybase/client by MarcoPolo 5 years ago
- Cap selection indices when text changes (#26680) Summary: This PR https://github.com/facebook/react-native/pull/22723 cached selections, so if you had a cached selection indicies, but updated the tex... — committed to facebook/react-native by MarcoPolo 5 years ago
- Cap selection indices when text changes (#26680) Summary: This PR https://github.com/facebook/react-native/pull/22723 cached selections, so if you had a cached selection indicies, but updated the tex... — committed to expo/react-native by MarcoPolo 5 years ago
- React Native sync for revisions 54f297a...ab075a2 Summary: This sync includes the following changes: - **[ab075a232](https://github.com/facebook/react/commit/ab075a232 )**: Do not unmount layout effe... — committed to facebook/react-native by sammy-SC 2 years ago
I am also having same issue… don’t know how to fix…
Have similar issue on RN 0.60.4