Scroll waits for pinch

This commit is contained in:
Dan Abramov
2023-10-03 20:36:57 +01:00
parent 99a22a0508
commit b3d05972e4
2 changed files with 16 additions and 0 deletions
@@ -156,6 +156,7 @@ const ImageItem = ({
delayLongPress, delayLongPress,
swipeToCloseEnabled = true, swipeToCloseEnabled = true,
doubleTapToZoomEnabled = true, doubleTapToZoomEnabled = true,
pinchRef,
}: Props) => { }: Props) => {
const [isScaled, setIsScaled] = useState(false) const [isScaled, setIsScaled] = useState(false)
const [isLoaded, setIsLoaded] = useState(false) const [isLoaded, setIsLoaded] = useState(false)
@@ -223,6 +224,7 @@ const ImageItem = ({
} }
const pinch = Gesture.Pinch() const pinch = Gesture.Pinch()
.withRef(pinchRef)
.onStart((e) => { .onStart((e) => {
pinchOrigin.value = { pinchOrigin.value = {
x: e.focalX - SCREEN.width/2, x: e.focalX - SCREEN.width/2,
@@ -110,6 +110,13 @@ function ImageViewing({
} }
}, [imageList, imageIndex]) }, [imageList, imageIndex])
const [pinchRefs] = useState(new Map())
for (let imageSrc of images) {
if (!pinchRefs.get(imageSrc)) {
pinchRefs.set(imageSrc, createRef())
}
}
if (!visible) { if (!visible) {
return null return null
} }
@@ -156,6 +163,13 @@ function ImageViewing({
delayLongPress={delayLongPress} delayLongPress={delayLongPress}
swipeToCloseEnabled={swipeToCloseEnabled} swipeToCloseEnabled={swipeToCloseEnabled}
doubleTapToZoomEnabled={doubleTapToZoomEnabled} doubleTapToZoomEnabled={doubleTapToZoomEnabled}
pinchRef={pinchRefs.get(imageSrc)}
/>
)}
renderScrollComponent={props => (
<ScrollView
{...props}
waitFor={Array.from(pinchRefs.values())}
/> />
)} )}
onMomentumScrollEnd={onScroll} onMomentumScrollEnd={onScroll}