在 React Native 天才聊天中,我如何将点击作为普通消息处理?
In react native gifted chat, how would I process a click as an ordinary message?
我正在引用此处的代码:
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 控制输入文本。您可以使用该道具来控制输入的文本。
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 implement onInputTextChanged
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})}
/* ... */
/>
您无需模拟按钮按下即可实现功能:
我正在引用此处的代码:
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 控制输入文本。您可以使用该道具来控制输入的文本。
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})}
/* ... */
/>
您无需模拟按钮按下即可实现功能: