about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authordan <dan.abramov@gmail.com>2023-10-06 04:22:32 +0100
committerGitHub <noreply@github.com>2023-10-05 20:22:32 -0700
commitd2f11f8e3650be601528aad0ba2c7beed307999f (patch)
treeb1d66fad6353141b223ac5002291cd5a0c74fcae /src
parent3b78d3227f67442c0e57eb3aa60bbf3faade9320 (diff)
downloadvoidsky-d2f11f8e3650be601528aad0ba2c7beed307999f.tar.zst
Fix stuck lightbox header after double tap (#1627)
Diffstat (limited to 'src')
-rw-r--r--src/view/com/lightbox/ImageViewing/components/ImageItem/ImageItem.android.tsx23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/view/com/lightbox/ImageViewing/components/ImageItem/ImageItem.android.tsx b/src/view/com/lightbox/ImageViewing/components/ImageItem/ImageItem.android.tsx
index 6ff4dee2e..553a4a2e7 100644
--- a/src/view/com/lightbox/ImageViewing/components/ImageItem/ImageItem.android.tsx
+++ b/src/view/com/lightbox/ImageViewing/components/ImageItem/ImageItem.android.tsx
@@ -61,16 +61,21 @@ const ImageItem = ({
   const dismissSwipeTranslateY = useSharedValue(0)
   const containerRef = useAnimatedRef()
 
-  function getCommittedScale(): number {
-    'worklet'
-    const [, , committedScale] = readTransform(committedTransform.value)
-    return committedScale
-  }
-
   // Keep track of when we're entering or leaving scaled rendering.
+  // Note: DO NOT move any logic reading animated values outside this function.
   useAnimatedReaction(
     () => {
-      return pinchScale.value !== 1 || getCommittedScale() !== 1
+      if (pinchScale.value !== 1) {
+        // We're currently pinching.
+        return true
+      }
+      const [, , committedScale] = readTransform(committedTransform.value)
+      if (committedScale !== 1) {
+        // We started from a pinched in state.
+        return true
+      }
+      // We're at rest.
+      return false
     },
     (nextIsScaled, prevIsScaled) => {
       if (nextIsScaled !== prevIsScaled) {
@@ -169,7 +174,7 @@ const ImageItem = ({
       }
       // Don't let the picture zoom in so close that it gets blurry.
       // Also, like in stock Android apps, don't let the user zoom out further than 1:1.
-      const committedScale = getCommittedScale()
+      const [, , committedScale] = readTransform(committedTransform.value)
       const maxCommittedScale =
         (imageDimensions.width / SCREEN.width) * MAX_ORIGINAL_IMAGE_ZOOM
       const minPinchScale = 1 / committedScale
@@ -256,7 +261,7 @@ const ImageItem = ({
       if (!imageDimensions) {
         return
       }
-      const committedScale = getCommittedScale()
+      const [, , committedScale] = readTransform(committedTransform.value)
       if (committedScale !== 1) {
         // Go back to 1:1 using the identity vector.
         let t = createTransform()