Skip to content

[WIP] Nav3 migration with deeplink updates#1655

Open
dturner wants to merge 3 commits intomainfrom
dt/nav3-migration
Open

[WIP] Nav3 migration with deeplink updates#1655
dturner wants to merge 3 commits intomainfrom
dt/nav3-migration

Conversation

@dturner
Copy link
Collaborator

@dturner dturner commented Feb 25, 2026

No description provided.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @dturner, 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 undertakes a significant refactoring of the JetNews application's navigation architecture. It transitions the app to use the experimental Nav3 library, which brings a new paradigm for handling navigation state and screen composition. This migration also includes a robust deep linking mechanism, allowing external links to directly access specific content within the application, improving user experience and external integration.

Highlights

  • Nav3 Migration: The application's navigation system has been migrated from the traditional Compose Navigation to the new Nav3 library, introducing a more declarative and type-safe approach to managing navigation state.
  • Deep Link Updates: Enhanced deep linking capabilities have been implemented, allowing the application to handle incoming URIs and navigate directly to specific content using serializable NavKeys.
  • Kotlin Serialization Integration: Kotlin Serialization has been integrated to facilitate the serialization and deserialization of NavKey objects, which are crucial for managing navigation state and deep link parameters.

🧠 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
  • JetNews/app/build.gradle.kts
    • Added Kotlin Serialization plugin and core library dependency.
    • Included new Nav3-related dependencies: androidx.lifecycle.viewmodel.navigation3 and androidx.navigation3.ui.
    • Updated the version reference for kotlinx-serialization.
  • JetNews/app/src/main/AndroidManifest.xml
    • Added a new intent filter to support deep linking to the home screen with an optional postId parameter.
  • JetNews/app/src/main/java/com/example/jetnews/ui/AppDrawer.kt
    • Updated the currentRoute parameter to currentKey of type NavKey.
    • Modified the selection logic for navigation items to correctly use NavKey instances.
  • JetNews/app/src/main/java/com/example/jetnews/ui/JetnewsApp.kt
    • Removed the usage of NavController and JetnewsNavigationActions.
    • Introduced NavigationState and Navigator classes for managing Nav3 navigation.
    • Updated AppDrawer and AppNavRail to consume currentKey and Navigator functions.
    • Replaced JetnewsNavGraph with JetnewsNavDisplay for screen composition.
    • Added a deepLinkKey parameter to the JetnewsApp composable to handle initial deep links.
  • JetNews/app/src/main/java/com/example/jetnews/ui/JetnewsNavGraph.kt
    • Removed the file, as its functionality has been replaced by the new Nav3 implementation.
  • JetNews/app/src/main/java/com/example/jetnews/ui/JetnewsNavigation.kt
    • Removed the file, as its contents have been superseded by the new JetnewsNavigation.kt within the navigation package.
  • JetNews/app/src/main/java/com/example/jetnews/ui/MainActivity.kt
    • Imported the toNavKey extension function for Intent.
    • Passed the deepLinkKey obtained from the incoming Intent to the JetnewsApp.
  • JetNews/app/src/main/java/com/example/jetnews/ui/components/AppNavRail.kt
    • Updated the currentRoute parameter to currentKey of type NavKey.
    • Modified the selection logic for navigation items to correctly use NavKey instances.
  • JetNews/app/src/main/java/com/example/jetnews/ui/navigation/JetnewsNavDisplay.kt
    • Added a new file implementing the NavDisplay composable, which serves as the central point for displaying navigation entries based on the NavigationState.
  • JetNews/app/src/main/java/com/example/jetnews/ui/navigation/JetnewsNavigation.kt
    • Added a new file defining the DeepLinkable interface, HomeKey, and InterestsKey as serializable NavKeys.
    • Implemented rememberNavigationState for managing the navigation back stack and Navigator for handling navigation actions.
    • Provided the toNavKey extension function for Intent to convert deep link URIs into NavKey objects.
  • JetNews/app/src/main/java/com/example/jetnews/ui/navigation/deeplinks/DeepLinkMatcher.kt
    • Added a new file containing the core logic for matching an incoming Uri against defined DeepLinkPatterns and extracting relevant arguments.
  • JetNews/app/src/main/java/com/example/jetnews/ui/navigation/deeplinks/DeepLinkPattern.kt
    • Added a new file responsible for parsing and storing metadata about deep link URI patterns, including identifying path and query arguments and their respective type parsers.
  • JetNews/app/src/main/java/com/example/jetnews/ui/navigation/deeplinks/DeepLinkRequest.kt
    • Added a new file providing a utility class for representing and parsing requested deep link URIs, including an extension property for query parameters.
  • JetNews/app/src/main/java/com/example/jetnews/ui/navigation/deeplinks/KeyDecoder.kt
    • Added a new file implementing a custom AbstractDecoder for Kotlin Serialization, specifically designed to decode arguments into NavKey instances.
  • JetNews/gradle/libs.versions.toml
    • Updated dependency versions and added new library entries for Nav3 and Kotlin Serialization.
Activity
  • The pull request is currently marked as 'Work In Progress' (WIP), indicating that the author is still actively developing and refining the changes.
  • No specific review comments or approvals have been recorded yet, consistent with its WIP status.
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.

Copy link
Contributor

@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

This pull request migrates the app's navigation from Navigation-Compose to the new Nav3 library, including updates to deep linking. The changes are extensive, touching dependency management, AndroidManifest, and core navigation logic. While the migration is well-underway, I've identified a critical issue in the new deep link handling that could cause crashes, a high-severity issue with inconsistent navigation logic for top-level destinations, and a medium-severity suggestion to clean up unused dependencies. Addressing these points will improve the robustness and correctness of the new navigation implementation.

Comment on lines +54 to +64
data.queryParametersMap.forEach { query ->
val queryName = query.key
val queryValue = query.value
val queryStringParser = pattern.queryValueParsers[queryName] ?: error("Could not get parser for query with name: $queryName")
if (queryValue == null){
error("Query value: $queryValue was null")
} else {
val queryParsedValue = queryStringParser.invoke(queryValue)
args[queryName] = queryParsedValue
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The current implementation for matching query parameters will cause the app to crash if the incoming deep link URI contains any query parameters not explicitly defined in the DeepLinkPattern (e.g., analytics parameters like utm_source). This is because it iterates over all parameters from the incoming URI and calls error() for any unknown ones.

The logic should be inverted: iterate over the expected parameters defined in pattern.queryValueParsers and attempt to find their values in the incoming URI. This makes the matching more robust by ignoring extraneous parameters.

        pattern.queryValueParsers.forEach { (queryName, parser) ->
            data.getQueryParameter(queryName)?.let { queryValue ->
                val queryParsedValue = parser.invoke(queryValue)
                args[queryName] = queryParsedValue
            }
        }

Comment on lines +114 to +117
fun toInterests() {
if (state.currentKey == InterestsKey) return
state.currentKeys.add(InterestsKey)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The navigation logic for toInterests is inconsistent with toHome. While toHome clears the navigation stack to switch to the home tab (which is typical for top-level destinations in a drawer or bottom bar), toInterests simply pushes the destination onto the current stack.

This creates an inconsistent user experience and back stack management. For a top-level destination like 'Interests', the behavior should be similar to 'Home', replacing the stack to perform a tab switch.

    fun toInterests() {
        if (state.currentKey == InterestsKey) return

        state.currentKeys.clear()
        state.currentKeys.add(InterestsKey)
        state.backStacks[InterestsKey::class.toString()]?.apply {
            if (isEmpty()) {
                add(InterestsKey)
            }
        }
    }

implementation(libs.androidx.lifecycle.viewModelCompose)
implementation(libs.androidx.lifecycle.runtime.compose)
implementation(libs.androidx.lifecycle.viewmodel.navigation3)
implementation(libs.androidx.navigation.compose)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

With the migration to Nav3, it appears the navigation-compose library is no longer used. The previous usages like NavHost, rememberNavController, and currentBackStackEntryAsState have been replaced with Nav3 equivalents. It's good practice to remove unused dependencies to keep the project clean and reduce the app size.

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