feat: GIF 切换添加入场缩放弹性动画

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
xfy 2026-05-19 16:17:09 +08:00
parent ce64526125
commit 1395e9666f

View File

@ -1,8 +1,15 @@
package plus.rua.project.ui package plus.rua.project.ui
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.FastOutSlowInEasing
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.spring
import androidx.compose.animation.core.tween
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.graphicsLayer
import com.github.panpf.sketch.AsyncImage import com.github.panpf.sketch.AsyncImage
import plus.rua.project.getGifUri import plus.rua.project.getGifUri
@ -26,9 +33,28 @@ fun AnimatedGif(
) { ) {
val gifFile = remember(seed) { GIF_FILES.random() } val gifFile = remember(seed) { GIF_FILES.random() }
val uri = remember(gifFile) { getGifUri(gifFile) } val uri = remember(gifFile) { getGifUri(gifFile) }
val scale = remember { Animatable(0f) }
LaunchedEffect(seed) {
scale.snapTo(0f)
scale.animateTo(
targetValue = 1.1f,
animationSpec = tween(250, easing = FastOutSlowInEasing),
)
scale.animateTo(
targetValue = 1f,
animationSpec = spring(dampingRatio = Spring.DampingRatioMediumBouncy),
)
}
AsyncImage( AsyncImage(
uri = uri, uri = uri,
contentDescription = contentDescription, contentDescription = contentDescription,
modifier = modifier, modifier = modifier
.graphicsLayer {
scaleX = scale.value
scaleY = scale.value
alpha = scale.value.coerceIn(0f, 1f)
},
) )
} }