microsoft / surface-duo-compose-sdk

This repo contains components built with Jetpack Compose for the Microsoft Surface Duo.
MIT License
74 stars 2 forks source link

TwoPaneLayoutNav can find route for pane1 but not for pane2 #56

Closed tscholze closed 1 year ago

tscholze commented 1 year ago

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 tutorial, 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!

Papes96 commented 1 year ago

I had the same error, make sure you are importing composable from: import com.microsoft.device.dualscreen.twopanelayout.twopanelayoutnav.composable and not from: import androidx.navigation.compose.composable

khalp commented 1 year ago

Hi @tscholze, thanks for continuing to use our SDK and providing feedback 😄

And thank you @Papes96 for the tip, yes you definitely want to make sure you're importing the correct composable definition so all routes are added to the twoPaneBackStack. I would also recommend that you call navigateTo instead of navigate in your navigateToRegion function so it will work in both single and dual screen mode!

Tobi, if that doesn't fix your problem, please let me know and provide the code for RegionsScreen and RegionScreen. That way, I can help you debug the issue some more!

tscholze commented 1 year ago

@Papes96 thanks, that was the fix! <3 @khalp I'm now a step further into the process to adopting the app to the surface duo.

I may come back to the technet community with another question :)