Skip to content

Instantly share code, notes, and snippets.

@EmmanuelGuther
Created November 7, 2021 09:43
Show Gist options
  • Select an option

  • Save EmmanuelGuther/ada90a078b3ddcd35f24dbf024d4f31b to your computer and use it in GitHub Desktop.

Select an option

Save EmmanuelGuther/ada90a078b3ddcd35f24dbf024d4f31b to your computer and use it in GitHub Desktop.
@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