Vladas
09/30/2021, 9:24 AM@Composable
private fun RotatableImage() {
var rotated by remember { mutableStateOf(false) }
val degrees = remember(rotated) {
if (rotated) 90f
else 0f
}
BoxWithConstraints(
modifier = Modifier
.fillMaxSize()
.background(Color.Gray), contentAlignment = Alignment.Center
) {
val width: Dp
val height: Dp
if (rotated) {
width = maxHeight
height = maxWidth
} else {
width = maxWidth
height = maxHeight
}
//I use Image instead of Box
Box(modifier = Modifier
.rotate(degrees)
.background(Color.Red)
.width(width)
.height(height)
// .width(width/3) //this works but it is too small
// .height(height/3)
.clickable {
rotated = !rotated
}
)
}
}
Zach Klippenstein (he/him) [MOD]
09/30/2021, 4:40 PM