Skip to content

Android TextInput setting selection props beyond 0 on mount crash #18316

Closed
@lxcid

Description

@lxcid

When I set selection props on <TextInput /> that is above 0 (e.g. { start: 1, end: 1 }), it will crash at setSpan()

e.g.

<TextInput multiline={true} selection={{ start: 1, end: 1 }}>
  <Text>abc</Text>
</TextInput>

It seems like the text are not set before selection is applied, thereby causing the crash. Crash log stack trace provided below.

Environment

Environment:
  OS: macOS High Sierra 10.13.3
  Node: 9.2.0
  Yarn: 1.3.2
  npm: 5.5.1
  Watchman: 4.9.0
  Xcode: Xcode 9.2 Build version 9C40b
  Android Studio: 3.0 AI-171.4443003

Packages: (wanted => installed)
  react: 16.2.0 => 16.2.0
  react-native: 0.53.2 => 0.53.2

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
Error while updating property 'selection' of a view managed by: AndroidTextInput

null

setSpan (1 ... 1) ends beyond length 0
updateViewProp
    ViewManagersPropertyCache.java:92
setProperty
    ViewManagerPropertyUpdater.java:129
updateProps
    ViewManagerPropertyUpdater.java:48
updateProperties
    ViewManager.java:34
createView
    NativeViewHierarchyManager.java:233
execute
    UIViewOperationQueue.java:153
dispatchPendingNonBatchedOperations
    UIViewOperationQueue.java:1010
doFrameGuarded
    UIViewOperationQueue.java:981
doFrame
    GuardedFrameCallback.java:31
doFrame
    ReactChoreographer.java:136
doFrame
    ChoreographerCompat.java:107
run
    Choreographer.java:856
doCallbacks
    Choreographer.java:670
doFrame
    Choreographer.java:603
run
    Choreographer.java:844
handleCallback
    Handler.java:739
dispatchMessage
    Handler.java:95
loop
    Looper.java:148
main
    ActivityThread.java:5417
invoke
    Method.java
run
    ZygoteInit.java:726
main
    ZygoteInit.java:616

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 }}

<TextInput
  // selection={{ start: 0, end: 0 }} // Uncomment and it does not crash
  // selection={{ start: 1, end: 1 }} // Uncomment and it crash in android
  style={styles.paragraph}
  multiline={true}>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions