Nat Strangerweather
05/13/2021, 8:11 PMNat Strangerweather
05/13/2021, 8:11 PMNat Strangerweather
05/13/2021, 8:12 PMNat Strangerweather
05/13/2021, 8:12 PMval infiniteTransition = rememberInfiniteTransition()
val durationMillis = remember { mutableStateOf(10000) }
val positionState = infiniteTransition.animateFloat(
initialValue = 0f,
targetValue = 1f,
animationSpec = infiniteRepeatable(
animation = tween(
durationMillis = durationMillis.value,
easing = LinearEasing
)
)
)
Nat Strangerweather
05/13/2021, 8:20 PMlayout(constraints.maxWidth, constraints.maxHeight) {
var yPosition = 0
val xPosition = 0
val verticalAnimationPositioning =
(constraints.maxHeight - (constraints.maxHeight * positionState.value)).toInt()
placeables.forEachIndexed { index, placeable ->
if (index <= 6) {
placeable.placeRelative(x = xPosition, y = yPosition)
yPosition += placeable.height
} else if (index >= 7) {
placeable.placeRelative(
constraints.maxWidth - tileSize,
yPosition - placeable.height * 7 + verticalAnimationPositioning,
1f
)
yPosition += verticalAnimationPositioning
}
}
Nat Strangerweather
05/13/2021, 8:21 PMHere: else if (index >= 7) {
Nat Strangerweather
05/13/2021, 8:22 PMdurationMillis.value += 10000
Nat Strangerweather
05/13/2021, 8:22 PMDoris Liu
05/13/2021, 8:44 PMyPosition += verticalAnimationPositioning
This places the placeables (with index >= 7) verticalAnimationPositioning
apart, yet that number is changing due to the animation. Hence the perceived catch up. If you'd like to have the placeables a fixed distance apart, I'd do yPosition += someFixedIntValue
🙂Doris Liu
05/13/2021, 8:47 PMThe other question is do I need to use coroutines so the main thread does not get blocked?Do you mean coroutines for the animations? The infinite animations does a very lightweight setup before it starts, then it runs in an internally created
LaunchedEffect
. In other words, it won't block the main thread.Nat Strangerweather
05/13/2021, 8:54 PM