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,
swipeToCloseEnabled = true,
doubleTapToZoomEnabled = true,
pinchRef,
}: Props) => {
const [isScaled, setIsScaled] = useState(false)
const [isLoaded, setIsLoaded] = useState(false)
@@ -223,6 +224,7 @@ const ImageItem = ({
}
const pinch = Gesture.Pinch()
.withRef(pinchRef)
.onStart((e) => {
pinchOrigin.value = {
x: e.focalX - SCREEN.width/2,
@@ -110,6 +110,13 @@ function ImageViewing({
}
}, [imageList, imageIndex])
const [pinchRefs] = useState(new Map())
for (let imageSrc of images) {
if (!pinchRefs.get(imageSrc)) {
pinchRefs.set(imageSrc, createRef())
}
}
if (!visible) {
return null
}
@@ -156,8 +163,15 @@ function ImageViewing({
delayLongPress={delayLongPress}
swipeToCloseEnabled={swipeToCloseEnabled}
doubleTapToZoomEnabled={doubleTapToZoomEnabled}
pinchRef={pinchRefs.get(imageSrc)}
/>
)}
renderScrollComponent={props => (
<ScrollView
{...props}
waitFor={Array.from(pinchRefs.values())}
/>
)}
onMomentumScrollEnd={onScroll}
//@ts-ignore
keyExtractor={(imageSrc, index) =>