kotlinuser-interfaceviewcompose-multiplatformcompose-desktop

What is the principle of switching views in Compose Desktop?


When I want to switch views in Compose Desktop how should I do this? Should I make like a Column holding multiple views and switch one invisible and the other one visible (perhaps with an animation) or do I reassign some property holding only one view?

I know there are such libraries as Decompose, but I'd like to understand the basics for my simple app with just two or three different views.


Solution

  • It's the same an in Jetpack Compose.

    As said in the comments, you just use simple if() else statements and show your desired composables (or even entire screens) depending on the conditions you choose.

    var isHigh by remember { mutableStateOf(true) }
    if (isHigh) {
        Text("So high...")
    } else {
        MyOtherComposable()
    }
    
    @Composable
    fun MyOtherComposable() {
       // ...
    }
    

    And, now, the navigation library is supported by Compose Multiplatform (desktop and others) too.