Draw a simple non-animating circular progress indicator.
CircularProgressIndicatorCustomAnimationSample
@Composable
fun CircularProgressIndicatorCustomAnimationSample() {
val progress = remember { mutableFloatStateOf(0f) }
val animatedProgress = remember { Animatable(0f) }
val colors =
ProgressIndicatorDefaults.colors(indicatorColor = Color.Green, trackColor = Color.White)
LaunchedEffect(Unit) {
snapshotFlow(progress::value).collectLatest {
animatedProgress.animateTo(it, tween(durationMillis = 1024, easing = LinearEasing))
}
}
Box(
modifier =
Modifier.background(MaterialTheme.colorScheme.background)
.padding(CircularProgressIndicatorDefaults.FullScreenPadding)
.fillMaxSize()
) {
Button(
modifier = Modifier.align(Alignment.Center).padding(12.dp),
onClick = { progress.floatValue = if (progress.floatValue == 0f) 1f else 0f },
label = { Text("Animate") },
)
// Draw the circular progress indicator with custom animation
Spacer(
Modifier.fillMaxSize().focusable().drawBehind {
drawCircularProgressIndicator(
progress = animatedProgress.value,
strokeWidth = 10.dp,
colors = colors,
startAngle = 120f,
endAngle = 60f,
)
}
)
}
}