Repository navigation
Migrate activity and dialog destination, action, and NavController snippets - #1220
Open
edward-williams-stellarelements wants to merge 1 commit into
Open
edward-williams-stellarelements wants to merge 1 commit into
edward-williams-stellarelements wants to merge 1 commit into
Conversation
edward-williams-stellarelements
requested a review
from a team
as a code owner
October 23, 2026 20:55
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 13 region tags, one for each code block it migrates from these pages: 12 in
:views(8 navigation graphs and 4 Kotlin blocks) and 1 in:compose:snippets. Each page gets its own sub-package, and each navigation graph that the guide prints as a complete file gets its own file inviews/src/main/res/navigation/.:views):nav_graph_activity_destinations_class_name.xml:android_views_navigation_activity_destinations_class_namenav_graph_activity_destinations_implicit_intent.xml:android_views_navigation_activity_destinations_implicit_intentnav_graph_activity_destinations_other_app.xml:android_views_navigation_activity_destinations_other_appnav_graph_activity_destinations_data_pattern.xml:android_views_navigation_activity_destinations_data_patternnavigation/activitydestinations/ActivityDestinations.kt:android_views_navigation_activity_destinations_start_activityandandroid_views_navigation_activity_destinations_navigate_bundle:views):nav_graph_dialog_destinations.xml:android_views_navigation_dialog_destinations_dialog:views):nav_graph_actions.xml:android_views_navigation_actions_definenavigation/actions/Actions.kt:android_views_navigation_actions_navigatenav_graph_actions_global.xml:android_views_navigation_actions_global:views):nav_graph_global_action.xml:android_views_navigation_global_action_create:views,navigation/navcontroller/NavControllerCreate.kt:android_views_navigation_navcontroller_navhostfragment:compose:snippets,navigation/navcontroller/NavControllerCreate.kt:android_compose_navigation_navcontroller_createDependencies, manifest, and supporting code
views/build.gradle.ktsandgradle/libs.versions.toml: addsandroidx.navigation:navigation-fragment-ktx, using theandroidx-navigationversion that's already in the catalog.:viewshad no Navigation dependency before. It providesNavHostFragment(Navcontroller page),NavController(Activity-destinations and Actions pages), theapp:attributes that the navigation graphs use (startDestination,destination,popUpTo,popUpToInclusive,action,data,dataPattern,targetPackage,argType), and the navigators behind the graphs'<activity>,<fragment>, and<dialog>destinations. No other dependency is added.views/src/main/AndroidManifest.xml: registersDestinationActivity, the activity that the Activity-destinations page'sstartActivity(Intent(context, DestinationActivity::class.java))call launches. The class is at the bottom ofActivityDestinations.kt. It can't be private, because the system instantiates it.navController,context, and an activity forstartActivity()andsupportFragmentManager. None of that is inside a region.Compile-driven resources (required for the snippets to compile, no region tags):
views/src/main/res/values/activity_destinations.xml: the stringssampleActivityTitleandlocalActivityTitle, and the idsimpleFragment. The Activity-destinations page's four graphs reference@string/sampleActivityTitle,@string/localActivityTitle, andapp:startDestination="@id/simpleFragment", and resource linking fails while they're undefined. The page's graphs don't include asimpleFragmentdestination, so the id is declared on its own. The names come from the page.views/src/main/res/values/navcontroller.xml: the idnav_host_fragment, forR.id.nav_host_fragmentin the Navcontroller page's Kotlin. The name comes from the page.nav_graph_actions.xml: the Actions page prints only the<fragment>element, so the file adds the<navigation>root around the region and afragmentBdestination after it. The action'sapp:destination="@id/fragmentB"has to resolve.nav_graph_global_action.xml: the page's...line is a plain exclude that hides themainFragmentdestination, whichapp:startDestinationand the global action point to. It renders as..., like the page.List of modifications (visible diffs vs. the page)
<?xml version="1.0" encoding="utf-8"?>. That line has to be the first line of the file, ahead of the license header, so it can't be inside a region. These 7 regions start at<navigation.android_views_navigation_activity_destinations_navigate_bundle:bundleOf("userId" to "someUser")is nowBundle().apply { putString("userId", "someUser") }, on the same line.bundleOfis deprecated in the core-ktx version this repository uses ("This method does not provide type safety at compile time. Use the platformBundleclass directly instead"), so the original line builds with a deprecation warning. The guide's text already says the value is passed "with aBundle".android_views_navigation_actions_global: addsxmlns:tools="http://schemas.android.com/tools"to the<navigation>element. The page's graph usestools:layoutwithout declaring thetoolsnamespace, andaapt2rejects it ("unbound prefix").android_views_navigation_actions_global: the commentAction back to destination which launched into this in_game_nav_graphnow ends with a full stop.android_views_navigation_dialog_destinations_dialog: the page's two standalone...lines are<!-- ... -->comments. Nothing needs to be hidden there for the graph to compile.android:name(com.example.android.navigation.activity.DestinationActivity,com.example.FragmentA,com.example.android.gamemodule.*,androidx.navigation.myapp.MyDialogFragment) and the page's indentation.spotlessApplymade no changes.Lint reports
InvalidNavigationwarnings on 5 of the new graphs. These are warnings, not errors, and they come from the guide's code, which is kept as printed. The four Activity-destinations graphs setapp:startDestination="@id/simpleFragment"without containing that destination, and the Dialog-destinations graph has no start destination, because the guide shows only the part of each graph it explains.Snippets not migrated
AndroidManifest.xmlblock stays on the guide page, because manifest blocks are kept there.dialog()example and the Kotlin DSL graph) are left as they are on the guide page for now.Heads-up, unrelated to this PR and left untouched:
spotlessApplylogs "Skipping 'build.gradle.kts' because it does not converge" forviews/build.gradle.kts, which has a nonstandard license header onmain.Build:
./gradlew :views:spotlessApply :compose:snippets:spotlessApply(no changes), then./gradlew :views:buildand./gradlew :compose:snippets:buildpass.