t3-code-android-nightly/patches/react-native-image-viewing@0.2.2.patch
shivam dc0a9bd313
fix(mobile): a single tap on an Android image toggles its top bar (#45191)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
2026-11-28 16:43:41 -08:00

446 lines
23 KiB
Diff

diff --git a/dist/ImageViewing.js b/dist/ImageViewing.js
index 3d7641a9a94864415d207c678b71f8c592c90aa1..160afbcbb74776e2a706817b5448a36e078ea0bc 100644
--- a/dist/ImageViewing.js
+++ b/dist/ImageViewing.js
@@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*
*/
-import React, { useCallback, useRef, useEffect } from "react";
-import { Animated, Dimensions, StyleSheet, View, VirtualizedList, Modal, } from "react-native";
+import React, { useCallback, useRef, useEffect, useLayoutEffect } from "react";
+import { Animated, Dimensions, StyleSheet, View, VirtualizedList, Modal, Platform, useWindowDimensions, } from "react-native";
import ImageItem from "./components/ImageItem/ImageItem";
import ImageDefaultHeader from "./components/ImageDefaultHeader";
import StatusBarManager from "./components/StatusBarManager";
@@ -17,23 +17,34 @@ const DEFAULT_ANIMATION_TYPE = "fade";
const DEFAULT_BG_COLOR = "#000";
const DEFAULT_DELAY_LONG_PRESS = 800;
const SCREEN = Dimensions.get("screen");
-const SCREEN_WIDTH = SCREEN.width;
+const useViewingDimensions = Platform.OS === "android" ? useWindowDimensions : () => SCREEN;
function ImageViewing({ images, keyExtractor, imageIndex, visible, onRequestClose, onLongPress = () => { }, onImageIndexChange, animationType = DEFAULT_ANIMATION_TYPE, backgroundColor = DEFAULT_BG_COLOR, presentationStyle, swipeToCloseEnabled, doubleTapToZoomEnabled, delayLongPress = DEFAULT_DELAY_LONG_PRESS, HeaderComponent, FooterComponent, }) {
+ const viewport = useViewingDimensions();
+ const SCREEN_WIDTH = viewport.width;
+ const viewportKey = Platform.OS === "android" ? `${viewport.width}:${viewport.height}` : undefined;
const imageList = useRef(null);
const [opacity, onRequestCloseEnhanced] = useRequestClose(onRequestClose);
- const [currentImageIndex, onScroll] = useImageIndexChange(imageIndex, SCREEN);
- const [headerTransform, footerTransform, toggleBarsVisible] = useAnimatedComponents();
+ const [currentImageIndex, onScroll] = useImageIndexChange(imageIndex, viewport);
+ const [headerTransform, footerTransform, toggleBarsVisible, toggleBars] = useAnimatedComponents(viewportKey);
useEffect(() => {
if (onImageIndexChange) {
onImageIndexChange(currentImageIndex);
}
}, [currentImageIndex]);
- const onZoom = useCallback((isScaled) => {
+ const activeZoom = useRef(null);
+ const onZoom = useCallback(function handleZoom(isScaled) {
+ if (Platform.OS === "android" && activeZoom.current !== handleZoom) {
+ return;
+ }
var _a, _b;
// @ts-ignore
(_b = (_a = imageList) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.setNativeProps({ scrollEnabled: !isScaled });
toggleBarsVisible(!isScaled);
- }, [imageList]);
+ }, [imageList, toggleBarsVisible]);
+ useLayoutEffect(() => {
+ activeZoom.current = onZoom;
+ return () => { activeZoom.current = null; };
+ }, [onZoom]);
if (!visible) {
return null;
}
@@ -45,11 +56,12 @@ function ImageViewing({ images, keyExtractor, imageIndex, visible, onRequestClos
imageIndex: currentImageIndex,
})) : (<ImageDefaultHeader onRequestClose={onRequestCloseEnhanced}/>)}
</Animated.View>
- <VirtualizedList ref={imageList} data={images} horizontal pagingEnabled windowSize={2} initialNumToRender={1} maxToRenderPerBatch={1} showsHorizontalScrollIndicator={false} showsVerticalScrollIndicator={false} initialScrollIndex={imageIndex} getItem={(_, index) => images[index]} getItemCount={() => images.length} getItemLayout={(_, index) => ({
+ {/* Reset Android image gestures on resize while preserving custom header state. */}
+ <VirtualizedList key={viewportKey} ref={imageList} onScroll={Platform.OS === "android" ? onScroll : undefined} scrollEventThrottle={Platform.OS === "android" ? 16 : undefined} data={images} horizontal pagingEnabled windowSize={2} initialNumToRender={1} maxToRenderPerBatch={1} showsHorizontalScrollIndicator={false} showsVerticalScrollIndicator={false} initialScrollIndex={currentImageIndex} getItem={(_, index) => images[index]} getItemCount={() => images.length} getItemLayout={(_, index) => ({
length: SCREEN_WIDTH,
offset: SCREEN_WIDTH * index,
index,
- })} renderItem={({ item: imageSrc }) => (<ImageItem onZoom={onZoom} imageSrc={imageSrc} onRequestClose={onRequestCloseEnhanced} onLongPress={onLongPress} delayLongPress={delayLongPress} swipeToCloseEnabled={swipeToCloseEnabled} doubleTapToZoomEnabled={doubleTapToZoomEnabled}/>)} onMomentumScrollEnd={onScroll}
+ })} renderItem={({ item: imageSrc }) => (<ImageItem onZoom={onZoom} imageSrc={imageSrc} onRequestClose={onRequestCloseEnhanced} onLongPress={onLongPress} delayLongPress={delayLongPress} swipeToCloseEnabled={swipeToCloseEnabled} doubleTapToZoomEnabled={doubleTapToZoomEnabled} onTap={toggleBars}/>)} onMomentumScrollEnd={onScroll}
//@ts-ignore
keyExtractor={(imageSrc, index) => keyExtractor
? keyExtractor(imageSrc, index)
diff --git a/dist/components/ImageItem/ImageItem.android.d.ts b/dist/components/ImageItem/ImageItem.android.d.ts
index 0b1aa96dce0f1f9336934be1f44c4e30687454e5..cba7d2d28e1435f37d4287e20c4d02f30ea4940a 100644
--- a/dist/components/ImageItem/ImageItem.android.d.ts
+++ b/dist/components/ImageItem/ImageItem.android.d.ts
@@ -15,6 +15,7 @@ declare type Props = {
delayLongPress: number;
swipeToCloseEnabled?: boolean;
doubleTapToZoomEnabled?: boolean;
+ onTap?: () => void;
};
-declare const _default: React.MemoExoticComponent<({ imageSrc, onZoom, onRequestClose, onLongPress, delayLongPress, swipeToCloseEnabled, doubleTapToZoomEnabled, }: Props) => JSX.Element>;
+declare const _default: React.MemoExoticComponent<({ imageSrc, onZoom, onRequestClose, onLongPress, delayLongPress, swipeToCloseEnabled, doubleTapToZoomEnabled, onTap, }: Props) => JSX.Element>;
export default _default;
diff --git a/dist/components/ImageItem/ImageItem.android.js b/dist/components/ImageItem/ImageItem.android.js
index 5fcaa9f9a7d893817fee89b85186ee3936118e69..be4c58da4267096327d8ee9c6e9191e266396351 100644
--- a/dist/components/ImageItem/ImageItem.android.js
+++ b/dist/components/ImageItem/ImageItem.android.js
@@ -6,17 +6,17 @@
*
*/
import React, { useCallback, useRef, useState } from "react";
-import { Animated, ScrollView, Dimensions, StyleSheet, } from "react-native";
+import { Animated, ScrollView, Dimensions, View, } from "react-native";
import useImageDimensions from "../../hooks/useImageDimensions";
import usePanResponder from "../../hooks/usePanResponder";
import { getImageStyles, getImageTransform } from "../../utils";
import { ImageLoading } from "./ImageLoading";
const SWIPE_CLOSE_OFFSET = 75;
const SWIPE_CLOSE_VELOCITY = 1.75;
-const SCREEN = Dimensions.get("window");
-const SCREEN_WIDTH = SCREEN.width;
-const SCREEN_HEIGHT = SCREEN.height;
-const ImageItem = ({ imageSrc, onZoom, onRequestClose, onLongPress, delayLongPress, swipeToCloseEnabled = true, doubleTapToZoomEnabled = true, }) => {
+const ImageItem = ({ imageSrc, onZoom, onRequestClose, onLongPress, delayLongPress, swipeToCloseEnabled = true, doubleTapToZoomEnabled = true, onTap, }) => {
+ const SCREEN = Dimensions.get("window");
+ const SCREEN_WIDTH = SCREEN.width;
+ const SCREEN_HEIGHT = SCREEN.height;
const imageContainer = useRef(null);
const imageDimensions = useImageDimensions(imageSrc);
const [translate, scale] = getImageTransform(imageDimensions, SCREEN);
@@ -28,10 +28,10 @@ const ImageItem = ({ imageSrc, onZoom, onRequestClose, onLongPress, delayLongPre
onZoom(isZoomed);
if ((_a = imageContainer) === null || _a === void 0 ? void 0 : _a.current) {
imageContainer.current.setNativeProps({
- scrollEnabled: !isZoomed,
+ scrollEnabled: swipeToCloseEnabled && !isZoomed,
});
}
- }, [imageContainer]);
+ }, [imageContainer, onZoom, swipeToCloseEnabled]);
const onLongPressHandler = useCallback(() => {
onLongPress(imageSrc);
}, [imageSrc, onLongPress]);
@@ -42,6 +42,7 @@ const ImageItem = ({ imageSrc, onZoom, onRequestClose, onLongPress, delayLongPre
doubleTapToZoomEnabled,
onLongPress: onLongPressHandler,
delayLongPress,
+ onTap,
});
const imagesStyles = getImageStyles(imageDimensions, translateValue, scaleValue);
const imageOpacity = scrollValueY.interpolate({
@@ -64,21 +65,15 @@ const ImageItem = ({ imageSrc, onZoom, onRequestClose, onLongPress, delayLongPre
const offsetY = (_c = (_b = (_a = nativeEvent) === null || _a === void 0 ? void 0 : _a.contentOffset) === null || _b === void 0 ? void 0 : _b.y, (_c !== null && _c !== void 0 ? _c : 0));
scrollValueY.setValue(offsetY);
};
- return (<ScrollView ref={imageContainer} style={styles.listItem} pagingEnabled nestedScrollEnabled showsHorizontalScrollIndicator={false} showsVerticalScrollIndicator={false} contentContainerStyle={styles.imageScrollContainer} scrollEnabled={swipeToCloseEnabled} {...(swipeToCloseEnabled && {
+ return (<ScrollView ref={imageContainer} style={{ width: SCREEN_WIDTH, height: SCREEN_HEIGHT }} pagingEnabled nestedScrollEnabled showsHorizontalScrollIndicator={false} showsVerticalScrollIndicator={false} contentContainerStyle={{ height: SCREEN_HEIGHT * 2 }} scrollEnabled={swipeToCloseEnabled} {...(swipeToCloseEnabled && {
onScroll,
onScrollEndDrag,
})}>
- <Animated.Image {...panHandlers} source={imageSrc} style={imageStylesWithOpacity} onLoad={onLoaded}/>
- {(!isLoaded || !imageDimensions) && <ImageLoading />}
+ {/* Pinch from anywhere on screen, not only on the fitted image. */}
+ <View {...panHandlers} pointerEvents={isLoaded && imageDimensions ? "auto" : "none"} style={{ width: SCREEN_WIDTH, height: SCREEN_HEIGHT }}>
+ <Animated.Image source={imageSrc} style={imageStylesWithOpacity} onLoad={onLoaded}/>
+ {(!isLoaded || !imageDimensions) && <ImageLoading />}
+ </View>
</ScrollView>);
};
-const styles = StyleSheet.create({
- listItem: {
- width: SCREEN_WIDTH,
- height: SCREEN_HEIGHT,
- },
- imageScrollContainer: {
- height: SCREEN_HEIGHT * 2,
- },
-});
export default React.memo(ImageItem);
diff --git a/dist/components/ImageItem/ImageLoading.js b/dist/components/ImageItem/ImageLoading.js
index 9770f7db158a2fb2b1c69a49e5fcbc89d8624603..995fab7524bb8673258d44e5eda361c62dae0324 100644
--- a/dist/components/ImageItem/ImageLoading.js
+++ b/dist/components/ImageItem/ImageLoading.js
@@ -6,25 +6,17 @@
*
*/
import React from "react";
-import { ActivityIndicator, Dimensions, StyleSheet, View } from "react-native";
+import { ActivityIndicator, Dimensions, Platform, StyleSheet, View } from "react-native";
const SCREEN = Dimensions.get("screen");
-const SCREEN_WIDTH = SCREEN.width;
-const SCREEN_HEIGHT = SCREEN.height;
-export const ImageLoading = () => (<View style={styles.loading}>
+export const ImageLoading = () => {
+ const { width, height } = Platform.OS === "android" ? Dimensions.get("window") : SCREEN;
+ return (<View style={[styles.loading, { width, height }]}>
<ActivityIndicator size="small" color="#FFF"/>
</View>);
+};
const styles = StyleSheet.create({
- listItem: {
- width: SCREEN_WIDTH,
- height: SCREEN_HEIGHT,
- },
loading: {
- width: SCREEN_WIDTH,
- height: SCREEN_HEIGHT,
alignItems: "center",
justifyContent: "center",
},
- imageScrollContainer: {
- height: SCREEN_HEIGHT,
- },
});
diff --git a/dist/hooks/useAnimatedComponents.d.ts b/dist/hooks/useAnimatedComponents.d.ts
index de5957458fea62f33743103acaa170a2c90d3638..16519797ee3da81cde2712d14aff117668d9675d 100644
--- a/dist/hooks/useAnimatedComponents.d.ts
+++ b/dist/hooks/useAnimatedComponents.d.ts
@@ -6,9 +6,9 @@
*
*/
import { Animated } from "react-native";
-declare const useAnimatedComponents: () => readonly [{
+declare const useAnimatedComponents: (resetKey?: string) => readonly [{
[key: string]: Animated.Value;
}[], {
[key: string]: Animated.Value;
-}[], (isVisible: boolean) => void];
+}[], (isVisible: boolean) => void, () => void];
export default useAnimatedComponents;
diff --git a/dist/hooks/useAnimatedComponents.js b/dist/hooks/useAnimatedComponents.js
index 4730fe40735bd80afc97abdd14150a2fb4abf3e5..dacd69487ec88b152bede0fbcd1b6394a3a4ba56 100644
--- a/dist/hooks/useAnimatedComponents.js
+++ b/dist/hooks/useAnimatedComponents.js
@@ -5,16 +5,24 @@
* LICENSE file in the root directory of this source tree.
*
*/
+import { useCallback, useMemo, useRef } from "react";
import { Animated } from "react-native";
const INITIAL_POSITION = { x: 0, y: 0 };
const ANIMATION_CONFIG = {
duration: 200,
useNativeDriver: true,
};
-const useAnimatedComponents = () => {
- const headerTranslate = new Animated.ValueXY(INITIAL_POSITION);
- const footerTranslate = new Animated.ValueXY(INITIAL_POSITION);
- const toggleVisible = (isVisible) => {
+const useAnimatedComponents = (resetKey) => {
+ const barsVisible = useRef(true);
+ const [headerTranslate, footerTranslate] = useMemo(() => {
+ barsVisible.current = true;
+ return [
+ new Animated.ValueXY(INITIAL_POSITION),
+ new Animated.ValueXY(INITIAL_POSITION),
+ ];
+ }, [resetKey]);
+ const toggleVisible = useCallback((isVisible) => {
+ barsVisible.current = isVisible;
if (isVisible) {
Animated.parallel([
Animated.timing(headerTranslate.y, { ...ANIMATION_CONFIG, toValue: 0 }),
@@ -33,9 +41,10 @@ const useAnimatedComponents = () => {
}),
]).start();
}
- };
+ }, [headerTranslate, footerTranslate]);
const headerTransform = headerTranslate.getTranslateTransform();
const footerTransform = footerTranslate.getTranslateTransform();
- return [headerTransform, footerTransform, toggleVisible];
+ const toggleBars = useCallback(() => toggleVisible(!barsVisible.current), [toggleVisible]);
+ return [headerTransform, footerTransform, toggleVisible, toggleBars];
};
export default useAnimatedComponents;
diff --git a/dist/hooks/useImageIndexChange.js b/dist/hooks/useImageIndexChange.js
index cb5f0f798e5cfeedf459b7d22e92871db3092020..97ca2c9c326b1c53e6a5d90c3bb95d53342088d1 100644
--- a/dist/hooks/useImageIndexChange.js
+++ b/dist/hooks/useImageIndexChange.js
@@ -5,16 +5,34 @@
* LICENSE file in the root directory of this source tree.
*
*/
-import { useState } from "react";
+import { useCallback, useLayoutEffect, useRef, useState } from "react";
+import { Platform } from "react-native";
const useImageIndexChange = (imageIndex, screen) => {
const [currentImageIndex, setImageIndex] = useState(imageIndex);
- const onScroll = (event) => {
+ const indexRef = useRef(imageIndex);
+ const activeScroll = useRef(null);
+ const onScroll = useCallback(function handleScroll(event) {
+ if (Platform.OS === "android") {
+ // Events at this width stay valid until commit; replaced or relaid-out lists do not.
+ if (activeScroll.current !== handleScroll ||
+ Math.abs(event.nativeEvent.layoutMeasurement.width - screen.width) > 1) {
+ return;
+ }
+ }
const { nativeEvent: { contentOffset: { x: scrollX }, }, } = event;
if (screen.width) {
const nextIndex = Math.round(scrollX / screen.width);
- setImageIndex(nextIndex < 0 ? 0 : nextIndex);
+ const boundedIndex = nextIndex < 0 ? 0 : nextIndex;
+ if (boundedIndex !== indexRef.current) {
+ indexRef.current = boundedIndex;
+ setImageIndex(boundedIndex);
+ }
}
- };
+ }, [screen]);
+ useLayoutEffect(() => {
+ activeScroll.current = onScroll;
+ return () => { activeScroll.current = null; };
+ }, [onScroll]);
return [currentImageIndex, onScroll];
};
export default useImageIndexChange;
diff --git a/dist/hooks/usePanResponder.d.ts b/dist/hooks/usePanResponder.d.ts
index a4e41f0aaab61e029088f4efbdf940b1d23357c1..20f4929b66dce1d7647eb0690b2c097b9ed1c490 100644
--- a/dist/hooks/usePanResponder.d.ts
+++ b/dist/hooks/usePanResponder.d.ts
@@ -14,6 +14,7 @@ declare type Props = {
doubleTapToZoomEnabled: boolean;
onLongPress: () => void;
delayLongPress: number;
+ onTap?: () => void;
};
-declare const usePanResponder: ({ initialScale, initialTranslate, onZoom, doubleTapToZoomEnabled, onLongPress, delayLongPress, }: Props) => readonly [GestureResponderHandlers, Animated.Value, Animated.ValueXY];
+declare const usePanResponder: ({ initialScale, initialTranslate, onZoom, doubleTapToZoomEnabled, onLongPress, delayLongPress, onTap, }: Props) => readonly [GestureResponderHandlers, Animated.Value, Animated.ValueXY];
export default usePanResponder;
diff --git a/dist/hooks/usePanResponder.js b/dist/hooks/usePanResponder.js
index 99dcbc7efea4eba86a8bc2bad71dde73c8ebf1b4..15bcfe657eb7f05ba0c8b298dbeba1f6e5b2680a 100644
--- a/dist/hooks/usePanResponder.js
+++ b/dist/hooks/usePanResponder.js
@@ -5,17 +5,17 @@
* LICENSE file in the root directory of this source tree.
*
*/
-import { useMemo, useEffect } from "react";
+import { useMemo, useEffect, useRef } from "react";
import { Animated, Dimensions, } from "react-native";
import { createPanResponder, getDistanceBetweenTouches, getImageTranslate, getImageDimensionsByTranslate, } from "../utils";
-const SCREEN = Dimensions.get("window");
-const SCREEN_WIDTH = SCREEN.width;
-const SCREEN_HEIGHT = SCREEN.height;
-const MIN_DIMENSION = Math.min(SCREEN_WIDTH, SCREEN_HEIGHT);
const SCALE_MAX = 2;
const DOUBLE_TAP_DELAY = 300;
const OUT_BOUND_MULTIPLIER = 0.75;
-const usePanResponder = ({ initialScale, initialTranslate, onZoom, doubleTapToZoomEnabled, onLongPress, delayLongPress, }) => {
+const usePanResponder = ({ initialScale, initialTranslate, onZoom, doubleTapToZoomEnabled, onLongPress, delayLongPress, onTap, }) => {
+ const SCREEN = Dimensions.get("window");
+ const SCREEN_WIDTH = SCREEN.width;
+ const SCREEN_HEIGHT = SCREEN.height;
+ const MIN_DIMENSION = Math.min(SCREEN_WIDTH, SCREEN_HEIGHT);
let numberInitialTouches = 1;
let initialTouches = [];
let currentScale = initialScale;
@@ -25,6 +25,9 @@ const usePanResponder = ({ initialScale, initialTranslate, onZoom, doubleTapToZo
let isDoubleTapPerformed = false;
let lastTapTS = null;
let longPressHandlerRef = null;
+ let tapCandidate = false;
+ const tapTimer = useRef(null);
+ const pendingTaps = useRef(new Set());
const meaningfulShift = MIN_DIMENSION * 0.01;
const scaleValue = new Animated.Value(initialScale);
const translateValue = new Animated.ValueXY(initialTranslate);
@@ -68,21 +71,37 @@ const usePanResponder = ({ initialScale, initialTranslate, onZoom, doubleTapToZo
});
return () => scaleValue.removeAllListeners();
});
+ useEffect(() => () => pendingTaps.current.forEach(clearTimeout), []);
const cancelLongPressHandle = () => {
longPressHandlerRef && clearTimeout(longPressHandlerRef);
};
+ const cancelTap = (timer) => {
+ clearTimeout(timer);
+ pendingTaps.current.delete(timer);
+ };
+ // A pinch is never a tap: every toggle still waiting on its double-tap window is dropped.
+ const cancelPendingTaps = () => {
+ pendingTaps.current.forEach(clearTimeout);
+ pendingTaps.current.clear();
+ };
const handlers = {
onGrant: (_, gestureState) => {
numberInitialTouches = gestureState.numberActiveTouches;
if (gestureState.numberActiveTouches > 1)
return;
- longPressHandlerRef = setTimeout(onLongPress, delayLongPress);
+ longPressHandlerRef = setTimeout(() => {
+ tapCandidate = false;
+ onLongPress();
+ }, delayLongPress);
},
onStart: (event, gestureState) => {
initialTouches = event.nativeEvent.touches;
numberInitialTouches = gestureState.numberActiveTouches;
- if (gestureState.numberActiveTouches > 1)
+ tapCandidate = gestureState.numberActiveTouches === 1;
+ if (gestureState.numberActiveTouches > 1) {
+ cancelPendingTaps();
return;
+ }
const tapTS = Date.now();
// Handle double tap event by calculating diff between first and second taps timestamps
isDoubleTapPerformed = Boolean(lastTapTS && tapTS - lastTapTS < DOUBLE_TAP_DELAY);
@@ -99,6 +118,8 @@ const usePanResponder = ({ initialScale, initialTranslate, onZoom, doubleTapToZo
y: initialTranslate.y +
(SCREEN_HEIGHT / 2 - touchY) * (targetScale / currentScale),
}, targetScale);
+ tapCandidate = false;
+ cancelTap(tapTimer.current);
onZoom(!isScaled);
Animated.parallel([
Animated.timing(translateValue.x, {
@@ -130,6 +151,7 @@ const usePanResponder = ({ initialScale, initialTranslate, onZoom, doubleTapToZo
const { dx, dy } = gestureState;
if (Math.abs(dx) >= meaningfulShift || Math.abs(dy) >= meaningfulShift) {
cancelLongPressHandle();
+ tapCandidate = false;
}
// Don't need to handle move because double tap in progress (was handled in onStart)
if (doubleTapToZoomEnabled && isDoubleTapPerformed) {
@@ -140,6 +162,8 @@ const usePanResponder = ({ initialScale, initialTranslate, onZoom, doubleTapToZo
gestureState.numberActiveTouches === 2) {
numberInitialTouches = 2;
initialTouches = event.nativeEvent.touches;
+ tapCandidate = false;
+ cancelPendingTaps();
}
const isTapGesture = numberInitialTouches == 1 && gestureState.numberActiveTouches === 1;
const isPinchGesture = numberInitialTouches === 2 && gestureState.numberActiveTouches === 2;
@@ -214,6 +238,16 @@ const usePanResponder = ({ initialScale, initialTranslate, onZoom, doubleTapToZo
},
onRelease: () => {
cancelLongPressHandle();
+ if (tapCandidate && onTap) {
+ // Wait out the double tap window so a double tap zooms without also toggling.
+ const timer = setTimeout(() => {
+ pendingTaps.current.delete(timer);
+ onTap();
+ }, DOUBLE_TAP_DELAY);
+ pendingTaps.current.add(timer);
+ tapTimer.current = timer;
+ }
+ tapCandidate = false;
if (isDoubleTapPerformed) {
isDoubleTapPerformed = false;
}
@@ -266,6 +300,12 @@ const usePanResponder = ({ initialScale, initialTranslate, onZoom, doubleTapToZo
tmpTranslate = null;
}
},
+ // A gesture taken over mid-pinch must commit like a release, or pans stay
+ // gated on the pre-pinch scale while the image still shows zoomed.
+ onTerminate: () => {
+ tapCandidate = false;
+ handlers.onRelease();
+ },
};
const panResponder = useMemo(() => createPanResponder(handlers), [handlers]);
return [panResponder.panHandlers, scaleValue, translateValue];