Reputation: 151
I want to write a component which can edit an article for words input and insert images. I use TextInput for words input. If I want to insert an image in the middle of the text, I will generate an Image component and an new TextInput after the Image. But I don't know how to get the cursor position and content after the cursor. Anyone help?
Upvotes: 5
Views: 1910
Reputation: 132
The answer by @Noitidart points to the right direction
<TextInput>
hasonSelectionChange
which fires with{ nativeEvent:{ start:number, end:number } }
. It updates whenever cursor position changes.
However, it's useful to note that as of RN 0.61, onSelectionChange
fires with { nativeEvent: { selection: { start:number, end:number } }, text: string }
.
Upvotes: 1
Reputation: 37238
<TextInput>
has onSelectionChange
which fires with { nativeEvent:{ start:number, end:number } }
. It updates whenever cursor position changes.
Upvotes: 3