Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

Commit

Permalink
make NavHostFragment cast nullable 6b8f8da Victor Albertos Gil <me@vi…
Browse files Browse the repository at this point in the history
…ctoralbertos.com>	29 Jun 2020 at 09:42
  • Loading branch information
VictorAlbertos committed Jun 29, 2020
1 parent 6438634 commit 6707dfe
Showing 1 changed file with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ fun BottomNavigationView.setupWithNavController(
}

destinationChangedListener?.let {
selectedNavController.value?.removeOnDestinationChangedListener(destinationChangedListener)
selectedNavController.value?.removeOnDestinationChangedListener(
destinationChangedListener
)
}
selectedItemTag = newlySelectedItemTag
isOnFirstFragment = selectedItemTag == firstFragmentTag
Expand Down Expand Up @@ -202,13 +204,13 @@ private fun BottomNavigationView.setupItemReselected(
navigationItemReselectedListener?.onNavigationItemReselected(item)

val newlySelectedItemTag = graphIdToTagMap[item.itemId]
val selectedFragment = fragmentManager.findFragmentByTag(newlySelectedItemTag)
as NavHostFragment
val navController = selectedFragment.navController
// Pop the back stack to the start destination of the current navController graph
navController.popBackStack(
navController.graph.startDestination, false
)
(fragmentManager.findFragmentByTag(newlySelectedItemTag) as? NavHostFragment)?.let {
val navController = it.navController
// Pop the back stack to the start destination of the current navController graph
navController.popBackStack(
navController.graph.startDestination, false
)
}
}
}

Expand Down Expand Up @@ -266,8 +268,9 @@ private fun AppCompatActivity.obtainNavHostFragment(
.add(containerId, navHostFragment, fragmentTag)
.commitNow()

navHostFragment.navController.graph = navHostFragment.navController.navInflater.inflate(graphResId)
.also { graph -> graph.startDestination = startDestination }
navHostFragment.navController.graph =
navHostFragment.navController.navInflater.inflate(graphResId)
.also { graph -> graph.startDestination = startDestination }

intent = originalIntent

Expand Down

0 comments on commit 6707dfe

Please sign in to comment.