A Jetpack Compose library equivalent to ViewGroup's layoutAnimation, providing staggered entrance animations for layout children with support for both pre-built and custom animations.
ComposeLayoutAnimation simplifies the process of adding entrance animations to layout children in Jetpack Compose. Just like ViewGroup's layoutAnimation in traditional Android development, this library allows you to define an animation that automatically applies to all children of a layout with configurable delay between items.
The library provides two types of animations:
- GraphicsLayer Modifications: Visual-only animations like fade, scale, and rotation that don't affect layout measurements
- Layout Modifications: Animations that affect actual layout like slide and expand
- Staggered animations for layout children
- Pre-built animation templates
- Custom animation support
- Simple API for combining animations
- Layout and GraphicsLayer animations
- Supports all Compose Layouts including
Column
,Row
,LazyColumn
,LazyRow
, andLazyVerticalGrid
ComposeLayoutAnimation is available on mavenCentral()
, Add the dependency to your app's build.gradle
:
dependencies {
implementation 'io.github.aghajari:ComposeLayoutAnimation:1.0.0'
}
Basic usage with a simple animation:
Column {
LayoutAnimation(
animationSpec = LayoutAnimationSpec(
delayMillisBetweenItems = 50,
) {
fade(from = 0f, to = 1f) with
translationY(from = 0f, to = 100f) then
translationY(from = 100f, to = 0f)
},
) {
repeat(5) { index ->
CardItem(
text = "Item $index",
modifier = Modifier.animateLayoutItem(),
)
}
}
}
Output:
Basic usage with a pre-built animation:
LayoutAnimation(animationSpec = fallDownAnimationSpec()) {
...
}
Ready-to-use animations for common scenarios:
fallDownAnimationSpec()
: Items fade in while falling from abovebounceAnimationSpec()
: Items bounce up from bottomspiralAnimationSpec()
: Items spiral in with rotationflipAnimationSpec()
: Items flip in verticallyorigamiUnfoldAnimationSpec()
: 3D paper unfolding effectperspectiveRevealAnimationSpec()
: 3D perspective swing effectelasticSnapAnimationSpec()
: Elastic snapping from sidecascadeDropAnimationSpec()
: Cascading drop with rotationswivelRevealAnimationSpec()
: 3D door-like opening effectelegantEntranceAnimationSpec()
: Sophisticated entrance with combined effects
Combine animations using various operators:
// Parallel animations
fade() + scale() // Using +
fade() with scale() // Using 'with' infix function
together(fade(), scale()) // Using together()
// Sequential animations
fade() then scale() // Using 'then' infix function
sequence(fade(), scale()) // Using sequence()
Every animation, whether pre-built or custom, can be configured with:
durationMillis
: Duration of the animationdelayMillis
: Delay before the animation startsdelayMillisBetweenItems
: Stagger delay between itemseasing
: Easing curve for the animationrepeatMode
: How the animation should repeat (Restart or Reverse)repeatIterations
: Number of times to repeat
Share your animations with us :))
fun cascadeDropAnimationSpec(
initialDelayMillis: Int = 0,
durationMillis: Int = 1700,
delayMillisBetweenItems: Int = (durationMillis * 0.2).toInt(),
easing: Easing = FastOutSlowInEasing,
): LayoutAnimationSpec {
return LayoutAnimationSpec(
initialDelayMillis = initialDelayMillis,
delayMillisBetweenItems = delayMillisBetweenItems,
) {
translationY(
durationMillis = (durationMillis * 0.5).toInt(),
easing = easing,
from = -200f,
to = 0f,
) + rotationZ(
durationMillis = (durationMillis * 0.5).toInt(),
easing = easing,
from = -15f,
to = 0f,
) + fade(
durationMillis = (durationMillis * 0.3).toInt(),
easing = LinearEasing,
from = 0f,
to = 1f,
)
}
}
Copyright 2025 Amir Hossein Aghajari
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.