Repository navigation
Migrate Navigation back stack, migration, and configuration change snippets - #1229
Open
edward-williams-stellarelements wants to merge 1 commit into
Conversation
edward-williams-stellarelements
requested a review
from a team
as a code owner
October 27, 2026 14:19
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Code snippets are for:
This PR adds 11 region tags, one for each code block it migrates from these pages. 9 are in
:views: 8 XML resources and 1 Kotlin block. The other 2 are Kotlin blocks in:compose:snippets. Each page gets its own sub-package, and each graph or menu that the guide prints as a complete file gets its own file.:compose:snippets,navigation/backstack/BackStack.kt):android_compose_navigation_backstack_pop_back_stackandandroid_compose_navigation_backstack_pop_up_to. Both are plainNavControllercalls. They go in the same module as the page's other Kotlin, which is a Compose example.:views):nav_graph_multi_back_stacks.xml:android_views_navigation_multi_back_stacks_action:views):navigation/migrate/MigrateToNavigation.kt:android_views_navigation_migrate_host_layoutnav_graph_migrate_product_list.xml:android_views_navigation_migrate_product_list_graphmenu/menu_migrate_activity_main_drawer.xml:android_views_navigation_migrate_drawer_menunav_graph_migrate_activity_main.xml:android_views_navigation_migrate_drawer_graphnav_graph_migrate_graph_b.xml:android_views_navigation_migrate_graph_bnav_graph_migrate_graph_b_before_combining.xml:android_views_navigation_migrate_graph_b_before_combiningnav_graph_migrate_combined.xml:android_views_navigation_migrate_combined_graph:views):nav_graph_config_changes.xml:android_views_navigation_config_changes_destination_labelDependencies and supporting code
views/build.gradle.ktsandgradle/libs.versions.toml: these files addandroidx.navigation:navigation-fragment-ktx, using theandroidx-navigationversion that's already in the catalog. The two lines are identical to the ones Migrate activity and dialog destination, action, and NavController snippets #1220 and Migrate navigation graph design, Kotlin DSL, nested graph, and Navigation Editor snippets #1221 add, so whichever of these PRs merges first, the others drop the duplicates when they rebase. The library provides theapp:attributes that the graphs use (startDestination,destination,argType,popUpTo,popUpToSaveState, andrestoreState) and the navigator behind their<fragment>destinations. Nothing else is added.:viewsalready depends onappcompatandmaterial, which cover the Migrate page'sAppCompatActivityand menu, and:compose:snippetsalready depends onnavigation-compose.navControllerthe page's code assumes.nav_graph_multi_back_stacks.xml: the Multi-back-stacks page prints only the<action>element. The file adds a<navigation>root around the region, with two nested graphs,first_stack(start destinationfirst_stack_start_destination) andsecond_stack, so@id/second_stackand@id/first_stack_start_destinationresolve. The action is a global action in that root.nav_graph_config_changes.xml: the Config-changes page prints<navigation ...>. An XML start tag can't hold a comment or an exclude, so the region's<navigation>is a nested graph without attributes, inside a root<navigation>that declares theandroidandtoolsnamespaces (see the list of modifications).MigrateToNavigation.kt: the page's...line just before the comment is a plain exclude that hidessuper.onCreate(savedInstanceState), which lint'sMissingSuperCallcheck requires.Compile-driven resources. The snippets need these files to compile, so the files have no region tags:
views/src/main/res/layout/product_list_host.xml: the Migrate page's Kotlin snippet callssetContentView(R.layout.product_list_host). The page forces the file name. The content is the page's ownproduct_list_hostlayout from "Create a New Layout to Host the UI", which stays on the guide page.views/src/main/res/values/migrate.xml: the stringsmenu_home,menu_gallery,menu_slideshow, andmenu_tools, for the Migrate page's drawer menu (android:title="@string/menu_*"). The names come from the page.views/src/main/res/drawable/ic_menu_camera.xml,ic_menu_gallery.xml,ic_menu_slideshow.xml, andic_menu_manage.xml: the menu'sandroid:icon="@drawable/ic_menu_*"attributes need them. The names come from the page. Each file is a whole Material Icons source file from google/material-design-icons (Apache License 2.0, commit10ecc147), with this repository's license header added:ic_menu_camera.xml:android/image/photo_camera/materialicons/black/res/drawable/baseline_photo_camera_24.xmlic_menu_gallery.xml:android/image/photo_library/materialicons/black/res/drawable/baseline_photo_library_24.xmlic_menu_slideshow.xml:android/image/slideshow/materialicons/black/res/drawable/baseline_slideshow_24.xmlic_menu_manage.xml:android/action/build/materialicons/black/res/drawable/baseline_build_24.xmlviews/src/main/res/values/config_changes.xml: the stringmy_dest_label(My destination), for the Config-changes page'sandroid:label="@string/my_dest_label". The name comes from the page.compose/snippets/src/main/res/values/backstack.xml: the iddestinationId, forR.id.destinationIdin the Backstack page'spopBackStack()call. The page doesn't print a graph that declares it. The name comes from the page.tools:layoutreferences, which only drive the Navigation Editor preview. The build and lint pass without them.List of modifications (visible diffs vs. the page)
Backstack page,
android_compose_navigation_backstack_pop_up_to: each of the three comments now ends with a full stop.Multi-back-stacks page,
android_views_navigation_multi_back_stacks_action: the page wraps the attribute values in curly quotes (”). That isn't valid XML, soaapt2can't compile the snippet as printed. All 10 curly quotes are now straight quotes ("). Nothing else changed.Migrate page,
android_views_navigation_migrate_host_layout: the three standalone...lines render as// .... The one before the comment is the exclude described above. The commentReplace setContentView(R.layout.product_list) with the line belownow ends with a full stop.Config-changes page,
android_views_navigation_config_changes_destination_label:<navigation ...>renders as<navigation>. The...sits inside an XML start tag, where neither a comment nor an exclude can go. The trailing...line is now a<!-- ... -->comment. Like the page, the snippet has no closing</navigation>.Everything else is copied verbatim. That includes:
<!-- activity_main_drawer.xml -->,<!-- activity_main_graph.xml -->,<!-- Graph B -->, and<!-- Combined Graph A and B -->)android:name7 of the 11 regions render identically to the page.
spotlessApplymade no changes.Lint reports 0 errors. Three warnings point at new files:
InvalidNavigationwarnings ("No start destination specified") innav_graph_config_changes.xml. The nested<navigation>that renders as the page's<navigation ...>can't carry attributes, and the hidden root only declares the namespaces.MergeRootFramewarning inproduct_list_host.xml, which keeps the page'sFrameLayout.Snippets not migrated
None of these blocks triggers the guide linter's GitHub-snippet check, so none needs a suppression. Where a Kotlin block stays on the guide page, its Java tab stays with it.
...placeholder and callsfinish(), so it needs an activity around it.routevalue and anAroute type that the page doesn't define.MyAppNavHostblock: will be migrated in a follow-up pull request. It needsA,B, andDestinationB, which the page doesn't define, and theDestinationB(/* ... */)placeholder needs a ruling.<action>block: will be migrated in a follow-up pull request.app:restoreState=”true”uses curly quotes, which isn't valid XML, and the page bolds theapp:popUpToSaveStateline.selectedBottomNavRoute, which the page doesn't define.product_list_hostFrameLayout,FragmentContainerView, and theFrameLayoutwith theNavHostFragment): View-based code.ProductListActivity,ProductListFragment,MainActivity,ProductDetailsActivity, andProductDetailsFragmentcode, the product click callback, and thenavigateToProductDetails()functions): View-based code (activities and fragments).navigation_activity.xmllayout blocks: View-based code.MainActivityKotlin and Java blocks: View-based code.Heads-up, unrelated to this PR and left untouched:
spotlessApplylogs "Skipping 'build.gradle.kts' because it does not converge" forcompose/snippets/build.gradle.kts, which is the same onmain.Build:
./gradlew :views:spotlessApply :compose:snippets:spotlessApplymade no changes. Then./gradlew :views:buildand./gradlew :compose:snippets:buildpass.Companion CL: cl/1008093242