Bobby Hargett
10/02/2023, 10:58 PM@Composable
private fun ScheduleTimeTracker(width: Dp, model: ItemModel) {
val trackerWidth = 8.dp
val trackerHeight = 6.dp
val position = remember { mutableStateOf(width.times(model.timeLeftInPercent())) } //so 30 minutes into an hour should timeLeftInPercent would be .50f
val offsetState: Dp by animateDpAsState(
position.value,
animationSpec = tween<Dp>(model.timeLeftInMillis(), easing = FastOutLinearInEasing), //30 minute show it should take this vertical line 30 minutes to travel the horizontal length of the box
label = "time tracker"
)
Box(
modifier = Modifier
.width(trackerWidth)
.offset(x = offsetState),
contentAlignment = Alignment.TopCenter
) {
Spacer(
Modifier
.width(1.dp)
.fillMaxHeight()
.background(Color.Red)
)
Triangle(color = Color.Red, Modifier.size(trackerWidth, height = trackerHeight))
}
LaunchedEffect(true) {
position.value = width.minus(4.dp)
}
}
I ask also, because at the top of this function I had a println and I noticed that it was printing it with every part of the animation. I think that is expected because it recomposes to animate the vertical line, but wanted to verify.Francesc
10/02/2023, 11:09 PMmodifier = modifier.offset { IntOffset(x = offsetState, y = 0) }