Last active
July 12, 2022 10:32
-
-
Save cp-hardik-p/173c9dadbcbd3b56c1bc87988a90591d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun ChasingCircleAnimation(infiniteTransition: InfiniteTransition) { | |
val arcAngle1 by infiniteTransition.animateFloat( | |
initialValue = 0F, | |
targetValue = 180F, | |
animationSpec = infiniteRepeatable( | |
animation = tween(1000, easing = LinearEasing), | |
repeatMode = RepeatMode.Restart | |
) | |
) | |
val arcAngle2 by infiniteTransition.animateFloat( | |
initialValue = 180F, | |
targetValue = 360F, | |
animationSpec = infiniteRepeatable( | |
animation = tween(1000, easing = LinearEasing), | |
repeatMode = RepeatMode.Restart | |
) | |
) | |
val scaleCircles by infiniteTransition.animateFloat( | |
initialValue = 0.3f, | |
targetValue = 1f, | |
animationSpec = infiniteRepeatable( | |
animation = tween(2000), | |
repeatMode = RepeatMode.Reverse | |
) | |
) | |
Box( | |
Modifier | |
.padding(top = 28.dp) | |
.scale(scaleCircles) | |
) { | |
Box( | |
Modifier | |
.align(Alignment.Center) | |
.size(50.dp) | |
.background(Color.White, shape = CircleShape) | |
) { | |
Canvas(modifier = Modifier | |
.rotate(arcAngle1) | |
.align(Alignment.Center) | |
.size(30.dp), onDraw = { | |
drawArc( | |
color = | |
Color.Black, | |
style = Stroke( | |
width = 10f, | |
cap = StrokeCap.Round | |
), | |
startAngle = 180f, | |
sweepAngle = 288f, | |
useCenter = false | |
) | |
}) | |
} | |
Box(Modifier.rotate(arcAngle2)) { | |
Canvas(modifier = Modifier | |
.rotate(180f) | |
.align(Alignment.Center) | |
.size(100.dp), onDraw = { | |
drawArc( | |
color = | |
Color.Blue, | |
style = Stroke( | |
width = 10f, | |
cap = StrokeCap.Round | |
), | |
startAngle = 180f, | |
sweepAngle = 288f, | |
useCenter = false | |
) | |
} | |
) | |
} | |
Canvas(modifier = Modifier | |
.rotate(arcAngle2) | |
.align(Alignment.Center) | |
.size(60.dp), onDraw = { | |
drawArc( | |
color = | |
Color.Blue, | |
style = Stroke( | |
width = 10f, | |
cap = StrokeCap.Round | |
), | |
startAngle = 180f, | |
sweepAngle = 288f, | |
useCenter = false | |
) | |
} | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment