我正在为我的应用程序使用<InputText>
of react-native-paper
。每次我从一个视图切换到另一个视图时,我都会使用该autofocus
属性,所以当我到达屏幕时,我可以直接输入。
但问题是键盘随机出现......有时键盘单独出现,有时我必须点击输入才能显示键盘......
这是我到处使用的输入示例:
<TextInput
label="Article"
value={this.state.article}
onChangeText={article => this.setState({article})}
onSubmitEditing={this.submitStepSaisie1}
autoFocus
style={{backgroundColor: 'transparent'}}
/>
我尝试在我的构造函数中使用这样的 ref :
constructor(props) {
super(props);
this.fieldOne = React.createRef();
this.fieldTwo = React.createRef();
}
在我的 TextInput 上:
<TextInput ref={this.fieldOne} />
但是当我调用this.fieldOne.current.focus()
它时,它会返回以下错误:Cannot read property 'focus' of null.
你们有窍门吗?谢谢 !