Skip to content

Commit

Permalink
fix: image zooms in fully after swiping on android
Browse files Browse the repository at this point in the history
  • Loading branch information
MorganDavid committed Aug 16, 2023
1 parent 8a91a9c commit f193ef6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/ImageViewing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ function ImageViewing({
delayLongPress={delayLongPress}
swipeToCloseEnabled={swipeToCloseEnabled}
doubleTapToZoomEnabled={doubleTapToZoomEnabled}
currentImageIndex={currentImageIndex}
/>
)}
onMomentumScrollEnd={onScroll}
Expand Down
16 changes: 16 additions & 0 deletions src/hooks/usePanResponder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Props = {
doubleTapToZoomEnabled: boolean;
onLongPress: () => void;
delayLongPress: number;
currentImageIndex: number;
};

const usePanResponder = ({
Expand All @@ -49,6 +50,7 @@ const usePanResponder = ({
doubleTapToZoomEnabled,
onLongPress,
delayLongPress,
currentImageIndex,
}: Props): Readonly<
[GestureResponderHandlers, Animated.Value, Animated.ValueXY]
> => {
Expand Down Expand Up @@ -120,6 +122,20 @@ const usePanResponder = ({
return () => scaleValue.removeAllListeners();
});

useEffect(() => {
onZoom(false);

// workaround for a bug where scaleValue gets incorrectly set after zooming then swiping.
// https://github.com/jobtoday/react-native-image-viewing/issues/158
const timeout = setTimeout(() => {
scaleValue.setValue(initialScale);
currentScale = initialScale;
currentTranslate = initialTranslate;
}, 100);

return () => clearTimeout(timeout);
}, [currentImageIndex]);

const cancelLongPressHandle = () => {
longPressHandlerRef && clearTimeout(longPressHandlerRef);
};
Expand Down

0 comments on commit f193ef6

Please sign in to comment.