Skip to content

Commit ac7a720

Browse files
committed
refactor(ui): simplify SimpleSpriteAnimator removing unnecessary CrossfadeAnimation
1 parent 082d698 commit ac7a720

1 file changed

Lines changed: 5 additions & 11 deletions

File tree

dynaquiz/composeApp/src/commonMain/kotlin/com/leanite/dynaquiz/core/ui/common/SimpleSpriteAnimator.kt

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package com.leanite.dynaquiz.core.ui.common
22

3-
import androidx.compose.animation.Crossfade
4-
import androidx.compose.animation.core.snap
53
import androidx.compose.foundation.Image
4+
import androidx.compose.foundation.layout.Box
65
import androidx.compose.runtime.Composable
76
import androidx.compose.runtime.LaunchedEffect
87
import androidx.compose.runtime.getValue
@@ -34,27 +33,22 @@ fun SimpleSpriteAnimator(
3433
) {
3534
var showActive by remember { mutableStateOf(false) }
3635

37-
LaunchedEffect(idle, active, shouldAnimate) {
36+
LaunchedEffect(shouldAnimate) {
3837
if (shouldAnimate) {
3938
while (true) {
40-
delay(idleDuration)
4139
showActive = true
4240
delay(activeDuration)
4341
showActive = false
42+
delay(idleDuration)
4443
}
4544
} else {
4645
showActive = false
4746
}
4847
}
4948

50-
Crossfade(
51-
targetState = showActive,
52-
animationSpec = snap(),
53-
modifier = modifier,
54-
label = "sprite-animator",
55-
) { isActive ->
49+
Box(modifier = modifier) {
5650
Image(
57-
painter = painterResource(if (isActive) active else idle),
51+
painter = painterResource(if (showActive) active else idle),
5852
contentDescription = contentDescription,
5953
)
6054
}

0 commit comments

Comments
 (0)