TextInput autoFocus上没有显示键盘[本机反应]

问题描述 投票:0回答:1

我在我的应用程序中有这个回复按钮,当用户按下它时,它会将TextInput autoFocus更改为true。我将autoFocus值设置为false作为默认值并将其保持在某个状态。我看到状态将变为true但它不会打开键盘。

这是我的TextInput:

<TextInput
    autoFocus={this.state.textInputFocus}
    selectTextOnFocus={true}
    ref={ref => this.textInputRef = ref}
    multiline = {true}
    placeholder="Write a comment ..."
    onChangeText={(postComment) => this.setState({postComment})}
    value={this.state.postComment} />

以下是按下回复按钮时更改状态的功能:

_openReplyBox(comment_id, commenter){
    this.setState({ postComment: commenter, textInputFocus: true })
}
react-native keyboard textinput autofocus
1个回答
1
投票

根据文件:

autoFocus:如果为true,则将输入集中在componentDidMount上。默认值为false

您可以使用refs来实现相同的功能。

 <TextInput
        ref={"textRef"}
        ...
      />

在openReplyBox中:

_openReplyBox(comment_id, commenter){
    this.refs.textRef.focus();
    this.setState({ postComment: commenter})
}
© www.soinside.com 2019 - 2024. All rights reserved.