Created
June 15, 2022 10:21
-
-
Save cp-radhika-s/1141825386bc6d29b71a984fe34543aa to your computer and use it in GitHub Desktop.
This file contains hidden or 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 FlingAnimation() { | |
val offset = remember { Animatable(Offset(0f, 0f), Offset.VectorConverter) } | |
Box( | |
modifier = Modifier | |
.fillMaxSize() | |
.pointerInput(Unit) { | |
coroutineScope { | |
while (true) { | |
val position = awaitPointerEventScope { | |
awaitFirstDown().position | |
} | |
launch { | |
offset.animateTo( | |
position, spring( | |
dampingRatio = Spring.DampingRatioLowBouncy, | |
stiffness = StiffnessVeryLow | |
) | |
) | |
} | |
} | |
} | |
} | |
) { | |
Circle(modifier = Modifier | |
.offset { offset.value.toIntOffset() } | |
.background(ThemeColor, CircleShape)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment