Skip to content
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

Merged
merged 12 commits into from
Jan 3, 2023

Conversation

azimgd
Copy link
Contributor

@azimgd azimgd commented Dec 30, 2022

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)

  1. Save this failing image, and any other that is less than 2048px
  2. Open staging.new.expensify.com.
  3. Open Settings, click on Avatar to open Profile Page.
  4. Click on Edit photo and upload the below image
  5. Try to scroll the slider to zoom in or zoom out the photo.
  6. Slider is scrolled smoothly without any delay
  7. Display an error message if a user is uploading a file/size too large (min: 80px, max: 2048px), images that are in allowed range should proceed to crop avatar screen
  8. Ensure there are no animation (scroll) glitches between pick image and crop avatar screens
  • Verify that no errors appear in the JS console

Offline tests

  1. Same as Tests

QA Steps

  1. Same as Tests
  2. Try various images with px density
  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover 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 tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (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 not onIconClick)
    • 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
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • 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
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • 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. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • 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 that Avatar 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 author checklist, including those that don't apply to this PR.

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)

@azimgd azimgd requested a review from a team as a code owner December 30, 2022 00:47
@melvin-bot melvin-bot bot requested review from MonilBhavsar and removed request for a team December 30, 2022 00:47
@melvin-bot
Copy link

melvin-bot bot commented Dec 30, 2022

@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,
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor

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"?

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

src/languages/en.js Outdated Show resolved Hide resolved
@azimgd
Copy link
Contributor Author

azimgd commented Jan 2, 2023

Hey @MonilBhavsar could you help us reviewing this PR.

@MonilBhavsar MonilBhavsar requested a review from tgolen January 2, 2023 10:51
@MonilBhavsar
Copy link
Contributor

Yes, and also requesting review from @tgolen

@azimgd
Copy link
Contributor Author

azimgd commented Jan 2, 2023

Would be cool if we can get this easy PR merged today.

@sobitneupane
Copy link
Contributor

sobitneupane commented Jan 2, 2023

Hello @MonilBhavsar, do we want to increase AVATAR_MAX_WIDTH_PX/AVATAR_MAX_HEIGHT_PX or keep it 2048? #13899 (comment)

@MonilBhavsar
Copy link
Contributor

Commented in that thread

@sobitneupane
Copy link
Contributor

sobitneupane commented Jan 2, 2023

Screenshots/Videos

Web
Screen.Recording.2023-01-02.at.16.56.11.mov
Mobile Web - Chrome
Screen.Recording.2023-01-02.at.22.08.39.mov
Mobile Web - Safari
Untitled.mov
Desktop
Screen.Recording.2023-01-02.at.22.20.26.mov
iOS
Untitled.mov
Android
Screen.Recording.2023-01-02.at.22.11.44.mov

Copy link
Contributor

@MonilBhavsar MonilBhavsar left a 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

@azimgd
Copy link
Contributor Author

azimgd commented Jan 2, 2023

Here is the comment from @tgolen

I think we should concentrate on fixing the bug first, in the most simple way we can. If at some point in the future we want to add precompression, then we can do that as a feature request. As of right now, no one is requesting precompression specifically.

#13006 (comment)

@azimgd
Copy link
Contributor Author

azimgd commented Jan 2, 2023

@MonilBhavsar So we all agreed on this solution with validating image resolution, would be cool if we can get this reviewed today.

@tgolen
Copy link
Contributor

tgolen commented Jan 2, 2023

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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)

Copy link
Contributor Author

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
Copy link
Contributor

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

@tgolen
Copy link
Contributor

tgolen commented Jan 2, 2023

It also looks like there are commits on this branch that are not signed, so it cannot be merged until that's fixed.

@azimgd azimgd force-pushed the avatar-image-constraints branch from 061b00c to b0a46ea Compare January 2, 2023 16:12
@azimgd
Copy link
Contributor Author

azimgd commented Jan 2, 2023

@tgolen Increased allowed width / height to 4096px, tested everything locally and addressed all comments. Ready for re-review.

tgolen
tgolen previously approved these changes Jan 2, 2023
Copy link
Contributor

@tgolen tgolen left a 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

@tgolen
Copy link
Contributor

tgolen commented Jan 2, 2023

@sobitneupane I see you tested with some screenshots, were you also going to post the full checklist?

AndrewGable
AndrewGable previously approved these changes Jan 2, 2023
Copy link
Contributor

@sobitneupane sobitneupane left a 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

@azimgd
Copy link
Contributor Author

azimgd commented Jan 3, 2023

I’m pretty sure I tested it on ios/safari and it scaled down image to 2048/2047 automatically.

#13899 (comment)

Checking again.

@azimgd
Copy link
Contributor Author

azimgd commented Jan 3, 2023

I was able to reproduce this on production. Can you try it as well please ?

@sobitneupane
Copy link
Contributor

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.

Copy link
Contributor

@sobitneupane sobitneupane left a 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 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 not onIconClick).
    • 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
  • 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 using Avatar 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. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • 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 that Avatar 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.

sobitneupane
sobitneupane previously approved these changes Jan 3, 2023
@azimgd
Copy link
Contributor Author

azimgd commented Jan 3, 2023

New issue where avatar crop screen won't open for large image was reported here: https://expensify.slack.com/archives/C049HHMV9SM/p1672734548804589 cc: @tgolen

MonilBhavsar
MonilBhavsar previously approved these changes Jan 3, 2023
src/languages/es.js Outdated Show resolved Hide resolved
Co-authored-by: Rocio Perez-Cano <pecanoro@users.noreply.github.com>
@tgolen tgolen merged commit 2039b64 into Expensify:main Jan 3, 2023
@OSBotify
Copy link
Contributor

OSBotify commented Jan 3, 2023

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

OSBotify commented Jan 4, 2023

🚀 Deployed to staging by @tgolen in version: 1.2.48-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

OSBotify commented Jan 5, 2023

🚀 Deployed to production by @luacmartins in version: 1.2.48-2 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

OSBotify commented Jan 6, 2023

🚀 Deployed to production by @luacmartins in version: 1.2.49-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants