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.runtime.Composable
|
||||
import androidx.compose.runtime.Stable
|
||||
|
||||
@Composable
|
||||
fun AnimatedDelayer(
|
||||
delay: Int = Delay.DELTA,
|
||||
content: @Composable AnimatedDelayerScope.() -> Unit
|
||||
) {
|
||||
val scope = AnimatedDelayerScope(
|
||||
val scope = IncreasedDelayerScope(
|
||||
delay = Delay(value = delay)
|
||||
)
|
||||
scope.content()
|
||||
|
|
@ -33,9 +34,31 @@ fun <T> AnimatedDelayer(
|
|||
}
|
||||
}
|
||||
|
||||
class AnimatedDelayerScope(
|
||||
var delay: Delay = Delay()
|
||||
)
|
||||
@Composable
|
||||
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
|
||||
value class Delay(
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ fun AnimatedDelayerScope.AnimatedOffset(
|
|||
AnimatedOffset(
|
||||
modifier = modifier,
|
||||
transitionLabel = transitionLabel,
|
||||
delay = delay++,
|
||||
delay = play(),
|
||||
contentAlignment = contentAlignment,
|
||||
content = content,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue