Forum Discussion

tscholze's avatar
tscholze
Iron Contributor
Apr 01, 2023
Solved

Compose Jetpack TwoPaneLayoutNav can find route for pane1 but not for pane2

Hi team, 

long time no see but here I'm with another problem which is properly caused by not understanding the API.

 

I use the version:

implementation("com.microsoft.device.dualscreen:twopanelayout:1.0.1-alpha06")

 

My code

Based on the https://learn.microsoft.com/en-us/dual-screen/android/jetpack/compose/two-pane-layout, I tried to get my TwoPaneLayoutNav working.

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            val navController = rememberNavController()

            TwoPaneLayoutNav(
                navController = navController,
                singlePaneStartDestination = "regions",
                pane1StartDestination = "regions",
                pane2StartDestination = "regions"
            ) {
                composable("regions") {
                    RegionsScreen(
                        navigateToRegion = { id -> navController.navigate("regions/${id}")}
                    )
                }
                composable("regions/{id}") { backStackEntry ->
                    val id = backStackEntry.arguments?.getString("id")
                    RegionScreen(regionId = id ?: "A")
                }
            }
        }
    }
} 

 

The problem 

But as soon as I span the app across both screens, the app crashes with the following error:

java.lang.IllegalArgumentException: Invalid route regions, not present in list of routes []

I tried not just "regions" but "regions/a", too. Both does not work. If I introduce another path like "test" is also does not work. In single screen mode, everything works as expected.

 

Thanks for your help!

  • khalper 

    It was a false friend during import.

    Following tip fixed it: https://github.com/microsoft/surface-duo-compose-sdk/issues/56#issuecomment-1500713025 

     

    Papes96 Thanks for your help on GitHub!

3 Replies

  • tscholze's avatar
    tscholze
    Iron Contributor
    I created an issue 🙂 https://github.com/microsoft/surface-duo-compose-sdk/issues/56
    • khalper's avatar
      khalper
      Icon for Microsoft rankMicrosoft
      Thanks Tobias for the feedback! I'll continue the discussion in the Github issue.
      • tscholze's avatar
        tscholze
        Iron Contributor

        khalper 

        It was a false friend during import.

        Following tip fixed it: https://github.com/microsoft/surface-duo-compose-sdk/issues/56#issuecomment-1500713025 

         

        Papes96 Thanks for your help on GitHub!

Resources