Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: image zooms in fully after swiping on android #191

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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