Page MenuHomePhabricator

[native] Migrate double tap gesture handling in FullScreenViewModal
ClosedPublic

Authored by angelika on Feb 6 2025, 5:12 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Apr 15, 8:41 AM
Unknown Object (File)
Tue, Apr 15, 8:10 AM
Unknown Object (File)
Tue, Apr 15, 2:27 AM
Unknown Object (File)
Tue, Apr 15, 1:34 AM
Unknown Object (File)
Tue, Apr 15, 12:14 AM
Unknown Object (File)
Mon, Apr 14, 8:40 PM
Unknown Object (File)
Mon, Apr 14, 4:26 AM
Unknown Object (File)
Sun, Mar 30, 10:53 AM
Subscribers

Details

Summary

https://linear.app/comm/issue/ENG-8150/convert-fullscreenviewmodal-to-reanimated-2-syntax

Migrated doubleTapUpdate, getHorizontalPanSpace, getVerticalPanSpace methods.

On double tap:

  • if the current scale is > 1 then animate scale to 1 and recenter the image with timing animation
  • otherwise animate scale to 3 and recenter the image with timing animation

The math was basically copied from the original implementation, just rewritten from v1 (nodes) to v2 api (worklets).

There is one more thing: in the original implementation there is logic to stop the animation if a gesture is active. In the methods migrated in the next diffs (backdropOpacity, recenter, fling) there are also a couple of places that stop the animations when gesture is active. V2 has function cancelAnimation that cancels any animation on a shared value, so I'm going to use it later in a separate diff to cancel all animations from double tap, recenter etc.

Depends on D14304

Test Plan

Tested after migration: verify the image is zoomed in/out after a double tap.

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

angelika held this revision as a draft.
This revision is now accepted and ready to land.Feb 17 2025, 3:39 AM
native/components/full-screen-view-modal.react.js
1193–1195 ↗(On Diff #47083)

It seems the old system was designed to work with other animations happening at the same time:

  1. Instead of just assigning the animation result to curScale, curX, and curY, we seem to have calculated the deltas, and then applied them directly. This would allow us to combine the results of this animation with another currently running one. How complicated would adding support for something like this be?
  2. In the old code, it seems that we would stop the animation if a pinch or pan gesture became active. This could be achieved now by adding something to pinchStart and panStart, right? Is it too complicated to try and support?

As in prior work, I'd like to reemphasize that it's your responsibility as the diff author to identify changes you've made from previous behavior, and to highlight and explain them to the diff reviewer.

native/components/full-screen-view-modal.react.js
1193–1195 ↗(On Diff #47083)

Regarding 2, I suppose that pinchUpdate and panUpdate handle most of this, by setting curX, curY, and curScale.

The only difference is that in panUpdate, we don't set curScale. Should we call cancelAnimation(curScale) in panStart? (Might make sense to add other cancelAnimations for clarity, but will defer to you on that.)

native/components/full-screen-view-modal.react.js
1193–1195 ↗(On Diff #47083)

Upon further review, 2 is handled in D14309.

Only remaining question is part 1 here

native/components/full-screen-view-modal.react.js
1193–1195 ↗(On Diff #47083)

About part 1:
Adding support for this would be complicated as there is no simple way of running a couple animations at once but consider that this is an animation after a double click. What other animation can be run while/after user double clicks the image? To double click user needs to stop doing anything for a moment and any animation will finish in the meantime.

About part 2, I've mentioned it in the description of this diff:

There is one more thing: in the original implementation there is logic to stop the animation if a gesture is active. In the methods migrated in the next diffs (backdropOpacity, recenter, fling) there are also a couple of places that stop the animations when gesture is active. V2 has function cancelAnimation that cancels any animation on a shared value, so I'm going to use it later in a separate diff to cancel all animations from double tap, recenter etc.

Adding support for this would be complicated as there is no simple way of running a couple animations at once but consider that this is an animation after a double click. What other animation can be run while/after user double clicks the image? To double click user needs to stop doing anything for a moment and any animation will finish in the meantime.

This is a fair point. Thanks for explaining!

About part 2, I've mentioned it in the description of this diff:

Sorry – my apologies for missing this.