我引用的是这里的代码:
https://snack.expo.io/@xcarpentier/gifted-chat
就代码而言,当有人按下时:
#awesome
由于以下原因将触发警报:
onPress: props => alert(`press on ${props}`),
我想做的是让媒体将“Hello world”发送到输入中,就好像用户只是输入消息然后按回车键一样。
看来我需要将“Hello world”发送到此函数中:
onSend(messages = []) {
this.setState((previousState) => ({
messages: GiftedChat.append(previousState.messages, messages),
}));
}
但我不确定该怎么做。
我怎样才能让新闻界像普通的聊天输入一样发挥作用?
最佳答案
GiftedChat 有一个 text
prop控制输入文本。您可以使用该 Prop 来控制输入的文本。
If you decide to specify a
text
prop, GiftedChat will no longer manage its own internal text state and will defer entirely to your prop. This is great for using a tool like Redux, but there's one extra step you'll need to take: simply implementonInputTextChanged
to receive typing events and reset events (e.g. to clear the text onSend)
示例
<GiftedChat
text={this.state.inputText}
onInputTextChanged={text => this.setState({inputText: text})}
/* ... */
/>
关于javascript - 在 React Native 天才聊天中,我如何将点击作为普通消息处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50655296/