Killian
09/15/2023, 12:38 PMval transition = rememberInfiniteTransition(label = "transition")
val visibility by transition.animateFloat(
initialValue = 0f,
targetValue = 1f,
animationSpec = infiniteRepeatable(
animation = tween(
durationMillis = 6.seconds.inWholeMilliseconds.toInt(),
),
repeatMode = RepeatMode.Reverse
), label = "visibility"
)
and then the views
Box {
Text(
modifier = Modifier.alpha(visibility),
text = "One view"
)
Text(
modifier = Modifier.alpha(1f - visibility),
text = "Other view"
)
}
Though the effect I’m trying to go for is that one view is shown for 6 seconds, and then it should fade in a second into the other view and show that for 6 seconds and this should continue infinite amount of times. Any tips or articles or pointers I could use? Thanks in advance! 🙂Stylianos Gakis
09/15/2023, 12:41 PMtransition.AnimatedContent
instead?
It allows you to define the spec for entering and exiting as you wishFilip Wiesner
09/15/2023, 12:42 PMCrossfade
specifically 😄Killian
09/15/2023, 12:45 PMCrossfade
, though that transitions between two states indeed, but it does not allow me to specify an infinite transition:Filip Wiesner
09/15/2023, 12:48 PMtargetState
every 6 seconds. It's a quick and dirty solution, although it may not be the best one.Killian
09/15/2023, 12:54 PMStylianos Gakis
09/15/2023, 1:03 PMLaunchedEffect(Unit) {
while(isActive) {
delay(6.seconds)
state = #1
delay(6.seconds)
state = #2
}
}
🤷
rememberUpdatedTransition seems to be the one with support for CrossFade or AnimatedContent. Don’t know how much it’d make sense for content to be animated this way backed by an *infinite*Transition, but maybe make a feature request if you feel like it to see what they sayFilip Wiesner
09/15/2023, 1:06 PMAnimatedContent
will support manually updating animation progress (for predictive back gesture), so that would enable you to have infinite transition.Killian
09/15/2023, 1:09 PMLaunchedEffect
and just any of the animation API’s? It seems the usage of delay
is something that the transition.animateFloat
also supports.. I just cannot figure out how to make it do what I want.Stylianos Gakis
09/15/2023, 1:11 PMKillian
09/15/2023, 1:12 PMRepeatMode.Reverse
it also reverses right after; ignoring the delay on it’s way back sort of. 🤷Albert Chang
09/16/2023, 4:11 AMinfiniteRepeatable(
animation = keyframes {
durationMillis = 7000
0f at 3000
1f at 4000
},
repeatMode = RepeatMode.Reverse,
initialStartOffset = StartOffset(3000)
)