File tree Expand file tree Collapse file tree 3 files changed +13
-7
lines changed
Expand file tree Collapse file tree 3 files changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import * as React from 'react'
22import { Image , StyleSheet , Text , View } from 'react-native'
33
44import { MessageType , Theme } from '../../types'
5- import { getUserAvatarNameColor , getUserName } from '../../utils'
5+ import { getUserAvatarNameColor , getUserInitials } from '../../utils'
66
77export const Avatar = React . memo (
88 ( {
@@ -23,7 +23,7 @@ export const Avatar = React.memo(
2323 author ,
2424 theme . colors . userAvatarNameColors
2525 )
26- const name = getUserName ( author )
26+ const initials = getUserInitials ( author )
2727
2828 if ( author . imageUrl ) {
2929 return (
@@ -41,9 +41,7 @@ export const Avatar = React.memo(
4141
4242 return (
4343 < View style = { [ styles . avatarBackground , { backgroundColor : color } ] } >
44- < Text style = { theme . fonts . userAvatarTextStyle } >
45- { name ? name [ 0 ] . toUpperCase ( ) : '' }
46- </ Text >
44+ < Text style = { theme . fonts . userAvatarTextStyle } > { initials } </ Text >
4745 </ View >
4846 )
4947 }
Original file line number Diff line number Diff line change @@ -38,7 +38,8 @@ export interface MessageTopLevelProps extends TextMessageTopLevelProps {
3838 /** Render a text message inside predefined bubble */
3939 renderTextMessage ?: (
4040 message : MessageType . Text ,
41- messageWidth : number
41+ messageWidth : number ,
42+ showName : boolean
4243 ) => React . ReactNode
4344 /** Show user avatars for received messages. Useful for a group chat. */
4445 showUserAvatars ?: boolean
@@ -145,7 +146,8 @@ export const Message = React.memo(
145146 ) (
146147 // type-coverage:ignore-next-line
147148 excludeDerivedMessageProps ( message ) as MessageType . Text ,
148- messageWidth
149+ messageWidth ,
150+ showName
149151 )
150152 default :
151153 return null
Original file line number Diff line number Diff line change @@ -31,6 +31,12 @@ export const getTextSizeInBytes = (text: string) => new Blob([text]).size
3131export const getUserAvatarNameColor = ( user : User , colors : ColorValue [ ] ) =>
3232 colors [ hashCode ( user . id ) % colors . length ]
3333
34+ /** Returns user initials (can have only first letter of firstName/lastName or both) */
35+ export const getUserInitials = ( { firstName, lastName } : User ) =>
36+ `${ firstName ?. charAt ( 0 ) ?? '' } ${ lastName ?. charAt ( 0 ) ?? '' } `
37+ . toUpperCase ( )
38+ . trim ( )
39+
3440/** Returns user name as joined firstName and lastName */
3541export const getUserName = ( { firstName, lastName } : User ) =>
3642 `${ firstName ?? '' } ${ lastName ?? '' } ` . trim ( )
You can’t perform that action at this time.
0 commit comments