AnimatedVisibility & Crossfade
Animate appearance and content swaps.
AnimatedVisibility & Crossfade is a free Jetpack Compose Academy lesson on CoddyKit — lesson 2 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.
Animating What Appears
Sometimes you want content to slide or fade in rather than pop. AnimatedVisibility animates a Composable as it enters and exits the screen. ✨
Wrap What You Show
Give AnimatedVisibility a boolean and a content lambda. When the boolean flips, it animates that content in or out for you.
AnimatedVisibility(visible = show) {
Text("Hello!")
}Default Enter and Exit
Out of the box it uses a gentle fade plus expand and shrink. The element appears and disappears smoothly without any extra configuration.
Customize the Entrance
Set the enter parameter to choose how content arrives. Combine transitions like fadeIn and slideInVertically with the plus operator.
enter = fadeIn() + slideInVertically()Customize the Exit
The exit parameter controls how content leaves. You can mirror the entrance or pick a different effect like shrinkOut for variety.
exit = fadeOut() + shrinkVertically()Slide, Expand, Scale
Compose ships many transitions: slideIn, expandHorizontally, scaleIn, and their exit pairs. Mix them to design exactly the motion you want.
Swapping Content Smoothly
To replace one Composable with another, reach for Crossfade. It fades the old content out while the new content fades in. 🔀
Crossfade on a Key
Give Crossfade a targetState. Whenever that value changes, it animates between the content produced for the old and new states.
Crossfade(targetState = screen) { current ->
ScreenFor(current)
}Great for Tabs and Screens
Crossfade shines when switching between distinct views, like loading versus loaded states or two tabs, giving a polished blend instead of a jarring swap.
Tune the Crossfade Timing
Pass an animationSpec to Crossfade to slow down or speed up the blend. A longer tween makes the transition feel softer and more deliberate.
Crossfade(state, animationSpec = tween(700)) { ... }Pick the Right Tool
Use AnimatedVisibility to show or hide one thing, and Crossfade to swap between alternatives. Each solves a different appearance problem.
Quick Check
Which Composable smoothly swaps one piece of content for another?
Recap: Enter, Exit, Swap
You now animate appearance with AnimatedVisibility and blend between views with Crossfade, customizing enter, exit, and timing. 🎉
Frequently asked questions
Is the “AnimatedVisibility & Crossfade” lesson free?
Yes — the full text of “AnimatedVisibility & Crossfade” 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 “AnimatedVisibility & Crossfade”?
Animate appearance and content swaps. 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 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “AnimatedVisibility & Crossfade” 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
- animate*AsState for Simple Tweens
- AnimatedVisibility & Crossfade
- updateTransition for Coordinated Motion
- Gesture-Driven Animations