-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NavController keep two items selected when back is pressed #2634
Comments
Can confirm. Having the same issue here. The issue seems to happen whenever I do a manual nav controller navigate: findNavController().navigate(R.id.my_navigation_destination_id)
// Or
findNavController.navigateUp() My back button is overridden to have a custom behavior and uses the navigateUp() function. If I had to hazard a guess, it looks like the list/set of selected drawer items is only reset when selecting a new item (an item not belonging in the selected item list), and when you do a manual navigation, that reset doesn't happen (though the drawer seems to capture the navigate event correctly) |
My fast solution was override the setupWithNavController method from DrawerNavigationUI and force the update of itemadapter.itemList to keep only one selected item when onDestinationChanged is called. |
I've been trying to implement your quick fix, I've successfully been able to complement |
I created a function to deselect the items different of the last selected item (based on identifier).
And onDestinationChanged I call this function in the last line.
This gist has some changes that I made: https://gist.github.com/felipelindemberg/847ba3c3d67f2fabff482ee0910e1fdf My menu has PrimaryDrawerItem, ExpandableItem and NavigationDrawerItem. I had to update the listener to receive events when the primaryItem is clicked, but this is not related with the issue. I think that just adding this function to unselect the items will solve this issues. I need to check the behavior for select items that are not top level. Whether to keep any element selected in the menu. Today does not select. |
Sorry I did not follow this issue as close as I should have. Hopefully this did not cause major problems yet and the workaround is working? |
About this issue
This issue can be reproduced in the sample:
1 - Open the sample and select Nav Controller Drawer
2 - Click in "Go to fragment 1"
3 - Open the drawer and see two selected items
4 - Close the Drawer and press back button to back to home fragment
5 - Open the drawer and check that the items keep selected
Additional Info
Details
The text was updated successfully, but these errors were encountered: