Keep fragments from inflating repeatedly#131
Conversation
When tapping in a given option in Navigation Drawer multiple times
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. 📝 WalkthroughWalkthroughMainActivity's navigation item handling now delegates to Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where the NavigationDrawer inflates fragments repeatedly when users tap navigation options multiple times. The solution switches from directly calling navController.navigate(id) to using NavigationUI.onNavDestinationSelected(), which automatically handles launchSingleTop behavior and preserves fragment state.
Changes:
- Replaced direct navigation call with
NavigationUI.onNavDestinationSelected()to prevent repeated fragment inflation - Added explanatory comments describing the fix
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@app/src/main/java/io/netbird/client/MainActivity.java`:
- Around line 320-324: In MainActivity (the menu selection handler where
NavigationUI.onNavDestinationSelected(item, navController) is called), capture
the boolean result returned by NavigationUI into a local variable, call
binding.drawerLayout.closeDrawers(), and return that captured boolean instead of
unconditionally returning false so the method returns whether the navigation was
handled; update the method that contains this logic (the nav item selection
handler) to use the result from NavigationUI.onNavDestinationSelected(...) as
the return value.
Indicating if the NavController handled navigation to the fragment successfully
There is a bug on NavigationDrawer where if an user taps a given option multiple times, fragments will be inflated repeatedly.
This PR changes the way the fragments are inflated so that each fragment is inflated only once.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.