Usage
🚀 Usage
import Zoom from 'react-native-zoom-reanimated'
// For Apple Photos-style gallery, also import ScrollableRef type
import Zoom, { ScrollableRef } from 'react-native-zoom-reanimated'
💡 Examples
📁 See the
example/directory for complete working examples.
Basic Usage
import Zoom from 'react-native-zoom-reanimated'
<Zoom>
<Image
source={{ uri: imageUri }}
resizeMode="contain"
style={{ width: deviceWidth, height: imageHeight * deviceWidth / imageWidth }}
/>
</Zoom>
Image Gallery with FlatList
Basic horizontal gallery with paging:
<FlatList
data={IMAGES}
horizontal
pagingEnabled
renderItem={({ item }) => (
<View style={{ width: screenWidth }}>
<Zoom>
<Image source={{ uri: item }} style={{ width: '100%', height: '100%' }} resizeMode="contain" />
</Zoom>
</View>
)}
/>
📄 Full example:
example/ImageGalleryStandalone.tsx
Apple Photos-Style Gallery
For seamless swipe navigation while zoomed — just like Apple Photos:
<Zoom
enableGallerySwipe
parentScrollRef={flatListRef}
currentIndex={index}
itemWidth={deviceWidth + IMAGE_GAP}
>
<Image source={{ uri: imageUri }} />
</Zoom>
Features:
- ✅ Swipe between images even while zoomed in
- ✅ Smooth edge-to-scroll transition
- ✅ Auto zoom reset when changing images
- ✅ Gap between images
📄 Full example:
example/FlatListExample.tsx— complete implementation with all features
Using the Hook Directly
For advanced control, use useZoomGesture hook:
import { useZoomGesture } from 'react-native-zoom-reanimated'
import { useAnimatedReaction } from 'react-native-reanimated'
const { zoomGesture, contentContainerAnimatedStyle, onLayout, onLayoutContent, zoomOut, isZoomedIn, scale } = useZoomGesture({
minScale: 1,
maxScale: 5,
})
// React to scale changes efficiently in worklet (no JS bridge overhead)
useAnimatedReaction(
() => scale.value,
(currentScale) => {
console.log('Current scale:', currentScale)
}
)
// React to zoom state changes
useAnimatedReaction(
() => isZoomedIn.value,
(isZoomed) => {
console.log('Is zoomed:', isZoomed)
}
)
📄 Full example:
example/UseZoomGestureExample.tsx