Skip to content

Instantly share code, notes, and snippets.

@dilrajsingh1997
Created May 31, 2022 08:39
Show Gist options
  • Save dilrajsingh1997/a663ee6df44e76976adf7291d6db97db to your computer and use it in GitHub Desktop.
Save dilrajsingh1997/a663ee6df44e76976adf7291d6db97db 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
)
)
Canvas(
modifier = Modifier.offset {
IntOffset(x = 200, y = yOffset.toInt())
},
onDraw = {
drawContext.canvas.nativeCanvas.drawText(
text = "hi",
x = 0f,
y = 0f,
paint = TextPaint().apply {
color = Color.WHITE
textSize = 84f
}
)
}
)
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