MessageAvatar for custom Message shows up unexpectedly, seemingly at random.
Describe the bug When using a custom Message for MessageList, we are disabling the showing of the current user avatar, but we show the avatar of the recipient. Sometimes, seemingly at random, the avatar of the other user shows on the righthand side of the conversation (side of current user messages). The random avatar disappears after the current user sends a message to the chat.
Dev environment info (please complete/provide the following information):
- stream-chat-expo @^0.10.1 (stream-chat-react-native/stream-chat-expo)
- Expo SDK 36
- iOS emulator and physical device as well as Android emulator and physical device
To Reproduce Steps to reproduce the behavior:
- Go to chat from ChannelList view
- See wrong avatar / avatar that shouldn't be there
Expected behavior The current user avatar should not appear at all, nor should it be the avatar of the other user in conversation.
Additional context Here is the code for the custom component and how we are incorporating into the MessageList stream component:
MessageList:
<MessageList
Message={props => (
<ChatMessage
ownMessage={props.isMyMessage(props.message)}
theme={theme}
{...props}
/>
)}
/>
Custom message component:
export const ChatMessage = ({ theme, ownMessage, ...props }) => {
const { message, isMyMessage, groupStyles } = props;
return (
<View>
{!ownMessage &&
(groupStyles[0] === `top` || groupStyles[0] === `single`) && (
<Text
style={{
fontSize: 12,
color: Colors.mediumGray,
textAlign: `left`,
left: 45,
}}
>
{message.user.name}
</Text>
)}
<MessageSimple
MessageAvatar={() =>
ownMessage ? null : (
<MessageAvatar
message={message}
isMyMessage={isMyMessage}
groupStyles={groupStyles}
/>
)
}
style={{
message: {
content: {
textContainer: {
css: {
backgroundColor: ownMessage
? theme.primary
: Colors.lightGray,
},
},
markdown: {
text: {
color: ownMessage ? theme.fontColor : Colors.black,
},
},
},
},
}}
{...props}
/>
</View>
);
};
Screenshots
Here is a screenshot of the bug.

@kgstaley thanks for detailed description. I will test the your code in our sample app and get back to you asap :)
@kgpasta I think that user avatar on right side is coming from MessageStatus. It basically indicates that the other user (Kerry Tester in this case) has read your message.
<ChatMessage ownMessage={props.isMyMessage(props.message)} theme={theme} {...props} />
Whats the value of theme prop that you have provided to ChatMessage component exactly? Maybe there is some issue there
Hey thanks for getting back so quickly. The theme prop that we are passing is just an object that contains hexcode values for color. i.e.
Object {
"dark": "hsl(253.20000000000005, 50.2%, 37.8%)",
"darker": "hsl(253.20000000000005, 50.2%, 25.2%)",
"fontColor": "#FFFFFF",
"key": "PURPLE",
"light": "hsl(253.20000000000005, 50.2%, 65.5%)",
"lighter": "hsl(253.20000000000005, 50.2%, 75.6%)",
"primary": "#5d41c0",
"translucentHighlight": "hsla(253.20000000000005, 50.2%, 75.6%, 0.2)",
}
So I don't see how that might cause an issue, as I'm only using it for styling the colors of the messages.
After digging into our custom styles for chat, it does indeed seem to be an issue regarding the MessageStatus component. Below I have pasted our custom theme as well as my debug code to wrap the status readByContainer
const chatTheme = {
colors: {
primary: theme.primary,
},
avatar: {
image: {
css: {
height: 45,
width: 45,
borderRadius: 45 / 2,
},
},
},
message: {
status: {
readByContainer: {
css: {
overflow: 'hidden',
borderColor: 'red',
borderWidth: 3,
},
},
},
content: {
markdown: {
text: {
fontSize: Typography.baseFontSize,
},
},
},
},
};
We apply this to the Chat and its children via the style prop on Chat:
<Chat style={chatTheme} client={chatClient}>
<View style={{ flexGrow: 1 }}>
<View style={{ flex: 1, paddingBottom: 8 }}>
<Channel channel={channel}>
<MessageList
additionalFlatListProps={{
// use list footer because flatlist orientation is reversed
ListFooterComponent: (
<MessageHeader
theme={theme}
photoSharing={photoSharing}
otherMembers={otherMembers}
personaRelationships={personaRelationships}
toggleOptionsModal={this.toggleOptionsModal}
/>
),
}}
Message={props => (
<ChatMessage
ownMessage={props.isMyMessage(props.message)}
theme={theme}
{...props}
/>
)}
/>
</Chat>
It indeed looks like a problem with our custom chat theme applied to Chat. Do you have any suggestions as how to customize the MessageAvatar component for only the other user and not apply our avatar image styles globally? I know that I can set the readByContainer overflow to 'hidden' and then set the size of the container but I would much prefer to just scale the image down rather than contain it in the readByContainer. Thanks.
Hey @kgstaley you can take a look at this example - https://github.com/GetStream/stream-chat-react-native/blob/master/docs/cookbook.md#customdifferent-style-for-received-and-sent-messages
Here I am adding different styles for sent message and received messages.
Let me know if you have any doubts :)
@kgpasta any update? Did it work?
Hi sorry, got caught up with some other work. What I ended up doing was passing a conditional statement into the style prop of our custom message component, like so:
avatar: !ownMessage && {
image: {
css: {
height: 45,
width: 45,
borderRadius: 45 / 2,
},
},
},
Works like a charm thanks!