javascript - 在 React Native 天才聊天中,我如何将点击作为普通消息处理?

标签 javascript react-native react-native-gifted-chat

我引用的是这里的代码:

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 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})}
  /* ... */
/>

关于javascript - 在 React Native 天才聊天中,我如何将点击作为普通消息处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50655296/

相关文章:

android - 将 Firestore 与移动 native 应用程序(React native )一起使用时的逆向工程风险

react-native - 如何在 react-native-gifted-chat 中发送图像?

javascript - 为什么 react-native-gifted-chat 不能从 firebase 时间戳正确显示时间?

javascript - 精确匹配单词的正则表达式影响特殊字符匹配

javascript - 完美的亚马逊链接正则表达式

javascript - 在css类中覆盖属性时如何获取css属性的确切值

javascript - Three.js:围绕物体的旋转?

React-Native 启动画面控制时间

javascript - Flex View 在 React Native 中重叠