image.png
# compose
l
image.png
d
Seems like an
initialDelay
parameter (a delay that doesn't repeat) on
repeatable/infiniteRepeatable
could be useful. Could you file a feature request for this? For the time being you could achieve this effect by using a coroutine-based animation API (e.g. Animatable, animate, etc) for each animation, and offset the initial start via a suspend
delay
before calling
animateTo
for starting them.
l
Where is initialDelay a parameter of the function?
@Doris Liu my code is here
Copy code
@Composable
private fun Circle(color: Color, delayMillis: Int) {
    val infiniteTransition = rememberInfiniteTransition()
    val animatedFloat by infiniteTransition.animateFloat(
        initialValue = 0f, targetValue = -10f, animationSpec = infiniteRepeatable(
            animation = tween(400, delayMillis = delayMillis, easing = LinearEasing),
            repeatMode = RepeatMode.Reverse
        )
    )
    Box(
        modifier = Modifier
            .offset(y = animatedFloat.dp)
            .padding(horizontal = 2.dp)
            .clip(CircleShape)
            .size(10.dp)
            .background(color)
    )
}
d
initialDelay
was an idea that I thought could be useful. It isn't implemented yet. You could file an issue here to track the future development of it. 🙂
What I suggested above using coroutine would look something like:
Copy code
@Composable
private fun Circle(color: Color, delayMillis: Int) {
    val animatedFloat = remember { Animatable(0f) }
    LaunchedEffect(animatedFloat) {
        delay(delayMillis) // delay here to avoid repeated delays
        animatedFloat.animateTo(targetValue = -10f, animationSpec = infiniteRepeatable(
            animation = tween(400, easing = LinearEasing),
            repeatMode = RepeatMode.Reverse
        )
    )
    Box(
        modifier = Modifier
            .offset(y = animatedFloat.value.dp)
            .padding(horizontal = 2.dp)
            .clip(CircleShape)
            .size(10.dp)
            .background(color)
    )
}
l
That’s perfect. Thank you very much.
h
Resurrecting an old thread! @Doris Liu was this ever filed? I couldn't find anything similar on issue tracker. I guess this could be useful for
rememberInfiniteTransition
. LaunchedEffect + delay is useful for
Animatable
s but the same hack ofc doesn't work for
transition
s.
d
I don't think this was filed. Please feel free to file one. What delay support would you like to have for
transition
s, or is this specific to infinite transitions?
h
Yeah e.g. tween already supports delay. This is specific to infinite transitions
d
I see. The delay support should be fairly straightforward to add. It's on my (long 😅) list of todo's. Please feel free to create an issue if you are interested in tracking the progress of that work. 🙂
Quick follow-up + a question: I'm working on the impl for this feature. In addition to initialDelay, I'm curious if there's a need for the opposite of a delay i.e. fast forward to a specific time on the timeline before starting. 🙂
BTW, the issue is tracked here: https://issuetracker.google.com/193173055
h
@Doris Liu I've never needed that but it could be useful