我创建了一个示例react-native应用程序。这个程序只包括TextInput和一个按钮
export default class App extends Component {
state = {
inputValue: "You can change me!"
};
_handleTextChange = inputValue => {
this.setState({ inputValue });
};
_handleSelectionChange = (event) =>{
this.setState({seleksi : event.nativeEvent.selection});
console.log(event.nativeEvent.selection);
}
_handleButtonPress = () => {
this.setState({inputValue : "Paijo tenan"});
};
render() {
return (
<View style={styles.container}>
<TextInput
value={this.state.inputValue}
onChangeText={this._handleTextChange}
**onSelectionChange={(event)=>this._handleSelectionChange(event)}**
style={{ width: 200, height:200, padding: 8 }}
multiline={true}
/>
<Button
title="Press me"
onPress={this._handleButtonPress}
/>
</View>
);
}
}
Run Code Online (Sandbox Code Playgroud)
当我设置onSelectionChange属性时,单击Button之后。TextInput上的文本选择显示异常。
在单击按钮之前,选择显示项目符号的开始和结束
之后,选择不显示项目符号的开始和结束
但是,当我在TextInput上键入一些文本时,就可以进行选择了。
单击按钮后,如何使选择生效,并在TextInput上使用onSelectionChange道具?为什么会这样呢?如何调试?,我的代码看起来还不错
react-native ×1