你如何在 react-native-gifted-chat 中自动聚焦输入框
How do you autofocus the input box in react-native-gifted-chat
我正在使用 gifted 聊天库,并希望在初始呈现时使用键盘自动聚焦输入。我看到有一个命令式函数 focusTextInput
但我该如何调用它?
<GiftedChat
{...props}
messages={this.state.messages}
ref={(chat) => this.chat = chat }
onSend={messages => this.onSend(messages)}
user={{
_id: 1,
}}
/>
我尝试设置 ref
并直接在挂载上调用它,但这没有用。
因为图书馆已经有 textInputProps
textInputProps (Object) - Extra props to be passed to the TextInput
因此您可以使用 TextInput
的 autoFocus
属性
<GiftedChat
textInputProps={{autoFocus: true}}
messages={this.state.messages}
onSend={messages => this.onSend(messages)}
user={{
_id: 1,
}}
/>
我正在使用 gifted 聊天库,并希望在初始呈现时使用键盘自动聚焦输入。我看到有一个命令式函数 focusTextInput
但我该如何调用它?
<GiftedChat
{...props}
messages={this.state.messages}
ref={(chat) => this.chat = chat }
onSend={messages => this.onSend(messages)}
user={{
_id: 1,
}}
/>
我尝试设置 ref
并直接在挂载上调用它,但这没有用。
因为图书馆已经有 textInputProps
textInputProps (Object) - Extra props to be passed to the
TextInput
因此您可以使用 TextInput
autoFocus
属性
<GiftedChat
textInputProps={{autoFocus: true}}
messages={this.state.messages}
onSend={messages => this.onSend(messages)}
user={{
_id: 1,
}}
/>