KotlinLeaner
04/19/2023, 3:31 PMPreview(showBackground = true)
@Composable
fun PulseAnimation() {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.fillMaxSize()
) {
val transition = rememberInfiniteTransition()
val duration = 3_000
val count = 3
val progress = List(3) {
transition.animateFloat(
initialValue = 0f,
targetValue = 1f,
animationSpec = InfiniteRepeatableSpec(
animation = tween(durationMillis = duration, easing = LinearEasing),
initialStartOffset = StartOffset(it * duration / count),
repeatMode = RepeatMode.Restart,
)
)
}
Canvas(modifier = Modifier.fillMaxHeight()) {
val radius = 40.dp.toPx() / 2f
drawLine(
color = Color.Black,
start = Offset(x = size.width / 2, y = 0F),
end = Offset(x = size.width / 2, y = size.height / 2),
strokeWidth = 2.dp.toPx(),
)
progress.forEach {
drawCircle(
color = Color.Magenta.copy(alpha = 1f - it.value),
radius = radius * it.value,
center = Offset(size.width, size.height / 2)
)
}
}
}
}