Skip to content

Instantly share code, notes, and snippets.

@cp-radhika-s
Created June 15, 2022 10:21
Show Gist options
  • Save cp-radhika-s/1141825386bc6d29b71a984fe34543aa to your computer and use it in GitHub Desktop.
Save cp-radhika-s/1141825386bc6d29b71a984fe34543aa to your computer and use it in GitHub Desktop.
@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