App icon indicating copy to clipboard operation
App copied to clipboard

Chat - Magnifying glass displayed anywhere on the modal page for small images

Open kavimuru opened this issue 5 years ago β€’ 40 comments

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Action Performed:

  1. Launch the app and login
  2. Add a small size image as attachment and send the image to any chat
  3. Click on the image thumbnail, it should open modal with the image
  4. Verify you see a magnifying glass when hovering over the image

Expected Result:

Magnifying glass displayed only when hovering the image

Actual Result:

Magnifying glass displayed on all the places

Workaround:

Unknown

Platform:

Where is this issue occurring?

  • Web
  • Desktop App

Version Number: 1.1.15.1 Reproducible in staging?: Yes Reproducible in production?: Yes Logs: https://stackoverflow.com/c/expensify/questions/4856 Notes/Photos/Videos:

https://user-images.githubusercontent.com/43996225/142030540-b71a9486-6622-4844-b776-3850ec0e5e35.mp4

Expensify/Expensify Issue URL: Issue reported by: Applause Slack conversation:

View all open jobs on GitHub

kavimuru avatar Nov 16 '21 17:11 kavimuru

Triggered auto assignment to @timszot (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.

MelvinBot avatar Nov 16 '21 17:11 MelvinBot

Triggered auto assignment to @mallenexpensify (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.

MelvinBot avatar Nov 16 '21 20:11 MelvinBot

Triggered auto assignment to @deetergp (Exported), see https://stackoverflow.com/c/expensify/questions/7972 for more details.

MelvinBot avatar Nov 16 '21 22:11 MelvinBot

Job posted https://www.upwork.com/jobs/~014d495c62816efa38

mallenexpensify avatar Nov 16 '21 22:11 mallenexpensify

Proposal

We can calculate the pressable size by calculating the final size of the image. The final size of the image can be calculated using the size of the container (extracted with onLayout) and the original size of the image (this.state.imgHeight and this.state.imgWidth).

We will need to add the following functions to src/components/ImageView/index.js:


    storeImageContainerSize(event) {
        if (this.state.imageContainer) {
            // just do it first time to avoid potentially falling in a loop of update image size -> layout changes size -> update image size -> etc.
            return;
        }
        this.setState({
            imageContainer: {
                height: event.nativeEvent.layout.height,
                width: event.nativeEvent.layout.width,
                ratio: event.nativeEvent.layout.height / event.nativeEvent.layout.width,
            }
        });
    }

    shouldUseImageSize() {
        // We can use the calculated image size if we have all required sizes (original image size + container size) and we are not zoomed in
        if (!this.state.imageContainer || !this.state.imgHeight || !this.state.imgWidth || this.state.isZoomed) {
            return false;
        }
        return true;
    }

    getFinalImageWidth() {
        if (this.state.imageContainer.width >= this.state.imgWidth && this.state.imageContainer.height >= this.state.imgHeight) {
            // Image fits completely
            return this.state.imgWidth;
        }
        const imageAspect = this.state.imgWidth / this.state.imgHeight;
        const imageContainterAspect = this.state.imageContainer.width / this.state.imageContainer.height;
        if (imageAspect > imageContainterAspect) {
            // Image is wider than container
            return '100%';
        }

        // Image is taller than container
        return this.state.imageContainer.height * imageAspect;
    }

    getFinalImageHeight() {
        if (this.state.imageContainer.width >= this.state.imgWidth && this.state.imageContainer.height >= this.state.imgHeight) {
            // Image fits completely
            return this.state.imgHeight;
        }
        const imageAspect = this.state.imgWidth / this.state.imgHeight;
        const imageContainterAspect = this.state.imageContainer.width / this.state.imageContainer.height;
        if (imageAspect > imageContainterAspect) {
            // Image is wider than container
            return this.state.imageContainer.width / imageAspect;
        }

        // Image is taller than container
        return '100%';
    }

We will adjust the current Pressable height and width: https://github.com/Expensify/App/blob/main/src/components/ImageView/index.js#L171-L177

like this:

                <Pressable
                    style={[
                        this.shouldUseImageSize() ? {height: this.getFinalImageHeight()} : styles.h100,
                        this.shouldUseImageSize() ? {width: this.getFinalImageWidth()} : styles.w100,
                        getZoomCursorStyle(this.state.isZoomed, this.state.isDragging),
                    ]}

And the store the layout container size from Image: https://github.com/Expensify/App/blob/main/src/components/ImageView/index.js#L213-L217

like this:

                    <Image
                        onLayout={e => this.storeImageContainerSize(e)}
                        source={{uri: this.props.url}}
                        style={getZoomSizingStyle(this.state.isZoomed, this.state.imgWidth, this.state.imgHeight, this.state.zoomScale)}
                        resizeMode={this.state.isZoomed ? 'contain' : 'center'}
                    />

CamilaRivera avatar Nov 17 '21 02:11 CamilaRivera

1. Replication I also was able to reproduce this issue in my web, desktop environment. Here are my replication videos - web issue - desktop issue

2. Problems Problem is that cursor: zoom-in style was set to the parent component, but the parent size is bigger than the image itself when the modal is open.

3. Solution We need to set the style cursor: zoom-in to the image area.

  • Because the current image is clickable and wrapped by Pressable component, we need to set this style to the Pressable component.
  • While processing this issue, we need to keep the placement of the small image in the center of the modal. To resolve this issue, we might use the margin style, but it will not resolve the hover area correctly. It means the zoom icon will be displayed on the margin area. So we need to use position: absolute, left: XXpx, top: YYpx property.
  • While calculating the top value, we need to know the modal height. It can be get by onLayout event of the parent view.
  • By doing this, we will show the image at the center of the modal dialog with its original size and zoom-in cursor will be displayed only on the image area.

Screenshot at Nov 21 02-33-42 Screenshot at Nov 21 02-34-18

This is my solution to resolve this issue.

railway17 avatar Nov 20 '21 19:11 railway17

@deetergp , can you please review @CamilaRivera and @railway17 's proposals above?

mallenexpensify avatar Nov 22 '21 19:11 mallenexpensify

Thank you both for your proposals @CamilaRivera & @railway17's. After reviewing them both, I'm inclined to go with @railway17 proposal is it's appears to get the job done with fewer changes.

deetergp avatar Nov 22 '21 19:11 deetergp

πŸ“£ @railway17 You have been assigned to this job by @deetergp! Please apply to this job in Upwork and let us know when we can expect a PR to be ready for review πŸ§‘β€πŸ’» Keep in mind: Code of Conduct | Contributing πŸ“–

MelvinBot avatar Nov 22 '21 19:11 MelvinBot

Hired @railway17 / MingYun H. in Upwork for the job.

mallenexpensify avatar Nov 22 '21 20:11 mallenexpensify

@mallenexpensify , @deetergp Nice to meet you. I have a coincidence issue with my pc. Actually, I reinstalled my OS to Big Sur after submitting my proposal on Sunday (my old OS version was Catalina). As you saw in my proposal, I was able to replicate and test on the desktop app. - desktop issue. But I can't start the desktop app (web is working) on my side. So, I can't upload a working video screenshot in the pull request. (this function was tested in my old system when I submit the proposal). My current system info like below

macOS Big Sur
version 11.5.2(20G95)

I tried with node 12.x, 14.x and 17.x by using nvm. But not working in all of the cases. Error is like below: image

Even though it was tested before, I would like to keep the rule to write the pull request description with attachments. Do you know how to run the desktop app in this environment?

railway17 avatar Nov 23 '21 16:11 railway17

I created a pull request with 2 videos (web fix was taken from my pc but desktop-fix video was taken from another pc). I will check this issue while you review it or might be later. And will submit here why it would not work.

railway17 avatar Nov 23 '21 19:11 railway17

Hi @railway17 , this is likely a better question for @deetergp who will be the one reviewing the PR. Scott, can you take a look above plz

mallenexpensify avatar Nov 23 '21 22:11 mallenexpensify

Hi, @deetergp , @mallenexpensify I resolved this error by upgrading the dev package versions to latest one in package.json like below:

   ...
    "electron": "^16.0.1",
    "electron-builder": "^22.14.5",
    "electron-notarize": "^1.1.1",
    "electron-reloader": "^1.2.1",
   ....

railway17 avatar Nov 24 '21 14:11 railway17

Hey @railway17. Here are the versions I'm running on my Big Sur machine:

➜  App git:(han-fix-magnifying-glass) βœ— node --version
v14.17.4
➜  App git:(han-fix-magnifying-glass) βœ— npm --version
6.14.14
➜  App git:(han-fix-magnifying-glass) βœ— nvm --version
0.38.0
➜  App git:(han-fix-magnifying-glass) βœ—

Generally, when I run into these kinds of runtime issues, I find that just deleting the node_modules folder and re-running npm i takes care of them. FWIW, I was able to run your branch on the desktop app without any problems.

deetergp avatar Nov 24 '21 17:11 deetergp

Issue not reproducible during KI retests. (First week)

mvtglobally avatar Dec 06 '21 21:12 mvtglobally

The solution for this issue has been :rocket: deployed to production :rocket: in version 1.1.17-7 and is now subject to a 7-day regression period :calendar:. Here is the list of pull requests that resolve this issue:

  • https://github.com/Expensify/App/pull/6437
  • https://github.com/Expensify/App/pull/6535

If no regressions arise, payment will be issued on 2021-12-13. :confetti_ball:

botify avatar Dec 06 '21 23:12 botify

The solution for this issue has been :rocket: deployed to production :rocket: in version 1.1.18-3 and is now subject to a 7-day regression period :calendar:. Here is the list of pull requests that resolve this issue:

  • https://github.com/Expensify/App/pull/6535

If no regressions arise, payment will be issued on 2021-12-15. :confetti_ball:

botify avatar Dec 08 '21 19:12 botify

We are tracking are a regression from this issue's PR. https://github.com/Expensify/App/issues/6518. It must be fixed before this issue can be paid out.

Also, this is @railway17 's first issue/PR in our repo so I think further assignment should be restrained until the regression is fixed,

parasharrajat avatar Dec 09 '21 11:12 parasharrajat

Just to reiterate and confirm what @parasharrajat said above, this issue should not be considered complete until https://github.com/Expensify/App/issues/6518 is resolved as well.

roryabraham avatar Dec 10 '21 21:12 roryabraham