I want to change the layout depending on the orien...
# compose
t
I want to change the layout depending on the orientation. I created a composable which does the this:
Copy code
@Composable
fun CustomLayout(
    child1: @Composable () -> Unit = {},
    child2: @Composable () -> Unit = {},
) {
    val cfg = LocalConfiguration.current
    val isLandscape by remember(cfg) { derivedStateOf { cfg.orientation == Configuration.ORIENTATION_LANDSCAPE } }
    if (isLandscape) {
        Row() {
            child1()
            child2()
        }
    } else {
        Column() {
            child1()
            child2()
        }
    }
}
Now my problem is that when the layout changes child1 and child2 getting destroyed and new composables are created. Normally that does not matter but in my case i do have a AndroidView inside of the child and do not want that the view is recreated when the layout changes. Is there any trick to avoid recreation of the composables in this case?
t
Wow thank you very much for the fast answer. Works 100% 🦜