Created
June 15, 2022 10:19
-
-
Save cp-radhika-s/b0920ec0d27dcb04816cb9ef226cec7b 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 SpringAnimation() { | |
val scope = rememberCoroutineScope() | |
val offset = remember { Animatable(Offset(0f, 0f), Offset.VectorConverter) } | |
val offset2 = remember { Animatable(Offset(0f, 0f), Offset.VectorConverter) } | |
val offset3 = remember { Animatable(Offset(0f, 0f), Offset.VectorConverter) } | |
Column( | |
modifier = Modifier | |
.fillMaxSize() | |
.padding(20.dp), | |
verticalArrangement = Arrangement.Center, | |
horizontalAlignment = Alignment.CenterHorizontally | |
) { | |
Circle(modifier = Modifier | |
.offset { offset.value.toIntOffset() } | |
.background(ThemeColor, CircleShape) | |
.pointerInput(Unit) { | |
detectDragGestures { change, dragAmount -> | |
change.consumeAllChanges() | |
scope.launch { | |
offset.animateTo( | |
offset.value + change.position, spring( | |
dampingRatio = Spring.DampingRatioLowBouncy | |
) | |
) | |
} | |
scope.launch { | |
offset2.animateTo( | |
offset.value + change.position, spring( | |
dampingRatio = Spring.DampingRatioLowBouncy, | |
stiffness = 100f | |
) | |
) | |
} | |
scope.launch { | |
offset3.animateTo( | |
offset.value + change.position, spring( | |
dampingRatio = Spring.DampingRatioLowBouncy, | |
stiffness = StiffnessVeryLow | |
) | |
) | |
} | |
} | |
}) | |
Spacer(modifier = Modifier.height(30.dp)) | |
Circle(modifier = Modifier | |
.offset { offset2.value.toIntOffset() } | |
.background(Color.White.copy(0.8f), CircleShape)) | |
Spacer(modifier = Modifier.height(30.dp)) | |
Circle(modifier = Modifier | |
.offset { offset3.value.toIntOffset() } | |
.background(Color.White.copy(0.3f), CircleShape)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment