Skip to content

Commit

Permalink
feat: allow simultaneous gesture (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
intergalacticspacehighway authored Oct 31, 2022
1 parent c945365 commit 838395f
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/zoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ import Animated, {
cancelAnimation,
runOnJS,
} from 'react-native-reanimated';
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
import {
Gesture,
GestureDetector,
GestureType,
} from 'react-native-gesture-handler';
import { ZoomListContext } from './zoom-list-context';

type Props = {
children: React.ReactNode;
minimumZoomScale?: number;
maximumZoomScale?: number;
simultaneousGesture?: GestureType;
} & ViewProps;

export function Zoom(props: Props) {
Expand All @@ -23,6 +28,7 @@ export function Zoom(props: Props) {
maximumZoomScale = 8,
style: propStyle,
onLayout,
simultaneousGesture,
} = props;

const zoomListContext = useContext(ZoomListContext);
Expand Down Expand Up @@ -198,11 +204,21 @@ export function Zoom(props: Props) {
);
}

return Gesture.Race(doubleTap, Gesture.Simultaneous(pan, pinch));
return Gesture.Race(
doubleTap,
simultaneousGesture
? Gesture.Simultaneous(pan, pinch, simultaneousGesture)
: Gesture.Simultaneous(pan, pinch)
);

// only add prop dependencies
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [maximumZoomScale, minimumZoomScale, zoomListContext]);
}, [
maximumZoomScale,
minimumZoomScale,
zoomListContext,
simultaneousGesture,
]);

useDerivedValue(() => {
if (scale.value > 1 && !isZoomed.value) {
Expand Down

0 comments on commit 838395f

Please sign in to comment.