Class

PathEasing

An easing function for an arbitrary Path.

PathEasingSample

@Sampled
@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))
    }
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: