codelab-android-compose icon indicating copy to clipboard operation
codelab-android-compose copied to clipboard

[Navigation CodeLab] Account type is not Changing and navigating to Overview Screen

Open amandeepcodes opened this issue 2 years ago • 1 comments

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.

navigation issue

amandeepcodes avatar Aug 15 '23 05:08 amandeepcodes

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.

remain-maomao avatar Jun 12 '24 03:06 remain-maomao

Added temporary fix for default destination until type safe args are added to this codelab and we can use the new hasRoute API

simona-anomis avatar Dec 09 '24 17:12 simona-anomis