Refine RollingNumber to animate negative when fixed length

This commit is contained in:
Dude so hot authored and renovate[bot] committed 2024-11-17 18:59:14 +08:00
1 parent 8b6c358266
commit ccc7d467c2
1 file changed
+7 -1
@@ -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))
}
}
}
}