Clear back stack before navigate to tab
This commit is contained in:
parent
9359988342
commit
a061121b1d
|
|
@ -15,8 +15,21 @@ abstract class BottomNavigationActivity : NavigationActivity() {
|
|||
val innerNavigation: ViewControllerNavigation<BottomNavigationActivity>
|
||||
get() = getNavigationContainer(supportFragmentManager)?.navigation ?: navigation as ViewControllerNavigation<BottomNavigationActivity>
|
||||
|
||||
fun navigateTo(@IdRes navigationTabId: Int, state: Parcelable? = null) =
|
||||
(supportFragmentManager.primaryNavigationFragment as? BottomNavigationFragment)?.navigateTo(navigationTabId, state)
|
||||
/**
|
||||
* Navigates to the given navigation tab.
|
||||
* Can be called from any node of navigation graph so all back stack will be cleared.
|
||||
*
|
||||
* @param navigationTabId Id of navigation tab.
|
||||
* @param state State of the given tab. If not null tab's fragment will be recreated, otherwise only in case it has not been created before.
|
||||
*/
|
||||
fun navigateTo(@IdRes navigationTabId: Int, state: Parcelable? = null) {
|
||||
supportFragmentManager.run {
|
||||
// Clear all navigation stack unto the main bottom navigation (tagged as top)
|
||||
popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE)
|
||||
|
||||
(primaryNavigationFragment as? BottomNavigationFragment)?.navigateTo(navigationTabId, state)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getNavigationContainer(fragmentManager: FragmentManager?): NavigationContainerFragment? =
|
||||
fragmentManager
|
||||
|
|
|
|||
Loading…
Reference in New Issue