Keep content centered when zoomed out
masterYou can force the content to remain centered in the viewport whenever the scale is less than 1× (zoomed out). This is useful for UIs like cinema or ticket-booking apps where the layout should stay framed until the user zooms in. When this mode is active, panning is restricted while zoomed out, and the content will snap back to the center. Once the user zooms in past 1×, free panning is enabled.
To achieve this, use the following props on <TransformWrapper>:
centerZoomedOut: (boolean) Keeps content centered whenever scale < 1.centerOnInit: (boolean) Centers content when the component mounts.initialScale: (number) Sets the starting zoom level (e.g.,0.5for 50%).minScale: (number) Sets the minimum allowed zoom level.
<TransformWrapper
initialScale={0.5}
minScale={0.2}
centerOnInit
centerZoomedOut
>
{(utils) => (
<TransformComponent>
<img src="your-image.jpg" alt="" />
</TransformComponent>
)}
</TransformWrapper>