voyager icon indicating copy to clipboard operation
voyager copied to clipboard

Can't pop root in Compose for Desktop

Open MJavoso opened this issue 1 year ago • 0 comments

I am not sure if this is intentional or not, but in Compose for Desktop, I have a little set up for testing:

private data class Window1(
    val applicationScope: ApplicationScope
) : Screen {
    @OptIn(InternalVoyagerApi::class)
    @Composable
    override fun Content() {
        val navigator = LocalNavigator.currentOrThrow
        Window(onCloseRequest = applicationScope::exitApplication) {
            Column(modifier = Modifier.fillMaxSize()) {
                Text("Ventana 1\nNivel: ${navigator.level}, tamaño: ${navigator.size}")

                Button(onClick = {
                    //navigator.dispose(this@Window1)
                    navigator.popAll() // None worked
                }) {
                    Text("Quitar tope")
                }

                Button(
                    onClick = {
                        navigator.push(Window2(applicationScope, onDispose = { navigator.pop() }))
                    }
                ) {
                    Text("Abrir ventana 2")
                }

                Button(
                    onClick = {
                        navigator.push(Window3(applicationScope, onDispose = { navigator.pop() }))
                    }
                ) {
                    Text("Abrir ventana 3")
                }
            }
        }
    }
}

Everything works fine except when I try to pop the root. I know that in this example I should be using the method provided in the application scope, but I think it would be nice to provide a custom logic on the Navigator composable if the stack gets emptied.

My problem is that in my own project, I need to travel from Window A to Window B, and I try to call navigator.pop() on Window A, but if I close Window B, it goes back to Window A because onCloseRequest of Window B calls navigator.pop() and succeeds, but the previous pop call failed because it is the root of the navigator.

MJavoso avatar Jun 20 '24 21:06 MJavoso