簡體   English   中英

使用 React-Native-Gifted-Chat 時如何隱藏 Android 鍵盤?

[英]How do I hide the Android Keyboard when using React-Native-Gifted-Chat?

我在我的 RN/Expo 應用程序中使用 React-Native-Gifted-Chat。 當用戶輸入消息時,消息框應隨鍵盤一起向上移動。 這是我在 iOS 上得到的行為,但在 Android 上,它掩蓋了盒子。

我試過在“GiftedChat”道具周圍附上一個“KeyboardAvoidingView”,但它會將消息框推到屏幕外。

我還嘗試了下面看到的內容,雖然鍵盤沒有消失,但在打字時它仍然覆蓋了消息框。

下面是我的代碼:

<KeyboardAvoidingView>
    <SafeAreaView style = { styles.header }>
      <GiftedChat
        messages={}
        showAvatarForEveryMessage={true}
        onSend={messages => onSend(messages)}
        user={{
          _id:1,
        }}
      />
    </SafeAreaView>  
    </KeyboardAvoidingView>

好的,所以下面的解決方案對我有用,但它可能只是因為這個屏幕只是一個“聊天屏幕”,意思是:

有人進入這個屏幕是為了發送和接收消息,沒有別的。

為了解決這個問題,我消除了所有的“視圖”,它給了我想要的行為。

以下是更新后的代碼:

return(
    <GiftedChat
        messages={}
        showAvatarForEveryMessage={true}
        onSend={messages => onSend(messages)}
        user={{
          _id:1,
        }}
    />
)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM