Mohamed Ibrahim
07/31/2021, 11:40 PMval current = LocalConfiguration.current
val screenWidth = current.screenWidthDp * 1f
val screenHeight = current.screenHeightDp * 1f
val radius = 300f
val xOffset = remember {
Animatable(0f)
}
LaunchedEffect(xOffset) {
xOffset.animateTo(radius,
animationSpec = infiniteRepeatable(
repeatMode = RepeatMode.Reverse,
animation = tween(durationMillis = 3000, easing = LinearEasing)
))
}
Canvas(modifier = Modifier
.fillMaxSize()
.background(
if (isSystemInDarkTheme()) Color.DarkGray else Color.LightGray
)) {
val canvasWidth = size.width
val canvasHeight = size.height
withTransform({
}) {
drawCircle(
color = Color.Blue,
center = Offset(canvasWidth / 2, y = canvasHeight / 2),
radius = radius
)
}
}
So I’ve this code and I want to animate this circle for example moving horizontally from edge to edge, how animate this offset value