From ccc7d467c2e980f8adcc07d92ca8afb9a110456a Mon Sep 17 00:00:00 2001 From: Dude so hot Date: Sun, 17 Nov 2024 17:43:16 +0800 Subject: [PATCH] Refine RollingNumber to animate negative when fixed length --- .../kotlin/com/hippo/ehviewer/ui/main/RollingNumber.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/main/RollingNumber.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/main/RollingNumber.kt index 166077fc5..5b3f9cc83 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/main/RollingNumber.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/ui/main/RollingNumber.kt @@ -5,6 +5,7 @@ import androidx.compose.animation.core.updateTransition import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.offset import androidx.compose.foundation.layout.size import androidx.compose.foundation.lazy.LazyRow @@ -147,7 +148,7 @@ fun RollingNumber( reverseLayout = true, horizontalArrangement = Arrangement.Center, ) { - val max = length ?: with(transition) { max(currentState.length, targetState.length) } + val max = with(transition) { max(currentState.length, targetState.length) } items(max, key = { it }) { reversed -> val rotate by transition.animateOffset { str -> val len = str.length @@ -197,5 +198,10 @@ fun RollingNumber( ) } } + if (length != null) { + items(length - max - if (isNegative) 1 else 0) { + Spacer(Modifier.size(size)) + } + } } }