Last active
August 31, 2023 06:37
-
-
Save Farhandroid/ba3771f6ca2b298da1b95d133d1b9d23 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 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