-
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
Add avatar upload density constraints #13899
Conversation
@MonilBhavsar Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
src/CONST.js
Outdated
@@ -32,6 +32,11 @@ const CONST = { | |||
// Minimum width and height size in px for a selected image | |||
AVATAR_MIN_WIDTH_PX: 80, | |||
AVATAR_MIN_HEIGHT_PX: 80, | |||
|
|||
// Maximum width and height size in px for a selected image | |||
AVATAR_MAX_WIDTH_PX: 2048, |
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.
We are having issues when avatar height or width is greater than around 4500/4800 pixels.
Facebook uses the following resolution:
FB Avatar size:
Max Size: 2048px X 2048px
Min Size: 168px X 168px
Aspect ratio: 1:1
So, max size is set 2048px here. @tgolen Are we okay with this or want to increase this size?
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.
While I’m also testing various resolutions on my end, could you help me with testing e.g. 4096 on different platforms including real mobile device ? @sobitneupane
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.
We are having issues when avatar height or width is greater than around 4500/4800 pixels.
@sobitneupane could you please expand on what kind of issues we have seen?
If I'm not wrong, looks like 2048 is coming from this reference?
And, comparing to other platforms, it seems more than enough. I would be down to decrease it, but not increase it.
@shawnborton can we please have your thoughts in this case
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.
We are having issues when avatar height or width is greater than around 4500/4800 pixels.
@sobitneupane could you please expand on what kind of issues we have seen?
This issue was reported for images larger than 5000 pixels. (https://expensify.slack.com/archives/C049HHMV9SM/p1669089889220939)
If I'm not wrong, looks like 2048 is coming from this reference? And, comparing to other platforms, it seems more than enough. I would be down to decrease it, but not increase it.
With 2048 px AVATAR_MAX_WIDTH_PX, users might face difficulty uploading profile avatar with Take photo option (Upload photo> Take photo) in native because image resolution might be greater than 2048px.
RPReplay_Final1672660161.MP4
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.
Thank you, got it!
I did some testing on Whatsapp, and looks like it compresses the image as per their accepted criteria.
I feel like we should do the same, and not ask user to compress the image according to our standards.
If we increase the limit for now to allow photos captured directly through camera, it doesn't really fix the issue, no? or it will create a new issue - "Users on this device can't upload profile picture directly through camera"?
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.
Just chiming in to say I agree with Monil's line of thought above. 2048 seems fine to me assuming we don't accidentally block things like camera uploads.
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 did we choose 2048? Why wouldn't we just choose the max size until we know there can be an issue with some native devices (eg. 4400)? I think that before we consider pre-compression, we should understand what the resolution is of native camera uploads first.
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.
FYI - By default my iPhone 13 Pro takes 3024 × 4032
so I agree 2048
is too small to block on.
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.
I can:
- Increase max resolution to: 4096px
- Set max resolution for camera upload to: 4096px
https://github.com/react-native-image-picker/react-native-image-picker#options
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.
Oh, cool. I was wondering if we could specify a max for the camera.
Hey @MonilBhavsar could you help us reviewing this PR. |
Yes, and also requesting review from @tgolen |
Would be cool if we can get this easy PR merged today. |
Hello @MonilBhavsar, do we want to increase AVATAR_MAX_WIDTH_PX/AVATAR_MAX_HEIGHT_PX or keep it 2048? #13899 (comment) |
Commented in that thread |
Screenshots/VideosWebScreen.Recording.2023-01-02.at.16.56.11.movMobile Web - ChromeScreen.Recording.2023-01-02.at.22.08.39.movMobile Web - SafariUntitled.movDesktopScreen.Recording.2023-01-02.at.22.20.26.moviOSUntitled.movAndroidScreen.Recording.2023-01-02.at.22.11.44.mov |
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.
Commented on the thread, but I feel like this will create a new issue and add overhead to the user experience when uploading images that are captured using latest smartphones
Here is the comment from @tgolen
|
@MonilBhavsar So we all agreed on this solution with validating image resolution, would be cool if we can get this reviewed today. |
The full checklist needs to be filled out in the PR description and there is no reviewer checklist posted yet. I will review the code this morning. |
&& (resolution.height <= CONST.AVATAR_MAX_HEIGHT_PX && resolution.width <= CONST.AVATAR_MAX_WIDTH_PX) | ||
); | ||
|
||
return getImageResolution(image).then(isResolutionWithinRange); |
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 please update this code so that there is no isResolutionWithinRange
variable? The method can be defined directly in then()
and it is easier to read and follow.
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.
Sure, fixed.
@@ -0,0 +1,11 @@ | |||
/** | |||
* Returns image dimensions for image selected from react-native-image-picker |
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.
Please add more of an explanation here of why it's OK for this method to be a no-op (since the height and width are already included with the image object)
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.
updated
@@ -0,0 +1,28 @@ | |||
/** | |||
* Returns image dimensions for picked File object | |||
* File object is returned as a result of a user selecting files using the <input> element |
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.
Please add more of an explanation here for the platform-specific usage of this file such as this being the best way to get the height/width of an image on web, and you can also explain why you used onload vs the other option you were considering (I remember you mentioned something about performance).
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.
updated.
It also looks like there are commits on this branch that are not signed, so it cannot be merged until that's fixed. |
061b00c
to
b0a46ea
Compare
@tgolen Increased allowed width / height to 4096px, tested everything locally and addressed all comments. Ready for re-review. |
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 great! I love the comments. Nice work on those
@sobitneupane I see you tested with some screenshots, were you also going to post the full 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.
@azimgd When I try to upload avatar larger than 4096px in iOS/Safari, neither resolutionContrainsts message is shown nor the image is uploaded.
Untitled.mov
I’m pretty sure I tested it on ios/safari and it scaled down image to 2048/2047 automatically. Checking again. |
I was able to reproduce this on production. Can you try it as well please ? |
Yes, I was able to reproduce it on production as well. |
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.
Reviewer Checklist
- I have verified the author checklist is complete (all boxes are checked off).
- I verified the correct issue is linked in the
### Fixed Issues
section above - I verified testing steps are clear and they cover the changes made in this PR
- I verified the steps for local testing are in the
Tests
section - I verified the steps for Staging and/or Production testing are in the
QA steps
section - I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
- I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
- I verified the steps for local testing are in the
- I checked that screenshots or videos are included for tests on all platforms
- I included screenshots or videos for tests on all platforms
- I verified tests pass on all platforms & I tested again on:
- Android / native
- Android / Chrome
- iOS / native
- iOS / Safari
- MacOS / Chrome / Safari
- MacOS / Desktop
- If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
- I verified proper code patterns were followed (see Reviewing the code)
- I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e.
toggleReport
and notonIconClick
). - I verified that comments were added to code that is not self explanatory
- I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
- I verified any copy / text shown in the product is localized by adding it to
src/languages/*
files and using the translation method - I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
- I verified any copy / text that was added to the app is correct English and approved by marketing by adding the
Waiting for Copy
label for a copy review on the original GH to get the correct copy. - I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
- I verified the JSDocs style guidelines (in
STYLE.md
) were followed
- I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e.
- If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
- I verified that this PR follows the guidelines as stated in the Review Guidelines
- I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like
Avatar
, I verified the components usingAvatar
have been tested & I retested again) - I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
- I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
- If a new component is created I verified that:
- A similar component doesn't exist in the codebase
- All props are defined accurately and each prop has a
/** comment above it */
- The file is named correctly
- The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
- The only data being stored in the state is data necessary for rendering and nothing else
- For Class Components, any internal methods passed to components event handlers are bound to
this
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor) - Any internal methods bound to
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
) - All JSX used for rendering exists in the render method
- The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
- If any new file was added I verified that:
- The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
- If a new CSS style is added I verified that:
- A similar style doesn't already exist
- The style can't be created with an existing StyleUtils function (i.e.
StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG
)
- If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like
Avatar
is modified, I verified thatAvatar
is working as expected in all cases) - If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
- If a new page is added, I verified it's using the
ScrollView
component to make it scrollable when more elements are added to the page. - I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.
New issue where avatar crop screen won't open for large image was reported here: https://expensify.slack.com/archives/C049HHMV9SM/p1672734548804589 cc: @tgolen |
Co-authored-by: Rocio Perez-Cano <pecanoro@users.noreply.github.com>
b447cbf
✋ 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 production by @luacmartins in version: 1.2.48-2 🚀
|
🚀 Deployed to production by @luacmartins in version: 1.2.49-0 🚀
|
Details
Create a limit for Avatar resolution and validate based on allowed min-max px resolution range.
Fixed Issues
$ 13006
PROPOSAL: 13006(1367560892)
Tests (Web, Desktop, Android, mWeb Android)
Offline tests
QA Steps
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)src/languages/*
files and using the translation methodWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
this
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)ScrollView
component to make it scrollable when more elements are added to the page.Screenshots/Videos
Web
WEB.mov
Mobile Web - Chrome
Screen.Recording.2023-01-02.at.23.27.49.mov
Mobile Web - Safari
Simulator.Screen.Recording.-.iPhone.13.-.2023-01-02.at.23.01.05.mp4
Desktop
Screen.Recording.2023-01-02.at.23.15.00.mov
iOS
Simulator.Screen.Recording.-.iPhone.13.-.2023-01-02.at.22.59.00.mp4
Android
Screen.Recording.2023-01-02.at.22.11.44.mov
(copied from sobit)