Skip to content

Commit

Permalink
Apply fix for image zoom issue
Browse files Browse the repository at this point in the history
Apply fix from jobtoday#191
  • Loading branch information
ls1955 committed Dec 24, 2023
1 parent dd88aa4 commit 6d5a352
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 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
3 changes: 3 additions & 0 deletions src/components/ImageItem/ImageItem.android.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Props = {
delayLongPress: number;
swipeToCloseEnabled?: boolean;
doubleTapToZoomEnabled?: boolean;
currentImageIndex: number;
};

const ImageItem = ({
Expand All @@ -49,6 +50,7 @@ const ImageItem = ({
delayLongPress,
swipeToCloseEnabled = true,
doubleTapToZoomEnabled = true,
currentImageIndex
}: Props) => {
const imageContainer = useRef<ScrollView & NativeMethodsMixin>(null);
const imageDimensions = useImageDimensions(imageSrc);
Expand Down Expand Up @@ -80,6 +82,7 @@ const ImageItem = ({
doubleTapToZoomEnabled,
onLongPress: onLongPressHandler,
delayLongPress,
currentImageIndex,
});

const imagesStyles = getImageStyles(
Expand Down
20 changes: 12 additions & 8 deletions src/components/ImageItem/ImageItem.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@ declare type Props = {
delayLongPress: number;
swipeToCloseEnabled?: boolean;
doubleTapToZoomEnabled?: boolean;
currentImageIndex: number;
};

declare const _default: React.MemoExoticComponent<({
imageSrc,
onZoom,
onRequestClose,
onLongPress,
delayLongPress,
swipeToCloseEnabled,
}: Props) => JSX.Element>;
declare const _default: React.MemoExoticComponent<
({
imageSrc,
onZoom,
onRequestClose,
onLongPress,
delayLongPress,
swipeToCloseEnabled,
currentImageIndex,
}: Props) => JSX.Element
>;

export default _default;
16 changes: 16 additions & 0 deletions src/hooks/usePanResponder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type Props = {
doubleTapToZoomEnabled: boolean;
onLongPress: () => void;
delayLongPress: number;
currentImageIndex: number;
};

const usePanResponder = ({
Expand All @@ -51,6 +52,7 @@ const usePanResponder = ({
doubleTapToZoomEnabled,
onLongPress,
delayLongPress,
currentImageIndex,
}: Props): Readonly<
[GestureResponderHandlers, Animated.Value, Animated.ValueXY]
> => {
Expand Down Expand Up @@ -156,6 +158,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 6d5a352

Please sign in to comment.