-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added a fallback icon when getting error on loading image #8852
Added a fallback icon when getting error on loading image #8852
Conversation
@jayeshmangwani can you address this too! |
src/components/Icon/Expensicons.js
Outdated
import Connect from '../../../assets/images/connect.svg'; | ||
|
||
export { | ||
ActiveRoomAvatar, | ||
AdminRoomAvatar, | ||
Android, | ||
AnnounceRoomAvatar, | ||
FallbackAvatar, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move this to alphabetical order, thanks!
i.e it should be added belowExpensifyCard
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Santhosh-Sellavel I have changed the export order for ExpensifyCard and also changed the import order for the same
src/components/Avatar.js
Outdated
constructor(props) { | ||
super(props); | ||
this.state = { | ||
isErrorFetchingImage: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isErrorFetchingImage
can we rename it to imageError
or showFallbackAvatar
?
@jayeshmangwani
cc: @AndrewGable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replaced isErrorFetchingImage with imageError
Isn't there a view that wraps the avatar image to give it the correct rounded crop? Can we add the background color to them? |
@shawnborton no, we are doing a rounded crop in image styling, let me send you code Lines 33 to 40 in 68f0bbf
getAvatarStyle is do the rounded crop and we are using this at Avatar Lines 42 to 45 in 68f0bbf
and imageStyle value using here Lines 51 to 53 in 68f0bbf
if you want me to add the background color at getAvatarStyle function then we can do that |
Got it - are we able to set a background color on the image in some kind of way so we don't get a blank area while it loads? I know we can do something like this via CSS where you just give the image a background color and it shows even if the img src doesn't work or hasn't loaded yet. Otherwise we should wrap them so that we can achieve that. |
if I am not wrong then this is already completed, I have added backgroundcolor to the image, and works like this, |
Okay great! Are you able to show it in action via a screenshot so we can confirm? |
grey-placeholder.movYes sure, please check this video profile picture is taking time to load and default grey background is visible |
Perfect, thank you for sharing the video! Looks good to me. |
All good then! |
I think the avatar has a weird fill here, Is this the expected avatar @shawnborton can you confirm? |
Yeah, I believe the shape inside of the circle should be white. |
@jayeshmangwani Can you check this out there could be some unnecessary fill while showing the fallback avatar thanks! |
src/components/Avatar.js
Outdated
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...(!this.state.imageError ? {fill: this.props.fill} : {})} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this is messy, can't we simplify it?
Let avoid this unnecessary comments
// eslint-disable-next-line react/jsx-props-no-spreading
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we have to pass fill for the fallback avatar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are you trying to do here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if getting error then not passing the fill prop otherwise fill will be pass
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// eslint-disable-next-line react/jsx-props-no-spreading
{...(!this.state.imageError ? {fill: this.props.fill} : {})}
these lines were added for conditional fill prop for Icon component,
Please let me know that do we have to remove the fill prop for the fallback avatar? then I need to add a condition for the Icon component also, here default file is themeColor.icon
App/src/components/Icon/index.js
Lines 47 to 51 in 5f6d8db
<IconToRender | |
width={width} | |
height={height} | |
fill={this.props.fill} | |
/> |
App/src/components/Icon/index.js
Line 33 in 5f6d8db
fill: themeColors.icon, |
|
@jayeshmangwani |
@jayeshmangwani 1. Details page2. In App Settings page Workspace icon@shawnborton do we have fallback image for workspace icon, or what should be do here. 3. In Workspaces Settings4. Workspace view - General Settings |
Good catch, let's fix all of those and ideally they all behave the same way - they have a background color applied to fill the space while the image loads, and we use a fallback icon if we can't fetch an image. For the workspace icon, we could fall back on the default workspace icon (green background with a building) or we could take the same approach where we supply a gray version of the icon? Thoughts? |
A gray version of the icon yes sounds good so that all fallbacks will have the same theme style. But I'm fine with the default green fill with the building also. |
Here is a gray fallback version of the workspace avatar: |
Can you resolve those conflicts @jayeshmangwani |
@Santhosh-Sellavel I have merged the latest main to the current branch, and changes have been made that you have suggested except for 1 change, I have commented on the reason for the change let me give you the URL of the change please let me know what conflicts have to be solved, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jayeshmangwani
Need to update the comment otherwise looks good. Tests well for me.
Also @AndrewGable, can you have a look at this when you have time.
src/components/Avatar.js
Outdated
@@ -23,6 +24,9 @@ const propTypes = { | |||
|
|||
/** The fill color for the icon. Can be hex, rgb, rgba, or valid react-native named color such as 'red' or 'blue' */ | |||
fill: PropTypes.string, | |||
|
|||
/** Function for using fallback avatar */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn’t make any sense, can we add something more meaningful!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Santhosh-Sellavel does this looks good ?
A fallback avatar component to display when there is an error on loading remote URL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A fallback avatar icon to display when there is an error on loading avatar from remote URL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AndrewGable Any thoughts?
@Santhosh-Sellavel should I update the comment if this comment message is final? |
Looks good! @jayeshmangwani |
@Santhosh-Sellavel - Can you approve? Then I will review! Thanks. |
PR Reviewer Checklist
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good & tests well for me!
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
🚀 Deployed to staging by @AndrewGable in version: 1.1.63-0 🚀
|
🚀 Deployed to staging by @AndrewGable in version: 1.1.63-0 🚀
|
🚀 Deployed to production by @AndrewGable in version: 1.1.63-2 🚀
|
Heads up! This PR was not carefully tested again style issues which caused this #12645 |
Heads up! This bug #12712 was caused due to missing offline tests on this PR. |
I'm not sure how this caused that, here we have added only fallback if image was not available, can you brief @parasharrajat so we could understand what exactly went wrong, thanks! |
So this PR added logic to handle image load failure via |
Details
Fixed Issues
$ #8291
Tests
Another way to test
PR Review Checklist
Contributor (PR Author) Checklist
### Fixed Issues
section aboveTests
sectionQA steps
sectiontoggleReport
and notonIconClick
)src/languages/*
filesSTYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
displayName
propertythis
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)PR Reviewer Checklist
### Fixed Issues
section aboveTests
sectionQA steps
sectiontoggleReport
and notonIconClick
).src/languages/*
filesSTYLE.md
) were followed/** comment above it */
displayName
propertythis
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)QA Steps
Another way to test
Screenshots
Web
8291-web.mov
Mobile Web
8291-mWeb.mov
Desktop
8291-Desktop.mov
iOS
8291-ios.mov
Android
8291-Android.1.mp4