Luis Daivid
04/28/2021, 6:50 AMAlbert Chang
04/28/2021, 7:19 AMval circleSize = remember { Animatable(initialValue = 100f) }
val xCoordinate = remember { Animatable(initialValue = 100f) }
val scope = rememberCoroutineScope()
Button(
onClick = {
scope.launch {
circleSize.animateTo(
targetValue = 200f,
animationSpec = tween(durationMillis = 3000)
)
xCoordinate.animateTo(
targetValue = 200f,
animationSpec = tween(durationMillis = 3000)
)
circleSize.animateTo(
targetValue = 100f,
animationSpec = tween(durationMillis = 3000)
)
}
}
) {
Text(text = "Animate")
}
Luis Daivid
04/28/2021, 8:30 AMLuis Daivid
04/28/2021, 8:40 AMAlbert Chang
04/28/2021, 8:48 AMLuis Daivid
04/28/2021, 8:49 AMZach Klippenstein (he/him) [MOD]
04/28/2021, 2:14 PMLuis Daivid
04/29/2021, 1:05 AMLuis Daivid
04/29/2021, 1:06 AMval circleSize = remember { Animatable(initialValue = 0f) }
val xCoordinate = remember { Animatable(initialValue = -25f) }
suspend fun startAnimation() {
circleSize.animateTo(
targetValue = 10f,
animationSpec = tween(durationMillis = 700),
)
xCoordinate.animateTo(
targetValue = 25f,
animationSpec = tween(durationMillis = 2100, easing = LinearEasing)
)
circleSize.animateTo(
targetValue = 0f,
animationSpec = tween(durationMillis = 700, easing = LinearEasing)
)
xCoordinate.snapTo(-25f)
}
LaunchedEffect(key1 = true) {
delay(initialDelay)
while (true) {
startAnimation()
}
}
Box(
modifier = modifier
.offset(x = xCoordinate.value.dp)
.clip(CircleShape)
.background(color)
.size(circleSize.value.dp),
)
Luis Daivid
04/29/2021, 1:08 AMAlbert Chang
04/29/2021, 5:51 AMLuis Daivid
04/29/2021, 5:57 AMLuis Daivid
04/29/2021, 5:57 AM@Composable
fun LoadingB(modifier: Modifier = Modifier) {
Box(modifier = modifier) {
Circle(color = Color.Green, initialDelay = 0L)
Circle(color = Color.Red, initialDelay = 700L)
Circle(color = Color.Cyan, initialDelay = 1400L)
Circle(color = Color.Magenta, initialDelay = 2100L)
}
}
@Composable
private fun Circle(modifier: Modifier = Modifier, color: Color, initialDelay: Long) {
val circleSize = remember { Animatable(initialValue = 0f) }
val xCoordinate = remember { Animatable(initialValue = -25f) }
suspend fun startAnimation() {
circleSize.animateTo(
targetValue = 10f,
animationSpec = tween(durationMillis = 700, easing = LinearEasing),
)
xCoordinate.animateTo(
targetValue = 25f,
animationSpec = tween(durationMillis = 1000, easing = LinearEasing)
)
circleSize.animateTo(
targetValue = 0f,
animationSpec = tween(durationMillis = 700, easing = LinearEasing)
)
xCoordinate.snapTo(-25f)
}
LaunchedEffect(key1 = true) {
delay(initialDelay)
while (true) {
startAnimation()
}
}
Box(
modifier = modifier
.offset(x = xCoordinate.value.dp)
.clip(CircleShape)
.background(color)
.size(circleSize.value.dp),
)
}
Albert Chang
04/29/2021, 6:53 AM