gpt4 book ai didi

react-native - 你如何在 react-native-gifted-chat 中自动聚焦输入框

转载 作者:行者123 更新时间:2023-12-02 00:34:26 26 4
gpt4 key购买 nike

我正在使用 gifted 聊天库,并希望在初始渲染时使用键盘自动聚焦输入。我看到有一个命令式函数 focusTextInput 但我该如何调用它呢?

<GiftedChat
{...props}
messages={this.state.messages}
ref={(chat) => this.chat = chat }
onSend={messages => this.onSend(messages)}
user={{
_id: 1,
}}
/>

Github Repo

我尝试设置 ref 并在 did mount 上直接调用它,但这没有用。

最佳答案

因为库已经有了textInputProps

textInputProps (Object) - Extra props to be passed to the TextInput

因此您可以使用 autoFocus TextInput

的 Prop
<GiftedChat
textInputProps={{autoFocus: true}}
messages={this.state.messages}
onSend={messages => this.onSend(messages)}
user={{
_id: 1,
}}
/>

关于react-native - 你如何在 react-native-gifted-chat 中自动聚焦输入框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50298484/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com