Created
May 31, 2022 08:39
-
-
Save dilrajsingh1997/a663ee6df44e76976adf7291d6db97db to your computer and use it in GitHub Desktop.
This file contains 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
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