MiSikora
10/16/2024, 5:03 PMval animationProgress = remember { Animatable(initialAnimationProgress) }
LaunchedEffect(Unit) {
while (isActive) {
if (animationProgress.value == 0f) {
animationProgress.animateTo(
targetValue = 1f,
animationSpec = tween(4000, easing = LinearEasing),
)
delay(4000)
} else {
animationProgress.animateTo(
targetValue = 0f,
animationSpec = tween(1200, easing = FastOutLinearInEasing),
)
delay(1200)
}
}
}
David
10/17/2024, 6:19 AMDavid
10/17/2024, 6:21 AMrememberInfiniteTransition
could be a fit for this use case.MiSikora
10/17/2024, 6:45 AMMiSikora
10/17/2024, 6:45 AMDavid
10/17/2024, 6:59 AMMiSikora
10/17/2024, 6:59 AMDavid
10/17/2024, 7:00 AMkeyframes
to go back and forth and then just set the RepeatMode.Restart
@Sampled
@Composable
fun InfiniteTransitionAnimateValueSample() {
// Creates an [InfiniteTransition] instance to run child animations.
val infiniteTransition = rememberInfiniteTransition()
// Infinitely animate a Dp offset from 0.dp to 100.dp
val offsetX by infiniteTransition.animateValue(
initialValue = 0.dp,
targetValue = 100.dp,
typeConverter = Dp.VectorConverter,
animationSpec = infiniteRepeatable(
animation = keyframes {
durationMillis = 500
0.dp at 200 // ms
80.dp at 300 using FastOutLinearInEasing
}
// Use the default RepeatMode.Restart to start from 0.dp after each iteration
)
)
Box(Modifier.offset(x = offsetX)) {
// Content goes here
}
}
David
10/17/2024, 7:00 AMMiSikora
10/17/2024, 7:01 AMMiSikora
10/17/2024, 7:03 AMAnimatable
and LaunchedEffect
is easier to maintainJonathan
10/17/2024, 2:58 PMLaunchedEffect
I don’t know if it’s correct but it works.Jonathan
10/17/2024, 3:02 PM