stream-chat-swift icon indicating copy to clipboard operation
stream-chat-swift copied to clipboard

Initials Placeholder for ChatAvatarView

Open martindaum opened this issue 3 years ago • 9 comments

What are you trying to achieve?

If there is no image set for an Avatar, I would like to show a placeholder with the initials of the user instead of an avatar placeholder.

If possible, how can you achieve this currently?

I guess I could create a custom view for it and use a custom MessageContentView to inject it

What would be the better way?

The Android SDK falls back to the initials view, so it would be great if the iOS SDK also has the same behaviour.

GetStream Environment

GetStream Chat version: 4.16.0 GetStream Chat frameworks: StreamChat, StreamChatUI iOS version: Swift version: Xcode version: Device:

Additional context

martindaum avatar Jun 14 '22 12:06 martindaum

Hello @martindaum ,

The "initials as channel avatar" behavior is outdated, our current Design Kit has "merged avatars" as default. You can see it in Swift SDK and React SDK (https://getstream.io/chat/demos/messaging/)

If you want to implement this behavior yourself, you can do so as:

class InitialsChannelAvatarView: ChatChannelAvatarView {
    override func loadMergedAvatars(channel: ChatChannel) {
        // .. get initials from the member
        // assign the avatar
        loadIntoAvatarImageView(from: nil, placeholder: yourNewInitialsImage)
    }
}

and inject your new class via Components

Do you need more help regarding this?

b-onc avatar Jun 14 '22 14:06 b-onc

I would want it in the MessageView, not for the Channel Avatar!

martindaum avatar Jun 14 '22 14:06 martindaum

Ah, thanks for clarifying, I misunderstood.

Indeed it's a missing feature from Swift SDK. We're internally tracking this as CIS-1978.

Meanwhile, you can apply the same logic from my message above, customize MessageContentView.updateContent func to create your initials avatar if the user's avatar is nil and assign it to authorAvatarView

b-onc avatar Jun 14 '22 14:06 b-onc

Okay thanks! I will implement it that way!

martindaum avatar Jun 14 '22 16:06 martindaum

public private(set) var authorAvatarView: ChatAvatarView?

I am not able to set the authorAvatarView because the setter is private. In the samples I have seen you can assign a custom ChatAvatarView to components, but then I am not able to retrieve the name. I am missing something?

martindaum avatar Jun 15 '22 05:06 martindaum

You wouldn't assign authorAvatarView, you'd assign an image to authorAvatarView.imageView.image

b-onc avatar Jun 15 '22 15:06 b-onc

Hi @martindaum,

Im just following up in here. Did your issue got resolved? Or are you still encountering some issues?

Best, Boris

bielikb avatar Jun 23 '22 10:06 bielikb

Not an ideal solution, because I have to render an image instead of designing a custom view. But as a workaround it would work. It would help if we could inject a custom view for the avatar view (which also has access to content) instead of having to use an image.

martindaum avatar Jun 23 '22 11:06 martindaum

Hey @martindaum,

thanks for the feedback! Ill create an issue internally for us to review this part of our SDK.

Best, Boris

bielikb avatar Jun 27 '22 15:06 bielikb