Skip to content

Instantly share code, notes, and snippets.

@dilrajsingh1997
Last active May 31, 2022 08:31
Show Gist options
  • Save dilrajsingh1997/ae87af611c3a35c9156a9966631c1cb8 to your computer and use it in GitHub Desktop.
Save dilrajsingh1997/ae87af611c3a35c9156a9966631c1cb8 to your computer and use it in GitHub Desktop.
val height = with(LocalDensity.current) {
LocalConfiguration.current.screenHeightDp.dp.toPx()
}
val position = remember {
mutableStateOf(1)
}
val yOffset by animateFloatAsState(
targetValue = if (position.value == 0) {
height / 2
} else {
height
},
animationSpec = tween(
durationMillis = 3000,
easing = FastOutSlowInEasing
)
)
Text(
text = "hi",
modifier = Modifier.offset {
IntOffset(x = 200, y = yOffset.toInt())
}
)
Button(
onClick = {
position.value = (position.value + 1) % 2
},
modifier = Modifier.align(Alignment.BottomCenter)
) {
Text(text = "Animate")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment