Tolriq
07/02/2024, 6:49 PMZach Klippenstein (he/him) [MOD]
07/02/2024, 7:06 PMTolriq
07/02/2024, 7:09 PMyschimke
07/02/2024, 7:20 PMyschimke
07/02/2024, 7:21 PMyschimke
07/02/2024, 7:22 PMTolriq
07/02/2024, 7:29 PMefemoney
07/05/2024, 12:20 AM@Composable
fun ProgressIndicator(
progress: () -> Float,
modifier: Modifier = Modifier,
progressColor: BackgroundColor = BackgroundColor.Unspecified,
progressBarColor: BackgroundColor = BackgroundColor.Unspecified,
animateProgress: Boolean = true,
) {
val bgs = LocalBackgroundColors.current
val color = progressColor.takeOrElse { bgs.state.successHighEmphasize }
val barColor = progressBarColor.takeOrElse { bgs.tertiary }
val getProgress = remember(progress) { { progress().coerceIn(ProgressRange) } }
val getValue = if (!animateProgress) getProgress else {
val animation = remember { AnimationState(getProgress()) }
LaunchedEffect(getProgress) {
snapshotFlow(getProgress).collectLatest {
animation.animateTo(it, ProgressAnimationSpec)
}
}
({ animation.value })
}
Canvas(
modifier
.progressSemantics(progress)
.requiredHeight(4.dp)
.fillMaxWidth()
.clip(CircleShape)
) {
drawTrack(barColor, 1f)
drawTrack(color, getValue())
}
}
efemoney
07/05/2024, 12:28 AMState<Float>
in my parameters, and I’d rather not. The getProgress could also easily be a rememberUpdatedState
. Also duplicated Modifier.progressSemantics
to take a lambda.Tolriq
07/05/2024, 6:26 AM