Fire-and-forget animation function for [IntOffset].
AnimateOffsetSample
@Composable
@Suppress("UNUSED_VARIABLE")
fun AnimateOffsetSample() {
@Composable
fun OffsetAnimation(selected: Boolean) {
// Animates the offset depending on the selected flag.
// [animateOffsetAsState] returns a State<Offset> object. The value of the State object is
// updated by the animation. Here we use that State<Offset> as a property delegate.
val offset: Offset by
animateOffsetAsState(if (selected) Offset(0f, 0f) else Offset(20f, 20f))
// In this example, animateIntOffsetAsState returns a State<IntOffset>. The value of the
// returned
// State object is updated by the animation.
val intOffset: IntOffset by
animateIntOffsetAsState(if (selected) IntOffset(0, 0) else IntOffset(50, 50))
}
}