使用 React Native TextInput,当在键盘可见时点击后退按钮(屏幕截图中的红色 1)时,可以稍后编辑 TextInput 值。但是,当点击检查/输入图标(屏幕截图中的红色 2)时,无法在键盘消失后更改 TextInput。之后点击输入时,插入符号在点击期间出现,但随后消失,没有任何反应。
这是我的组件:
export class MyInput extends Component {
constructor (props) {
super(props);
this.state = {
inputValue: `${Date.now()}-document`,
};
this.onFocus = this.onFocus.bind(this);
}
onFocus (text) {
if (this.placeholderRemoved) {
return text;
}
this.textInput.clear();
this.placeholderRemoved = true;
return '';
}
render () {
return (
<KeyboardAvoidingView>
<TextInput
value={this.state.inputValue}
onChangeText={(text) => {
this.setState({inputValue: text});
}}
/>
</KeyboardAvoidingView>
);
}
}
经测试:
- 小米 Pocophone F1,安卓 8.1
- 谷歌 Pixel 2(模拟器),Android 7.1.1
关闭键盘后如何启用 TextInput 的编辑?
在@Sean Wangs 请求后编辑
import React, {Component} from 'react';
import {AppRegistry, View} from 'react-native';
import {MyInput} from './myInputViewComponent';
export default class myApp extends Component {
render() {
return (
<View>
<MyInput />
</View>
);
}
}
AppRegistry.registerComponent('myApp', () => myApp);
"react": "16.7.0", "react-native": "0.57.6",

