7

As part of a FlatList, I render each ListItem (from the react-native-elements library) where I try to display an avatar (icon) from a url to a photo:

  <ListItem
     avatar={{ source: { uri: item.icon } }} 
   />

All the other props display fine but on the left side of each cell I just get a grey box. I've logged the value of item.icon and it points to a valid photo. Do I need to download the photo and then provide a local link to it?

How can I get the photo to show up as the cell's avatar?

The Kraken
  • 3,158
  • 5
  • 30
  • 67

3 Answers3

4

You're using the wrong object for the image avatar.

Stable Version

Either

avatar={{ uri: item.icon }}

OR

avatar={<Avatar
           rounded
           source={{uri: item.icon}}
           title={'Sample Title'}
       />}

Beta Version

leftAvatar={{ source: { uri: item.icon } }}
Pritish Vaidya
  • 21,561
  • 3
  • 58
  • 76
3

According to react-native-elements they have leftAvatar and no just avatar

<ListItem
        key={i}
        leftAvatar={{ source: { uri: l.avatar_url } }}
        title={l.name}
        subtitle={l.subtitle}
      />
Ammar Tariq
  • 799
  • 2
  • 13
  • 29
  • just to test if it is getting your props try adding this rounded: true in your leftAvatar object – Ammar Tariq Nov 27 '18 at 07:41
  • When I use `leftAvatar=` I get nothing but when I use `avatar=` I get a grey box without rounded corners. – The Kraken Nov 27 '18 at 07:48
  • For me leftAvatar works with local image, and get grey box with external url – Eric Dec 10 '19 at 08:52
  • Works for me in expo web view, but on my mobile device, I get a grey round avatar with no image. Tried calling the image both locally and from the web. – Paddymac Apr 06 '20 at 15:46
0

This is what I did to customize my leftAvatar with icons (react-native-elements / flatlist)

 leftAvatar={{
        icon: { name: item.icon, type: "ionicon", color: "black" },
        size: "large",
        overlayContainerStyle: { backgroundColor: "white" }
      }}
Diego Feder
  • 79
  • 1
  • 4