Created
November 7, 2021 09:43
-
-
Save EmmanuelGuther/ada90a078b3ddcd35f24dbf024d4f31b 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
| @Preview | |
| @Composable | |
| fun BikeScreen() { | |
| var bikeState by remember { mutableStateOf(BikePosition.Start) } | |
| // val offsetAnimation: Dp by animateDpAsState( | |
| // //get display size | |
| // if (bikeState == BikePosition.Start) (800).dp else (-100).dp, | |
| // ) | |
| val offsetX by animateDpAsState(targetValue = if (bikeState == BikePosition.Start) 5.dp else 300.dp, animationSpec = | |
| infiniteRepeatable(tween(3000),RepeatMode.Reverse)) | |
| Box( | |
| modifier = Modifier | |
| .fillMaxSize() | |
| ) { | |
| Image( | |
| painter = painterResource(R.drawable.ic_sun), | |
| contentDescription = null, | |
| modifier = Modifier | |
| .height(90.dp) | |
| .absoluteOffset(y = offsetX) | |
| ) | |
| Button( | |
| onClick = { | |
| bikeState = when (bikeState) { | |
| BikePosition.Start -> BikePosition.Finish | |
| BikePosition.Finish -> BikePosition.Start | |
| } | |
| }, modifier = Modifier | |
| .fillMaxSize() | |
| .wrapContentSize(align = Alignment.Center) | |
| ) { | |
| Text(text = "Start") | |
| } | |
| } | |
| } | |
| enum class BikePosition { | |
| Start, Finish | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment