I am trying to change the cursor position using components state because in future I want to handle the cursor position from the components state. But I am unable to do it
Code :
state = {
selection: {
start: 0,
end: 0,
},
text: "",
};
HandleChangeText = (text) => {
console.log(this.state.selection); // here the values of start and end are increasing
const { start, end } = this.state.selection;
this.setState({
selection: {
start: start + 1,
end: end + 1,
},
text: text,
});
};
HandleSelectionChange = ({ nativeEvent: { selection } }) => {
console.log("handleselection ", selection); // here I am getting start and end as 0,0 only
};
render() {
return (
<TextInput
value={this.state.text}
selection={this.state.selection}
onSelectionChange={this.HandleSelectionChange}
onChangeText={this.HandleChangeText}
multiline
/>
);
}
Issue : cursor position is not changing.It is not changing from the {start:1,end:1}