[Navigation CodeLab] Account type is not Changing and navigating to Overview Screen
When I am clicking on any AccountType it is showing only the first clicked Account Type in Navigation and also when it is showing Single Account screen, Navigation moves to Overview Tab.
when I am following the this codelab, I found the same problem you mentioned above, to confirm this problem, I downloaded the end version code, and the end version code indeed had the bug, so I sloved it.
the problem occurred because this line of code.
val currentScreen = rallyTabRowScreens.find { it.route == currentDestination?.route } ?: Overview
for a quick answer, just replace it with this line:
val currentScreen = rallyTabRowScreens.find { it.route == currentDestination?.route || (it == Accounts && currentDestination?.route?.startsWith( SingleAccount.route ) == true) } ?: Overview
for a deep explanation, continue to read. when you navigate the single_account, actually this page's route can be one of the following:
- single_account/Checking
- single_account/Home Savings
- single_account/Car Savings
of course, all of them can not match the tab routes: overview, accounts, bills, so the original code fall back to the overview page.
to solve this, you just need to add a condition to say that if the current route beyond the tab routes, but it starts with single_account, then the accounts tab should be highlighted.
hope this can answer your question.
Added temporary fix for default destination until type safe args are added to this codelab and we can use the new hasRoute API