javascript - How do you render item time under bubble chat react native gifted chat? - Stack Overflow

I use React Native Gifted Chat To create a UI chat and I want to render the chat time and symbol under

I use React Native Gifted Chat To create a UI chat and I want to render the chat time and symbol under the bubble chat.

I want make like this image :

I have tried to use the rendering message but no luck, please help.

I use React Native Gifted Chat To create a UI chat and I want to render the chat time and symbol under the bubble chat.

I want make like this image :

I have tried to use the rendering message but no luck, please help.

Share asked Feb 6, 2020 at 9:42 zidniryizidniryi 1,3513 gold badges16 silver badges37 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

I was just working on this my self. What you need to do is to have custom renderBubble in which you wrap the with your own ponents. It would look something like this. The first part of the code is just the alignment of timestamp to the left or right, depending if the message was written by the current user or not.

renderBubble(props) {
    var sameUserInPrevMessage = false;
    if (props.previousMessage.user !== undefined && props.previousMessage.user) {
      props.previousMessage.user._id === props.currentMessage.user._id ? sameUserInPrevMessage = true : sameUserInPrevMessage = false;
    }

    var messageBelongsToCurrentUser = currentUserId == props.currentMessage.user._id;
    return (
      <View>
        {!sameUserInPrevMessage && <View
          style={messageBelongsToCurrentUser ? styles.messageTimeAndNameContainerRight : styles.messageTimeAndNameContainerLeft}
        >
          
        <Bubble
          {...props}
        />
          <Text style={styles.messageTime}>{moment(props.currentMessage.createdAt).format("LT")}</Text>
          <Text style={styles.messageUsername}>{props.currentMessage.user.name}</Text>
        </View>}
      </View>
    )
  }

also put this in the GiftedChat ponent renderMessage={this.renderBubble}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744931565a4601771.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信