-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fix Chat Input Crashes on Android #20058
Conversation
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 empty, and reused a cached selection that was out of bounds of an empty string. For example, say you type "hello @" and autocomplete to "hello @foo". We do some text selection magic to insert the @foo and put your cursor in the correct spot. The Selection start and end indicies are both 11. When you submit to message, we clear the text. When we clear the text, RN keeps reusing those selection indices (of 11) and Android complains the selection is outside of the bounds of the text ("" has a length of 0, but you want to move the cursor to position 11, outside the bounds of 0). The workaround here is to set the selection at the same time as the text. The RN Issue is: facebook/react-native#25265
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.
Can we just do the same thing on ios ?
I tried it and it seems fine on iOS too. |
@@ -67,9 +67,13 @@ class PlainInput extends Component<InternalProps> { | |||
} | |||
const newTextInfo = fn(currentTextInfo) | |||
checkTextInfo(newTextInfo) | |||
this.setNativeProps({text: newTextInfo.text}) | |||
// If we're android, let's workaround this Issue: https://github.com/imnapo/react-native-cn-richtext-editor/issues/81 |
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.
Update comment
this.setNativeProps({ | ||
selection: this._sanityCheckSelection(newTextInfo.selection, newTextInfo.text), | ||
text: newTextInfo.text, | ||
}) | ||
this._lastNativeText = newTextInfo.text |
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.
We should likely set this._lastNativeSelection
here
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 empty, and reused a cached selection that was out
of bounds of an empty string.
For example, say you type "hello @" and autocomplete to "hello @foo". We
do some text selection magic to insert the @foo and put your cursor in
the correct spot. The Selection start and end indicies are both 11. When
you submit to message, we clear the text. When we clear the text, RN
keeps reusing those selection indices (of 11) and Android complains the
selection is outside of the bounds of the text ("" has a length of 0,
but you want to move the cursor to position 11, outside the bounds of
0).
The workaround here is to set the selection at the same time as the
text.
The RN Issue is: facebook/react-native#25265
@buoyad since I think he has the most context here.
@keybase/react-hackers