The useZoomable hook is the primary way to enable zoom, pan, and tap gestures on a component. It orchestrates layout calculations and gesture handling, returning the necessary props to apply to a component and its gesture handlers.
To use it, pass a configuration object of type UseZoomableProps and receive an object containing animatedStyle, gestures, and onZoomableLayout.
Key Props for useZoomable:
minScale / maxScale: Constraints for the zoom level.scale: The current scale.doubleTapScale: The scale factor applied during a double tap.isPanEnabled / isPinchEnabled: Boolean flags to toggle panning and pinching.isSingleTapEnabled / isDoubleTapEnabled: Boolean flags to toggle single and double tap detection.onInteractionStart / onInteractionEnd: Lifecycle callbacks for any interaction.onPinchStart / onPinchEnd: Lifecycle callbacks for pinch gestures.onPanStart / onPanEnd: Lifecycle callbacks for pan gestures.onSingleTap / onDoubleTap: Callbacks triggered by tap gestures.onProgrammaticZoom: Callback for zoom events triggered via code.onResetAnimationEnd: Callback triggered when a reset animation completes.onLayout: Callback for layout changes.ref: A React ref used to allow programmatic control via useZoomableHandle.
const { animatedStyle, gestures, onZoomableLayout } = useZoomable({
minScale: 1,
maxScale: 3,
scale: 1,
doubleTapScale: 2,
maxPanPointers: 2,
isPanEnabled: true,
isPinchEnabled: true,
isSingleTapEnabled: true,
isDoubleTapEnabled: true,
// ... other callbacks
ref: myRef,
});
// Use 'animatedStyle' on your view/image
// Use 'gestures' with your gesture handler component
// Use 'onZoomableLayout' on your container's onLayout prop