FaridSafi / react-native-gifted-chat

💬 The most complete chat UI for React Native
https://gifted.chat
MIT License
13.47k stars 3.55k forks source link

Misalignment of UI when render two message with same user and showAvatarForEveryMessage is disabled #2539

Open manindervolumetree opened 1 week ago

manindervolumetree commented 1 week ago

I'm facing an issue when showAvatarForEveryMessage = false while sending multiple message from same user. On message in which avatar is hidden takes default image size which is height = 36 and width = 36. So UI is getting misaligned.

Steps to Reproduce / Code Snippets

showAvatarForEveryMessage = false decrease avatar size to height 15 and width 15 Send multiple message from same user Simulator Screenshot - iPhone 15 - 2024-09-19 at 14 11 10

Expected Results

Expected result is the bubble should be alined Simulator Screenshot - iPhone 15 - 2024-09-19 at 14 10 38

fukemy commented 11 hours ago

better using your custom renderAvatar, see my code snippet for example:

const renderAvatar = (props) => {
        const { user = {} } = props.currentMessage
        const { user: pUser = {} } = props.previousMessage
        let isSameUser = pUser._id === user._id
        if (isSameUser) {
            // check if previous message is call
            // this case will now show user avatar before for current message
            if (props.previousMessage.call && roomDetailRef.current.Type === RoomType.Group) {
                isSameUser = false
            }
        }
        const isSelf = user._id === 1
        const isSameDate = utils.isSameHour(props.currentMessage, props.previousMessage)
        const shouldNotRenderName = (isSameUser && isSameDate) || isSelf
        if (shouldNotRenderName) return <View style={styles.nonAvatar} />
        return (
            <Avatar
                {...props}
                containerStyle={{
                    left: {
                        marginTop: isContactRoom ? 0 : 15,
                        marginRight: 0,
                    }
                }}
            />
        )
    }