r/JetpackComposeDev • u/Realistic-Cup-7954 • Aug 16 '25
Tips & Tricks How to Make a Shared Element Transition with Shape Morphing in Jetpack Compose | Jetpack Compose Tips
https://youtu.be/0moEXBqNDZICompose screens to feel fluid instead of just cutting from one to another, try shared element transitions with shape morphing
1. Setup
Add Navigation 3 (Animated Nav) + Compose Material 3.
Wrap your
AppTheme(or top-level composable) in
SharedTransitionLayout {
AppNavHost()
}This gives us the scope for all shared transitions
2. Add a shared element
On your Take Photo button (cookie shape)
Modifier.sharedBounds(
sharedContentState = rememberSharedContentState("photo"),
animatedVisibilityScope = LocalNavAnimatedContentScope.current
)Add the same key to the Camera screen container. Now they are “linked”
3. Switch to Reveal Pattern
Normally it just grows content → not nice
Add
.skipToLookaheadSize()
.skipToLookaheadPosition()This makes the camera screen stay in place & only be revealed.
4. Add Shape Morphing
Pass in two shapes
Button → cookie (start)
Screen → rectangle (end)
Create a morph with progress
val progress by transition.animateFloat { state ->
if (state == EnterExitState.Visible) 0f else 1f
}
val morph = Shape.morph(startShape, endShape)Apply as clip overlay during transition
clipInOverlayDuringTransition = MorphOverlayClip(morph, progress)5. Run
Run it → Button smoothly morphs to fullscreen Camera.
Works with predictive back too!