Transform: Pan, Zoom & Rotate
Support pinch and multi-touch gestures.
Transform: Pan, Zoom & Rotate is a free Jetpack Compose Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Jetpack Compose Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Pinch, Zoom, Rotate
Some gestures use two fingers at once. Compose bundles pan, zoom, and rotate into a single helper called detectTransformGestures. 🤏
One Detector, Three Values
Inside pointerInput, detectTransformGestures hands you pan as an Offset, zoom as a Float scale, and rotation in degrees together.
detectTransformGestures { _, pan, zoom, rotation -> }Store the Three States
Keep a scale, an offset, and a rotation in remembered state. Update each from the gesture so the element transforms live.
var scale by remember { mutableStateOf(1f) }Multiply the Zoom
The zoom value is relative, so multiply it into your scale rather than replacing it. Pinch out grows, pinch in shrinks.
scale *= zoomAdd the Rotation
The rotation delta is in degrees per gesture step. Accumulate it so twisting two fingers spins your content smoothly.
angle += rotationPan Moves It Around
The pan Offset reports how far the gesture's center moved. Add it to your offset state to slide the content under the fingers.
offset += panApply with graphicsLayer
The clean way to render transforms is the graphicsLayer modifier. Set scaleX, scaleY, rotationZ, and translation in one place.
Modifier.graphicsLayer(scaleX = scale, scaleY = scale, rotationZ = angle)Translate Inside the Layer
Inside graphicsLayer, set translationX and translationY from your offset. It transforms without forcing a costly layout pass.
translationX = offset.x; translationY = offset.yClamp the Scale
Users will pinch wildly, so clamp your scale to sane bounds with coerceIn. This stops content from vanishing or filling the world.
scale = scale.coerceIn(0.5f, 5f)Order of Operations
graphicsLayer applies scale, then rotation, then translation. Knowing this order helps you predict where transformed content lands.
Centered Around the Pivot
By default transforms pivot around the element's center. Adjust transformOrigin in graphicsLayer to zoom and rotate around another point.
Modifier.graphicsLayer(transformOrigin = TransformOrigin(0f, 0f))Quick Check
How should you apply the incoming zoom value to your scale state?
Recap: Multi-Touch Magic
You used detectTransformGestures for pan, zoom, and rotate, then applied them through graphicsLayer with clamping. Pinch-to-zoom is yours. 🎉
Frequently asked questions
Is the “Transform: Pan, Zoom & Rotate” lesson free?
Yes — the full text of “Transform: Pan, Zoom & Rotate” is free to read here on the web, and the Jetpack Compose Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Jetpack Compose Academy course, upgrade to CoddyKit PRO.
What will I learn in “Transform: Pan, Zoom & Rotate”?
Support pinch and multi-touch gestures. You practise Jetpack Compose Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Jetpack Compose Academy?
No prior experience is required. Jetpack Compose Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Transform: Pan, Zoom & Rotate” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Jetpack Compose Academy lesson?
Yes. Every Jetpack Compose Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- pointerInput & detectTapGestures
- Drag, Swipe & Fling
- Transform: Pan, Zoom & Rotate
- Nested Scroll Connections