diff --git a/tabbar-navigation/src/main/java/ru/touchin/roboswag/components/tabbarnavigation/BottomNavigationActivity.kt b/tabbar-navigation/src/main/java/ru/touchin/roboswag/components/tabbarnavigation/BottomNavigationActivity.kt index c83d378..69679a6 100644 --- a/tabbar-navigation/src/main/java/ru/touchin/roboswag/components/tabbarnavigation/BottomNavigationActivity.kt +++ b/tabbar-navigation/src/main/java/ru/touchin/roboswag/components/tabbarnavigation/BottomNavigationActivity.kt @@ -15,8 +15,21 @@ abstract class BottomNavigationActivity : NavigationActivity() { val innerNavigation: ViewControllerNavigation get() = getNavigationContainer(supportFragmentManager)?.navigation ?: navigation as ViewControllerNavigation - 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