首页 > 解决方案 > React Native Gifted Chat:如何隐藏键盘和文本输入

问题描述

我正在使用 expo 制作一个 react native 应用程序,并且正在使用react-native-gifted-chat类似聊天的功能(https://github.com/FaridSafi/react-native-gifted-chat)。在此功能中,我只希望某些用户能够发送消息。不能的用户应该只能查看已发送的消息。

为了实现这一点,我需要一种方法来为无权发送消息的用户隐藏键盘/文本输入。我正在阅读文档,但不确定如何执行此操作。有没有办法隐藏键盘/文本输入并只加载消息?

不确定这是否相关,但我的天才聊天代码如下:

<GiftedChat
      messages={this.state.messages}
      placeholder="Send your thoughts?"
      onSend={(messages) => this.sendMessage(messages)}
      user={{
        ...user details
      }}
/>

谢谢!

标签: react-nativereact-native-gifted-chat

解决方案


只需传递null道具renderInputToolbar

<GiftedChat
    ...
    renderInputToolbar={() => { return null }}
/>

推荐阅读