Skip to content

Instantly share code, notes, and snippets.

@danielwilson1702
Created March 2, 2022 11:54
Show Gist options
  • Save danielwilson1702/90860a871eec6d38d591980910aaf168 to your computer and use it in GitHub Desktop.
Save danielwilson1702/90860a871eec6d38d591980910aaf168 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