Add SharedDelay feature to the AnimatedOffset

This commit is contained in:
Thomas Andres Gomez 2022-07-19 11:20:45 +02:00
parent 22abe55fce
commit 611374d800
2 changed files with 28 additions and 5 deletions

View file

@ -2,13 +2,14 @@ package com.pixelized.biblib.ui.composable.animation
import androidx.compose.animation.* import androidx.compose.animation.*
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
@Composable @Composable
fun AnimatedDelayer( fun AnimatedDelayer(
delay: Int = Delay.DELTA, delay: Int = Delay.DELTA,
content: @Composable AnimatedDelayerScope.() -> Unit content: @Composable AnimatedDelayerScope.() -> Unit
) { ) {
val scope = AnimatedDelayerScope( val scope = IncreasedDelayerScope(
delay = Delay(value = delay) delay = Delay(value = delay)
) )
scope.content() scope.content()
@ -33,9 +34,31 @@ fun <T> AnimatedDelayer(
} }
} }
class AnimatedDelayerScope( @Composable
var delay: Delay = Delay() fun AnimatedDelayerScope.SharedDelay(content: @Composable AnimatedDelayerScope.() -> Unit) {
) val localScope = SharedDelayerScope(delay = play())
localScope.content()
}
@Stable
interface AnimatedDelayerScope {
val delay: Delay
fun play(): Delay
}
@Stable
private class IncreasedDelayerScope(
override var delay: Delay
): AnimatedDelayerScope {
override fun play(): Delay = delay++
}
@Stable
private class SharedDelayerScope(
override var delay: Delay
): AnimatedDelayerScope {
override fun play(): Delay = delay
}
@JvmInline @JvmInline
value class Delay( value class Delay(

View file

@ -26,7 +26,7 @@ fun AnimatedDelayerScope.AnimatedOffset(
AnimatedOffset( AnimatedOffset(
modifier = modifier, modifier = modifier,
transitionLabel = transitionLabel, transitionLabel = transitionLabel,
delay = delay++, delay = play(),
contentAlignment = contentAlignment, contentAlignment = contentAlignment,
content = content, content = content,
) )