【问题标题】:why my chat is not serialize according to the date with react-native-gifted chat?为什么我的聊天没有根据带有 react-native-gifted 聊天的日期进行序列化?
【发布时间】:2020-05-20 09:11:09
【问题描述】:

我正在尝试通过使用 react native 有天赋的聊天道具发送消息 但是有些如何它没有按天显示序列化 我可以使用 renderDay 道具,但还不够

这是我的代码

<GiftedChat
          messages={_.orderBy(messages, ['createdAt'], ['desc'])}
          onSend={(mes) => onSend(mes)}
          scrollToBottom={true}
          isTyping={typingStatus}
          renderFooter={() => (typingStatus == true ? <Typing /> : null)}
          renderSend={(props) => (
            <View
              style={{
                flexDirection: 'row',
                alignItems: 'center',
                height: 40,
              }}>
              <Icon
                raised
                name="attachment"
                color="#08CAF9"
                onPress={async () => await setAchieveSend(true)}
                reverse={AchieveSend == false ? false : true}
              />
              <Send {...props}>
                <View style={Styles.btnSend}>
                  <Icon raised name="send" size={24} color="#08CAF9" />
                </View>
              </Send>
            </View>
          )}
          user={{
            _id: ApiUserId,
            name: '',
            avatar: '',
          }}
        />

这是图片

【问题讨论】:

    标签: arrays react-native chat message react-native-gifted-chat


    【解决方案1】:

    抱歉来晚了,问题是GiftedChat以反转模式附加消息,你可以设置inverted={false}

    <GiftedChat messages={messages} inverted={false} />
    

    这可能会对你有所帮助....

    【讨论】:

    • 日期保存为日期对象的问题..不是消息反转模式
    【解决方案2】:

    请尝试以这种方式追加。

    
    GiftedChat.append(prevState, newMessage)
    
    

    由于 GiftedChat 做了一些内部附加。 将消息设置为

     setMessages(prevState => GiftedChat.append(prevState, newMessage));
    

    【讨论】:

      猜你喜欢
      • 2018-08-31
      • 1970-01-01
      • 1970-01-01
      • 2020-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多