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 ability to zoom images on web/desktop #2085

Merged
merged 5 commits into from
Mar 29, 2021
Merged

Conversation

marcaaron
Copy link
Contributor

@marcaaron marcaaron commented Mar 25, 2021

Details

Adds ability to zoom to 200% by clicking on image attachment on web/mWeb

Fixed Issues

Fixes https://github.com/Expensify/Expensify/issues/146569

Tests

web/desktop

  1. Click on an attachment
  2. Verify there is a zoom cursor
  3. Click and verify the image zooms
  4. Hold and drag and verify the image pans
  5. Click again and verify the image zooms back out

mWeb

  1. Click on an attachment in mobile web browser
  2. Verify that pinch to zoom works normally

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

Screenshots

Web

2021-03-26_10-08-18.mp4

Mobile Web

Desktop

2021-03-26_10-08-18.mp4

iOS

Android

@marcaaron marcaaron self-assigned this Mar 25, 2021
@marcaaron marcaaron marked this pull request as ready for review March 26, 2021 20:36
@marcaaron marcaaron requested a review from a team as a code owner March 26, 2021 20:36
@marcaaron marcaaron changed the title Add ability to zoom images on web/desktop/mweb Add ability to zoom images on web/desktop Mar 26, 2021
@botify botify requested review from ctkochan22 and removed request for a team March 26, 2021 20:37
@marcaaron marcaaron requested a review from roryabraham March 26, 2021 20:52
@marcaaron
Copy link
Contributor Author

Tagging in @roryabraham too since he's got some experience with UI widget guys in E.cash 😄

@roryabraham
Copy link
Contributor

roryabraham commented Mar 26, 2021

@marcaaron I was testing this on mobile web on my iPhone and noticed it had some unintended consequences. It's a bit hard to describe, so I suggest you try it by creating an ngrok tunnel to your localhost:8080 and visiting that tunnel on your phone.

On iPhone on mobile web and iOS right now, you can zoom into the images normally, without the changes in this PR. But with this PR, if you do that normal "pinch zoom", it recognizes it as a mouse-click, zooms the image (I think where you first touched the screen), and has a weird jumping effect.

I think basically we want to make sure we're not doing anything on tap, while on mouse-click we want to zoom in.

ImageView.displayName = 'ImageView';
componentDidMount() {
document.addEventListener('mousemove', this.trackMouseMove.bind(this));
document.addEventListener('touchmove', this.trackMouseMove.bind(this));
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 you need to set up a listener for touchmove?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So that mobile web touches would set isDragging

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But maybe there is a solution where we don't need to do this and we can tell what kind of mouse event we've got.

@marcaaron
Copy link
Contributor Author

Thanks for testing that. I guess my thinking here was that we sort of unofficially support pinching and zooming now, but that's probably more useful on mWeb than what these changes are providing to desktop/web users. So, maybe we should just disable this for mobile web and let people pinch/zoom normally for now? Not sure if there is an easy way to identify web vs. mobile web besides "screen width".

@shawnborton
Copy link
Contributor

Nice!

@marcaaron
Copy link
Contributor Author

@roryabraham came up with a temporary solution for the mobile web issue by adding a utility that detects if we have a touch screen. If we do, we'll assume that we can use that to zoom in on images and not utilize the feature, if not, then we'll allow the mouse zoom and drag feature instead. Let me know what you think.

@marcaaron
Copy link
Contributor Author

I will also caveat this by saying I think the long term solution here will be to use a single component for native/mWeb eventually. But didn't want to dive down that rabbit hole at the expense of quickly improving the desktop/web experience.

Copy link
Contributor

@roryabraham roryabraham left a comment

Choose a reason for hiding this comment

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

the long term solution here will be to use a single component for native/mWeb eventually

Interesting. Agreed we don't need to go down this rabbit hole today, but were you thinking another platform file extension for mWeb?

super(props);
this.scrollableRef = null;
this.canUseTouchScreen = canUseTouchScreen();
this.containerStyles = [
Copy link
Contributor

Choose a reason for hiding this comment

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

Only NAB is it seems like this should be put in a style file instead of declared in the constructor.

@marcaaron
Copy link
Contributor Author

but were you thinking another platform file extension for mWeb?

Ah no, I'm suggesting that native and mobile web use the same exact component to handle touches + pinch zoom with something like this which has web support, but still has a few kinks to work out.

@roryabraham
Copy link
Contributor

Oh, nice. Yeah that makes more sense to me. Anyways, this LGTM and tested well 👍

@roryabraham roryabraham merged commit 7d35d9d into master Mar 29, 2021
@roryabraham roryabraham deleted the marcaaron-addZoomForWeb branch March 29, 2021 17:50
@marcaaron marcaaron mentioned this pull request Mar 29, 2021
5 tasks
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.

3 participants