question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question - How to use renderAvatar?

See original GitHub issue

Question

I find the documentation fairly difficult to go on, as renderAvatar seems like it would require arguments in order to pass the source of the avatar into the component.

Currently we are trying to make the Avatar buttons on our application intractable. By going through the Source i see that onPress is supported in GiftedAvatar but I see no way to call it. This leads me to believe that we must use renderAvatar and pass a <GiftedAvatar component in there manually, while supplying the onPress prop. My question is, how would I go about getting the avatar link for the current user to pass it in to the <GiftedAvatar> Component.

As per the “documentation” on the ReadME, all that is shown is that there is a renderAvatar function.

How do we go about getting the avatar for the displayed message to pass to the component.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9

github_iconTop GitHub Comments

3reactions
MrGurnscommented, Feb 27, 2018

For anyone still confused as how to use this:

//each message structure
var newItem = {
  text: item.text,
  user: {
    _id: item.user_id,
    name: user.name,
    avatar: true,
  },
  avatarProps: {
    name: user.name,
    icon: user.icon,
  },
  createdAt: item.created_date,
   _id: item._id,
};

//in render
<GiftedChat
  messages={this.convertToGiftedMessage}
  onSend={messages => this.addMessage(messages)}
  user={{
  _id: localDataStore.activeUser,
  }}
  keyboardShouldPersistTaps={'never'}
  renderAvatar={(props) => {
    const { avatarProps } = props.currentMessage;
    if (avatarProps.name) {
      return(
        <UserAvatar size="40" name={avatarProps.name} src={avatarProps.icon} />
      );
    }
    return(null);
  }}
/>

Passing true to the avatar was key for me, cause if it is null, then it won’t render the avatar, nor call the renderAvatar prop.

1reaction
hunter547commented, Apr 17, 2020

@jamesdmurphy51 I’m sure you already found a workaround/solution for this but it’s the UserAvatar component from this library. Gives a little more control over the avatar and the creator of react-native-gifted-chat was inspired by this library, giving credit (in the form of a comment) in node_modules/react-native-gifted-chat/lib/GiftedAvatar.js:

Read more comments on GitHub >

github_iconTop Results From Across the Web

Building a Chat App with React Native and Gifted Chat (Part 4)
So far you learned how to use the Gifted Chat React Native ... Define a new method renderAvatar to pass into your GiftedChat...
Read more >
Paperclip gem render avatar upload in different view
This will have to be matched with the appropriate model code etc, but should work to allow you to upload the appropriate avatar....
Read more >
New top bar should render avatar with a transparent background
3 Answers 3 · Interesting. · Yes - you've got a point there - I've never tried to use the "Upload image" option,...
Read more >
De render / re render - Avatar - Second Life Community
I have accidently de rendered a friends avatar and now cant see them. lol:manvery-happy:. How do I fix this?
Read more >
Estimated time to render Avatar on your computer
I think this qualifies as a Fermi question ... images ) - around 36 hours per frame of individual top AMD Processor at...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found