We use cookies to enhance your experience. By continuing, you agree to our Privacy Policy.

Back to Snippets

Shake Animation for UI Components in Jetpack Compose

This Jetpack Compose function, ShakeContent, applies a shaking effect to its composable child when the shake parameter is true. It uses animateFloatAsState with a repeatable animation to shift the content back and forth along the X-axis. The animation consists of three iterations with a short duration, creating a smooth shaking motion. This can be useful for error indications or interactive UI feedback.

UIAnimation
Cavin Macwan

Cavin Macwan

Posted on February 18, 2025

Shake Animation for UI Components in Jetpack Compose
Click to expand preview
Scroll for source code

Source Code