Skip to content

Conversation

@doromaraujo
Copy link
Collaborator

@doromaraujo doromaraujo commented Jan 20, 2026

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

  • Bug Fixes
    • Improved navigation handling to respect the navigation system's handled status, reducing unnecessary screen reloads and better preserving user state when switching destinations.
    • Ensures the navigation drawer closes correctly after selection while honoring whether the destination action was processed.

✏️ Tip: You can customize this high-level summary in your review settings.

When tapping in a given option in Navigation
Drawer multiple times
Copilot AI review requested due to automatic review settings January 20, 2026 21:01
@coderabbitai
Copy link

coderabbitai bot commented Jan 20, 2026

Note

Other AI code review bot(s) detected

CodeRabbit 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.

📝 Walkthrough

Walkthrough

MainActivity's navigation item handling now delegates to NavigationUI.onNavDestinationSelected(item, navController) and returns its boolean result; the navigation drawer is still closed after selection.

Changes

Cohort / File(s) Summary
Navigation Refactor
app/src/main/java/io/netbird/client/MainActivity.java
In onNavigationItemSelected, replaced direct navController.navigate(id) with NavigationUI.onNavDestinationSelected(item, navController) and return its isHandled boolean. Drawer close behavior remains unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hopped through code at night,

Found a route that felt more right,
I nudged the nav to ask UI's say,
It told me if the route should play,
Drawer shut, I twitched my nose—hooray! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Keep fragments from inflating repeatedly' directly aligns with the PR's main objective of preventing repeated fragment inflations when the same drawer option is tapped.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@doromaraujo doromaraujo requested a review from pappz January 20, 2026 21:03
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants