-
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
Android TextInput setting selection props beyond 0 on mount crash #18316
Comments
Thanks for posting this! It looks like your issue may refer to an older version of React Native. Can you reproduce the issue on the latest stable release? Thank you for your contributions. |
Previous discussion: #17236 |
I have a workaround in https://github.com/akalin-keybase/rn-text-input-bugs , which is to wait for the next If the text box has focus, Android seems to fire |
Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions. |
Pretty sure this is still crashing. |
+1 |
The root cause is due to setSelection and setText are handled in different mechanism. Seletion is by set property and Text is handled by extra data update. And extra data update will be hanled after all properties are set. |
Make a pull request here: |
still have same issue in react native 0.60.5. |
@thymikee This is still very much an issue in 0.61.5 release. The workaround at https://github.com/akalin-keybase/rn-text-input-bugs/blob/master/App.js also doesn't work. We tried some workarounds with It looks like if you set the Our use case is inserting emoji and mentions into a message input, while maintaining the correct selection. I'll try to make a simple repro when I have a minute. Arguably trying to set selection outside of the available range shouldn't crash the entire app anyway. Sure I can see arguments for both sides but IMO it should select from the start point to the end of the text if the end is out of range, or move the cursor to the end of the text if the entire selection is out of range.
|
Doesn't look finished but 7ab5eb4 might solve this one day as it adds a |
@russelRajitha @anjY123 see mjmasn/SelectionCrash#1 for a new workaround. Haven't noticed any issues with it yet but feel free to try it and let me know how it goes. |
Experiencing the same issues (only on Android) with a use case similar to yours, this fix did it for me. Thanks! |
When I set
selection
props on<TextInput />
that is above 0 (e.g.{ start: 1, end: 1 }
), it will crash atsetSpan()
…e.g.
It seems like the text are not set before selection is applied, thereby causing the crash. Crash log stack trace provided below.
Environment
Expected Behavior
I would expect it to not crash and set the selection correctly.
Actual Behavior
It crashes with the following stack trace…
setSpan (1 ... 1) ends beyond length 0
Steps to Reproduce
https://snack.expo.io/@lxcid/textinput-selection-crash
Open the snack in Android and uncomment the line with
selection={{ start: 1, end: 1 }}
…The text was updated successfully, but these errors were encountered: