Skip to content

Fix #149 Pinch zoom on IOS #160

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

Open
wants to merge 2 commits 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
4 changes: 4 additions & 0 deletions src/ImageViewing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Props = {
keyExtractor?: (imageSrc: ImageSource, index: number) => string;
imageIndex: number;
visible: boolean;
maxScale?: number;
onRequestClose: () => void;
onLongPress?: (image: ImageSource) => void;
onImageIndexChange?: (imageIndex: number) => void;
Expand All @@ -47,6 +48,7 @@ type Props = {
const DEFAULT_ANIMATION_TYPE = "fade";
const DEFAULT_BG_COLOR = "#000";
const DEFAULT_DELAY_LONG_PRESS = 800;
const DEFAULT_MAX_SCALE = 3;
const SCREEN = Dimensions.get("screen");
const SCREEN_WIDTH = SCREEN.width;

Expand All @@ -55,6 +57,7 @@ function ImageViewing({
keyExtractor,
imageIndex,
visible,
maxScale = DEFAULT_MAX_SCALE,
onRequestClose,
onLongPress = () => {},
onImageIndexChange,
Expand Down Expand Up @@ -135,6 +138,7 @@ function ImageViewing({
<ImageItem
onZoom={onZoom}
imageSrc={imageSrc}
maxScale={maxScale}
onRequestClose={onRequestCloseEnhanced}
onLongPress={onLongPress}
delayLongPress={delayLongPress}
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 @@ -33,6 +33,7 @@ const SCREEN_HEIGHT = SCREEN.height;

type Props = {
imageSrc: ImageSource;
maxScale: number;
onRequestClose: () => void;
onZoom: (isZoomed: boolean) => void;
onLongPress: (image: ImageSource) => void;
Expand All @@ -43,6 +44,7 @@ type Props = {

const ImageItem = ({
imageSrc,
maxScale,
onZoom,
onRequestClose,
onLongPress,
Expand Down Expand Up @@ -120,6 +122,7 @@ const ImageItem = ({
<ScrollView
ref={imageContainer}
style={styles.listItem}
maximumZoomScale={maxScale}
pagingEnabled
nestedScrollEnabled
showsHorizontalScrollIndicator={false}
Expand Down
2 changes: 2 additions & 0 deletions src/components/ImageItem/ImageItem.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ImageSource } from "../../@types";

declare type Props = {
imageSrc: ImageSource;
maxScale: number;
onRequestClose: () => void;
onZoom: (isZoomed: boolean) => void;
onLongPress: (image: ImageSource) => void;
Expand All @@ -22,6 +23,7 @@ declare type Props = {

declare const _default: React.MemoExoticComponent<({
imageSrc,
maxScale,
onZoom,
onRequestClose,
onLongPress,
Expand Down
3 changes: 2 additions & 1 deletion src/components/ImageItem/ImageItem.ios.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const SCREEN_HEIGHT = SCREEN.height;

type Props = {
imageSrc: ImageSource;
maxScale: number;
onRequestClose: () => void;
onZoom: (scaled: boolean) => void;
onLongPress: (image: ImageSource) => void;
Expand All @@ -45,6 +46,7 @@ type Props = {

const ImageItem = ({
imageSrc,
maxScale,
onZoom,
onRequestClose,
onLongPress,
Expand All @@ -62,7 +64,6 @@ const ImageItem = ({
const scrollValueY = new Animated.Value(0);
const scaleValue = new Animated.Value(scale || 1);
const translateValue = new Animated.ValueXY(translate);
const maxScale = scale && scale > 0 ? Math.max(1 / scale, 1) : 1;

const imageOpacity = scrollValueY.interpolate({
inputRange: [-SWIPE_CLOSE_OFFSET, 0, SWIPE_CLOSE_OFFSET],
Expand Down