Skip to content

Comments

Fix incorrect back navigation to ForYou instead of Topic screen (#1866)#2072

Open
Amir-yazdanmanesh wants to merge 1 commit intoandroid:mainfrom
Amir-yazdanmanesh:fix/incorrect-back-navigation-1866
Open

Fix incorrect back navigation to ForYou instead of Topic screen (#1866)#2072
Amir-yazdanmanesh wants to merge 1 commit intoandroid:mainfrom
Amir-yazdanmanesh:fix/incorrect-back-navigation-1866

Conversation

@Amir-yazdanmanesh
Copy link

  • Fix cross-tab back navigation losing sub-stack state — pressing back after switching tabs now correctly returns to the previously viewed sub-page (e.g. Topic detail)
    instead of the tab root (ForYou)
  • Change toEntries() to only pass the current tab's entries to NavDisplay, preventing ListDetailSceneStrategy from mis-rendering after cross-tab transitions
  • Add BackHandler for tab-level back navigation since NavDisplay now only sees within-tab entries

Root Cause

toEntries() in NavigationState.kt flattened all tab sub-stacks into a single entries list. When pressing back from another tab, entries transitioned from [ForYouEntry,
TopicEntry, BookmarksEntry] to [ForYouEntry, TopicEntry], but ListDetailSceneStrategy failed to re-render the detail pane correctly because ForYouEntry lacks pane
metadata while TopicEntry has detailPane() metadata.

Test plan

  • Unit test added: testSubStackPreservedAfterTabSwitchAndBack in NavigatorTest.kt
  • Un-ignored navigationBar_multipleBackStackInterests instrumented test
  • Added navigationBar_backFromTabPreservesSubStack instrumented test with system back button
  • Manual verification: ForYou → tap topic → switch to Bookmarks → press back → Topic screen should be visible

Fixes #1866

@gemini-code-assist
Copy link

Summary of Changes

Hello @Amir-yazdanmanesh, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical navigation bug where the application would lose its sub-stack state when navigating back after switching between tabs. The changes ensure that the back button correctly restores the user to their previous sub-page within a tab, rather than resetting to the tab's root. This significantly improves the user experience by maintaining expected navigation behavior across the application's tabbed interface.

Highlights

  • Cross-Tab Back Navigation Fix: Resolved an issue where pressing back after switching tabs would incorrectly return to the tab root (ForYou) instead of the previously viewed sub-page (e.g., Topic detail), ensuring sub-stack state is preserved.
  • Navigation Entry Filtering: Modified the toEntries() function to pass only the current tab's navigation entries to NavDisplay, which prevents ListDetailSceneStrategy from mis-rendering after cross-tab transitions.
  • BackHandler Implementation: Introduced a BackHandler for tab-level back navigation, as NavDisplay now only processes entries within the active tab.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • app/src/androidTest/kotlin/com/google/samples/apps/nowinandroid/ui/NavigationTest.kt
    • Un-ignored navigationBar_multipleBackStackInterests test.
    • Added navigationBar_backFromTabPreservesSubStack instrumented test.
  • app/src/main/kotlin/com/google/samples/apps/nowinandroid/ui/NiaApp.kt
    • Imported BackHandler composable.
    • Added a BackHandler to enable correct tab-level back navigation.
  • core/designsystem/src/main/kotlin/com/google/samples/apps/nowinandroid/core/designsystem/component/scrollbar/AppScrollbars.kt
    • Removed SuppressLint import.
    • Removed @SuppressLint("ComposableModifierFactory") annotation.
  • core/navigation/src/main/kotlin/com/google/samples/apps/nowinandroid/core/navigation/NavigationState.kt
    • Modified toEntries function to only provide entries for the current top-level tab.
  • core/navigation/src/test/kotlin/com/google/samples/apps/nowinandroid/core/navigation/NavigatorTest.kt
    • Added testSubStackPreservedAfterTabSwitchAndBack unit test.
Activity
  • Added a new unit test, testSubStackPreservedAfterTabSwitchAndBack, to verify sub-stack preservation.
  • Un-ignored the existing navigationBar_multipleBackStackInterests instrumented test.
  • Introduced a new instrumented test, navigationBar_backFromTabPreservesSubStack, to validate system back button behavior.
  • Manual verification steps were outlined to confirm the fix for cross-tab back navigation.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@Amir-yazdanmanesh Amir-yazdanmanesh force-pushed the fix/incorrect-back-navigation-1866 branch from dd10f8c to a61e4ee Compare February 19, 2026 15:28
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request successfully addresses the issue where back navigation from a sub-stack would incorrectly return to the app root instead of preserving the previous tab's state. The solution of isolating entries per tab in toEntries() and adding a BackHandler for cross-tab navigation is a solid architectural improvement that also resolves rendering issues with ListDetailSceneStrategy. The added unit and instrumented tests provide good coverage for the fix.

…oid#1866)

When navigating ForYou → Topic → switch tab → back, the user landed on
the ForYou screen instead of the Topic screen. The root cause was that
toEntries() flattened all tab sub-stacks into a single entries list,
causing ListDetailSceneStrategy to mis-render after cross-tab back.

- Change toEntries() to only return entries from the current tab's
  sub-stack while still decorating all stacks for state preservation
- Add BackHandler for cross-tab back navigation since NavDisplay now
  only sees within-tab entries
- Add unit test for the sub-stack preservation scenario
- Un-ignore navigationBar_multipleBackStackInterests test
- Add back-button variant instrumented test
@Amir-yazdanmanesh Amir-yazdanmanesh force-pushed the fix/incorrect-back-navigation-1866 branch from a61e4ee to 88c9bbd Compare February 19, 2026 15:36
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.

[Bug]: Incorrect back navigation to For you

1 participant