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 badges1 Answer
Reset to default 5I 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条)