Add SharedDelay feature to the AnimatedOffset
This commit is contained in:
parent
22abe55fce
commit
611374d800
2 changed files with 28 additions and 5 deletions
|
|
@ -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(
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue