Skip to content

Migrate recipes to use the Metadata DSL#233

Draft
bsagmoe wants to merge 4 commits intomainfrom
bsagmoe/metadata-dsl
Draft

Migrate recipes to use the Metadata DSL#233
bsagmoe wants to merge 4 commits intomainfrom
bsagmoe/metadata-dsl

Conversation

@bsagmoe
Copy link
Contributor

@bsagmoe bsagmoe commented Feb 13, 2026

No description provided.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @bsagmoe, 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 refactors the navigation recipes to align with the new Metadata DSL, which offers a more structured and type-safe approach to defining navigation entry metadata. By leveraging NavMetadataKey and MetadataScope extension functions, the changes improve code readability, maintainability, and reduce the likelihood of errors associated with string-based map keys. This migration ensures the recipes demonstrate best practices with the updated navigation library.

Highlights

  • Metadata DSL Adoption: Migrated various navigation recipes (AnimatedActivity, BottomSheetActivity, ListDetailActivity, TwoPaneActivity, SharedViewModelActivity) to utilize the new metadata DSL for defining navigation entry metadata, replacing direct Map constructions.
  • Type-Safe Metadata Keys: Introduced NavMetadataKey objects (e.g., BottomSheetKey, ListKey, DetailKey, TwoPaneKey, ViewModelStoreKey) for type-safe access and definition of metadata properties, enhancing code clarity and reducing potential runtime errors.
  • MetadataScope Extension Functions: Converted metadata helper functions (e.g., bottomSheet(), listPane(), detailPane(), twoPane(), viewModelStoreKey()) into MetadataScope extension functions, providing a more idiomatic and concise way to define metadata within the metadata DSL block.
  • Dependency Updates: Updated the navigation3 library version to 1.1.0-SNAPSHOT and enabled the androidx.dev snapshot repository in settings.gradle.kts to access the latest features.

🧠 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/main/java/com/example/nav3recipes/animations/AnimatedActivity.kt
    • Imported the metadata DSL function.
    • Updated entry<ScreenC> to use the metadata DSL for defining transition specifications, replacing direct NavDisplay.transitionSpec and NavDisplay.popTransitionSpec calls with put operations using NavDisplay.TransitionKey, NavDisplay.PopTransitionKey, and NavDisplay.PredictivePopTransitionKey.
  • app/src/main/java/com/example/nav3recipes/bottomsheet/BottomSheetActivity.kt
    • Imported ModalBottomSheetProperties and the metadata DSL function.
    • Imported BottomSheetSceneStrategy.Companion.bottomSheet.
    • Updated entry<RouteB> to use the metadata DSL for applying the bottomSheet() metadata.
  • app/src/main/java/com/example/nav3recipes/bottomsheet/BottomSheetSceneStrategy.kt
    • Imported MetadataScope, NavMetadataKey, and get for type-safe metadata handling.
    • Modified the calculateScene method to access metadata using lastEntry.metadata[BottomSheetKey] instead of lastEntry?.metadata?.get(BOTTOM_SHEET_KEY) as? ModalBottomSheetProperties.
    • Refactored the bottomSheet() helper function to be an extension function on MetadataScope and use put(BottomSheetKey, modalBottomSheetProperties).
    • Removed the BOTTOM_SHEET_KEY constant and introduced BottomSheetKey as a NavMetadataKey<ModalBottomSheetProperties>.
  • app/src/main/java/com/example/nav3recipes/scenes/listdetail/ListDetailActivity.kt
    • Imported the metadata DSL function, ListDetailScene.Companion.detailPane, and ListDetailScene.Companion.listPane.
    • Adjusted formatting for data object Profile.
    • Updated entry<ConversationList> and entry<ConversationDetail> to use the metadata DSL for applying listPane() and detailPane() respectively.
  • app/src/main/java/com/example/nav3recipes/scenes/listdetail/ListDetailScene.kt
    • Imported MetadataScope, NavMetadataKey, and get for type-safe metadata handling.
    • Corrected formatting for LocalBackButtonVisibility.
    • Refactored listPane() and detailPane() helper functions to be extension functions on MetadataScope and use put with new ListKey and DetailKey.
    • Removed LIST_KEY and DETAIL_KEY constants and introduced ListKey and DetailKey as NavMetadataKey<Boolean>.
    • Updated calculateScene to access metadata using it.metadata[ListDetailScene.DetailKey] and it.metadata[ListDetailScene.ListKey].
  • app/src/main/java/com/example/nav3recipes/scenes/twopane/TwoPaneActivity.kt
    • Imported the metadata DSL function and TwoPaneScene.Companion.twoPane.
    • Updated entry<Home> and entry<Product> to use the metadata DSL for applying the twoPane() metadata.
  • app/src/main/java/com/example/nav3recipes/scenes/twopane/TwoPaneScene.kt
    • Imported MetadataScope, NavMetadataKey, and get for type-safe metadata handling.
    • Corrected formatting for rememberTwoPaneSceneStrategy.
    • Refactored the twoPane() helper function to be an extension function on MetadataScope and use put(TwoPaneKey, true).
    • Removed the TWO_PANE_KEY constant and introduced TwoPaneKey as a NavMetadataKey<Boolean>.
    • Updated calculateScene to access metadata using it.metadata[TwoPaneScene.TwoPaneKey].
  • app/src/main/java/com/example/nav3recipes/sharedviewmodel/README.md
    • Updated the code snippet to demonstrate the new metadata DSL syntax for viewModelStoreKey.
  • app/src/main/java/com/example/nav3recipes/sharedviewmodel/SharedViewModelActivity.kt
    • Removed an unused Column import.
    • Imported the metadata DSL function and SharedViewModelStoreNavEntryDecorator.Companion.viewModelStoreKey.
    • Updated entry<ChildScreen> to use the metadata DSL for applying the viewModelStoreKey() metadata.
  • app/src/main/java/com/example/nav3recipes/sharedviewmodel/SharedViewModelStoreNavEntryDecorator.kt
    • Adjusted package declaration to be after the copyright header.
    • Imported MetadataScope, NavMetadataKey, and get for type-safe metadata handling.
    • Modified decorate method to access metadata using entry.metadata[ViewModelStoreKey] instead of entry.metadata[PARENT_CONTENT_KEY].
    • Refactored the parent() helper function to viewModelStoreKey() as an extension function on MetadataScope and use put(ViewModelStoreKey, contentKey).
    • Removed the PARENT_CONTENT_KEY constant and introduced ViewModelStoreKey as a NavMetadataKey<Any>.
  • gradle/libs.versions.toml
    • Updated the navigation3 dependency version from 1.0.0 to 1.1.0-SNAPSHOT.
  • settings.gradle.kts
    • Uncommented and specified a maven repository URL for androidx.dev snapshots (build 14863006).
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 effectively migrates the project to use the new Metadata DSL for navigation entries. The changes significantly improve code quality by replacing string-based keys with type-safe NavMetadataKey objects and adopting a more readable builder syntax. This refactoring has been applied consistently across all relevant files, including animations, bottom sheets, and various scene implementations. The corresponding documentation in README.md has also been updated to reflect these new APIs. I've added one comment regarding the build configuration in settings.gradle.kts about using a hardcoded snapshot build ID, which could be improved for better maintainability.

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.

3 participants