[Android] selection crashes TextInput component
See original GitHub issueIs this a bug report?
Yes
Have you read the Contributing Guidelines?
Yes
Environment
Environment: OS: macOS High Sierra 10.13.2 Node: 9.3.0 Yarn: 1.3.2 npm: 5.6.0 Watchman: 4.9.0 Xcode: Xcode 9.2 Build version 9C40b Android Studio: 2.3 AI-162.3764568
Packages: (wanted => installed) react: 16.0.0 => 16.0.0 react-native: 0.50.3 => 0.50.3
Steps to Reproduce
Pass selection
prop into TextInput
component on Android.
import React from 'react';
import { StyleSheet, View, TextInput } from 'react-native';
export default function App() {
return (
<View style={styles.container}>
<TextInput
value="123"
selection={{ start: 3, end: 3 }}
/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
Expected Behavior
Selection should be applied.
Actual Behavior
Error while updating property 'selection' of a view managed by: AndroidTextInput
null
setSpan (3 ... 3) ends beyond length 0
updateViewProp
ViewManagersPropertyCache.java:92
setProperty
ViewManagerPropertyUpdater.java:129
updateProps
ViewManagerPropertyUpdater.java:48
updateProperties
ViewManager.java:34
createView
NativeViewHierarchyManager.java:214
execute
UIViewOperationQueue.java:153
run
UIViewOperationQueue.java:809
flushPendingBatches
UIViewOperationQueue.java:922
access$2100
UIViewOperationQueue.java:47
doFrameGuarded
UIViewOperationQueue.java:982
doFrame
GuardedFrameCallback.java:31
doFrame
ReactChoreographer.java:136
doFrame
ChoreographerCompat.java:107
run
Choreographer.java:872
doCallbacks
Choreographer.java:686
doFrame
Choreographer.java:618
run
Choreographer.java:860
handleCallback
Handler.java:751
dispatchMessage
Handler.java:95
loop
Looper.java:154
main
ActivityThread.java:6119
invoke
Method.java
run
ZygoteInit.java:886
main
ZygoteInit.java:776
Reproducible Demo
https://github.com/nkt/react-native-text-input-bug
(Paste the link to an example project and exact instructions to reproduce the issue.)
Issue Analytics
- State:
- Created 6 years ago
- Comments:14 (1 by maintainers)
Top Results From Across the Web
Android App crashing at material.textfield.TextInputLayout
you can change androidx.appcompat.widget.AppCompatEditText. to com.google.android.material.textfield.TextInputEditText. For example:
Read more >Specify the input method type - Android Developers
Every text field expects a certain type of text input, such as an email address, phone number, or just plain text.
Read more >TextField crash [199919707] - Visible to Public - Issue Tracker
Jetpack Compose release version: Android Studio Build:30. Kotlin version:1.5.21. Steps to Reproduce: 1. when the textField is empty, cilck backSpace, ...
Read more >MS4 crashing during playback and note selection in certain ...
As the title says, ms4 crashes at certain parts during playback as well as note input and selection in certain areas.
Read more >Sudden Crashes on Keyboard Input and File Download
I'm not sure if all these issues are related to the software update, or. Chrome crash. Do you suggest me to open bugs...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Gr1ver Thank you! This works!
This code works:
<TextInput autoFocus={true} onFocus={this.setSel} selection={this.state.select} onChangeText={this.props.changeContent} value={this.props.text}/>
Where this.setSel looks like:
_setSel() { this.setState({ select: {start: 1, end: 1} }) }
@nkt You will be able to set selection only after input have receive focus, subscribe to onFocus and onBlur and pass your custom selection depending on focused state.