Skip to content

Instantly share code, notes, and snippets.

@Farhandroid
Last active August 31, 2023 06:37
Show Gist options
  • Save Farhandroid/ba3771f6ca2b298da1b95d133d1b9d23 to your computer and use it in GitHub Desktop.
Save Farhandroid/ba3771f6ca2b298da1b95d133d1b9d23 to your computer and use it in GitHub Desktop.
@Composable
fun CustomAnimationExample() {
val offset = remember { Animatable(0f) }
val coroutineScope = rememberCoroutineScope()
var isUpwards by remember { mutableStateOf(true) }
Column {
Button(onClick = {
coroutineScope.launch {
val target = if (isUpwards) 300f else 0f
offset.animateTo(
targetValue = target,
animationSpec = tween(
durationMillis = 1000,
easing = LinearEasing
)
)
isUpwards = !isUpwards
}
}) {
Text("Move It!")
}
Box(
modifier = Modifier.offset(y = offset.value.dp)
) {
Text("I'm moving!")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment