Thread
#compose
    v

    Vladas

    11 months ago
    Is there any way for fillMaxSize to work with rotation. It works fine when view is a lot smaller than than device width and height but as it gets larger it starts to deform. I tried to do it with BoxWithConstraints and flip between width and height but it is still deforming when rotated.
    My code
    @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
                }
            )
        }
    }
    After rotation.
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    11 months ago
    Are you sure the constraints being passed to BoxWithConstraints are actually the full size of the screen?