Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielwilson1702/1770b154da109cbf5f206bd46447ebe9 to your computer and use it in GitHub Desktop.
Save danielwilson1702/1770b154da109cbf5f206bd46447ebe9 to your computer and use it in GitHub Desktop.
//https://developer.android.com/guide/navigation/navigation-pass-data#start
//Primary and detail nav graphs require data passed to them to initialize them with their tab number.
val primaryNavHostFragment =
childFragmentManager.findFragmentById(R.id.primary_nav_host_fragment) as NavHostFragment
var navController = primaryNavHostFragment.navController
navController.setGraph(
R.navigation.primary_nav_graph, bundleOf(
TAB_NUMBER to args.tabNumber
)
)
val detailNavHostFragment =
childFragmentManager.findFragmentById(R.id.detail_nav_host_fragment) as NavHostFragment
navController = detailNavHostFragment.navController
navController.setGraph(
R.navigation.details_nav_graph, bundleOf(
TAB_NUMBER to args.tabNumber,
PRIMARY_SELECTION to "Initialized with tab number ${args.tabNumber}"
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment