【问题标题】:React Native Gifted Chat: How to hide keyboard and text inputReact Native Gifted Chat:如何隐藏键盘和文本输入
【发布时间】:2020-11-21 17:54:36
【问题描述】:

我正在使用 expo 制作一个 react 本机应用程序,并且正在使用 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-native react-native-gifted-chat


    【解决方案1】:

    只需通过null 获取道具renderInputToolbar

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

    【讨论】:

    • 这似乎不起作用。键盘/文本输入仍显示在页面底部。
    • 我的错。已编辑。
    • 有没有办法让键盘的高度为0?现在它消失了,但消息和屏幕底部之间仍有 44px 的间隙。谢谢!
    【解决方案2】:

    minInputToolbarHeight 属性设置为零:

    <GiftedChat
        ...
        minInputToolbarHeight=0
    />
    

    【讨论】: