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.

Avatar not using fallback on title when source is undefined

See original GitHub issue

Explain what you did

Set source to undefined to show the placeholder title

Expected behavior

If source is undefined fallback on the defined title as placeholder

Describe the bug

Avatar does not fallback to placeholder title when source set to undefined.

To Reproduce

Example:

const [avatar, setAvatar] = useState({uri: 'https://s3.amazonaws.com/uifaces/faces/twitter/ladylexy/128.jpg' });

const removeAvatar = () => {
 setAvatar(undefined);
}

<Avatar
           rounded
           size="large"
           title={benutzerName.charAt(0)}
           containerStyle={styles.avatarContainer}
           showAccessory
           onAccessoryPress={removeAvatar}
           source={avatar}
    />

Screenshots

Avatar with image: image

Avatar with source set to undefined: image

Your Environment (please complete the following information):

software version
react-native-elements 2.0.4
react-native 0.63.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
flyingcirclecommented, Jul 23, 2020

@daryllukas is correct. The placeholder background is transparent and the default text color is white. So you either need to change the default text color style in the Avatar, or change your background color.

2reactions
djhrcommented, Jul 20, 2020

avatar seems quite broken on v2, even the basic examples from docs doesn’t work, e.g.

// Avatar with Title
<Avatar rounded title="MD" />

// Avatar with Icon
<Avatar rounded icon={{ name: 'home' }} />
Read more comments on GitHub >

github_iconTop Results From Across the Web

avatar not showing fallback icon when source prop becomes ...
I'm using an Avatar component with an image source and an icon as a fallback for a profile picture. If the image source...
Read more >
react-native-elements avatar - problem with fallback to title on ...
I'm using a cloud based storage for avatar images. If an image for a user doesn't exist I want to fallback to the...
Read more >
react-avatar - npm
Start using react-avatar in your project by running `npm i react-avatar`. ... If not set we will fallback to either name or value....
Read more >
Avatars - Salesforce Lightning Design System | React
If the imgSrc prop is undefined, and if a label or initials prop is available, the fallback avatar will render with initials.
Read more >
Avatar API - Material UI - MUI
API reference docs for the React Avatar component. Learn about the props, CSS, ... Used to render icon or text elements inside the...
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