An easing function for an arbitrary [Path].
PathEasingSample
@Composable
fun PathEasingSample() {
// Creates a custom PathEasing curve and applies it to an animation
var toggled by remember { mutableStateOf(true) }
val pathForAnimation = remember {
Path().apply {
moveTo(0f, 0f)
cubicTo(0.05f, 0f, 0.133333f, 0.06f, 0.166666f, 0.4f)
cubicTo(0.208333f, 0.82f, 0.25f, 1f, 1f, 1f)
}
}
val offset by
animateIntOffsetAsState(
targetValue = if (toggled) IntOffset.Zero else IntOffset(300, 300),
label = "offset",
animationSpec = tween(durationMillis = 1000, easing = PathEasing(pathForAnimation)),
)
Box(modifier = Modifier.fillMaxSize().clickable { toggled = !toggled }) {
Box(modifier = Modifier.offset { offset }.size(100.dp).background(Color.Blue))
}
}