ShakeController

class ShakeController(amplitude: Dp = 20.dp, @IntRange(from = 0) durationMillis: Int = 400, @FloatRange(from = 0.0) frequencyHz: Float = 8.0f, @FloatRange(from = 0.0, to = 1.0) decay: Float = 0.7f)

Controls a horizontal shake animation applied through Modifier.shakenBy.

Parameters

amplitude

Maximum horizontal displacement of the shake.

durationMillis

Total duration of the shake animation in milliseconds.

frequencyHz

Desired number of complete oscillations per second.

decay

Amount by which the amplitude decreases between successive shake cycles. 0f disables decay, while 1f applies maximum decay.

Constructors

Link copied to clipboard
constructor(amplitude: Dp = 20.dp, @IntRange(from = 0) durationMillis: Int = 400, @FloatRange(from = 0.0) frequencyHz: Float = 8.0f, @FloatRange(from = 0.0, to = 1.0) decay: Float = 0.7f)

Properties

Link copied to clipboard

Whether the shake animation is currently running.

Functions

Link copied to clipboard
suspend fun cancel(animated: Boolean = false)

Cancels an ongoing shake and resets its translation.

Link copied to clipboard
suspend fun shake()

Runs the shake animation.