React-native-gifted-chat: Why don't you show the name

Created on 20 Sep 2016  路  3Comments  路  Source: FaridSafi/react-native-gifted-chat

Thank you for your components
But I want to show you the names of both parties.What should I do?

Additional Information

  • React Native version: 0.33
  • react-native-gifted-chat version: 0.0.10
  • Platform(s) (iOS, Android, or both?): [both]

Most helpful comment

for those we still need any help, you could do something like below.

import { GiftedChat, Bubble } from 'react-native-gifted-chat'

renderName = (props) => {
  const { user: self } = this.state
  const { user = {} } = props.currentMessage
  const { user: pUser = {} } = props.previousMessage
  const isSameUser = pUser._id === user._id
  const isSelf = user._id === self._id
  const shouldNotRenderName = isSameUser

  return shouldNotRenderName ? (
    <View />
  ) : (
    <Text
      style={[ isSelf ? styles.selfUser : styles.otherUser ]}>
      {user.name}
    </Text>
  )
}

renderBubble = (props) => {
  return (
      <View>
        {this.renderName(props)}
        <Bubble {...props} />
      </View>
    )
  }
}

render () {
  return (
    <GiftedChat
      renderBubble={this.renderBubble}
      />
  )
}

All 3 comments

Just inherit from Bubble and render customised bubble component with name in renderBubble prop of

Is there a way to show the name only on the first bubble of a sequence of bubbles of the same user?

for those we still need any help, you could do something like below.

import { GiftedChat, Bubble } from 'react-native-gifted-chat'

renderName = (props) => {
  const { user: self } = this.state
  const { user = {} } = props.currentMessage
  const { user: pUser = {} } = props.previousMessage
  const isSameUser = pUser._id === user._id
  const isSelf = user._id === self._id
  const shouldNotRenderName = isSameUser

  return shouldNotRenderName ? (
    <View />
  ) : (
    <Text
      style={[ isSelf ? styles.selfUser : styles.otherUser ]}>
      {user.name}
    </Text>
  )
}

renderBubble = (props) => {
  return (
      <View>
        {this.renderName(props)}
        <Bubble {...props} />
      </View>
    )
  }
}

render () {
  return (
    <GiftedChat
      renderBubble={this.renderBubble}
      />
  )
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

luisfuertes picture luisfuertes  路  3Comments

xcxooxl picture xcxooxl  路  3Comments

arayaryoma picture arayaryoma  路  3Comments

cassioseffrin picture cassioseffrin  路  3Comments

pentarex picture pentarex  路  3Comments