ListItem Avatar Not Displaying
Asked Answered
S

3

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?

Seep answered 27/11, 2018 at 7:27 Comment(5)
are you using any library or ListItem is your custom component, if it is a custom component please post its code for better understandingLabe
It is from react-native-elementsSeep
Try avatar={{ uri: item.icon }}Collision
That did the trick! Do you know what the diff is between avatar and leftAvatar?Seep
leftAvatar is in beta version and avatar is in stable version as per the docs.Collision
C
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 } }}
Collision answered 27/11, 2018 at 7:54 Comment(0)
L
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}
      />
Labe answered 27/11, 2018 at 7:36 Comment(4)
just to test if it is getting your props try adding this rounded: true in your leftAvatar objectLabe
When I use leftAvatar= I get nothing but when I use avatar= I get a grey box without rounded corners.Seep
For me leftAvatar works with local image, and get grey box with external urlWillywilly
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.Premarital
M
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" }
      }}
Muscat answered 16/3, 2020 at 18:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.