Updated on 2026-08-14

This commit is contained in:
Tangem 2022-12-11 09:43:03 +03:00
parent 87c43ab20f
commit efd439d0ce
7 changed files with 29 additions and 10 deletions

View file

@ -54,12 +54,12 @@ fun FragmentActivity.openFragment(
if (screen.isDialogFragment) {
(fragment as DialogFragment).show(transaction, screen.name)
if (addToBackstack) {
transaction.addToBackStack(null)
transaction.addToBackStack(screen.name)
}
} else {
transaction.replace(R.id.fragment_container, fragment, screen.name)
if (addToBackstack && (screen != AppScreen.Home && screen != AppScreen.Welcome)) {
transaction.addToBackStack(null)
if (addToBackstack) {
transaction.addToBackStack(screen.name)
}
transaction.commitAllowingStateLoss()
}

View file

@ -12,7 +12,10 @@ sealed class NavigationAction : Action {
val addToBackstack: Boolean = true,
) : NavigationAction()
data class PopBackTo(val screen: AppScreen? = null) : NavigationAction()
data class PopBackTo(
val screen: AppScreen? = null,
val inclusive: Boolean = false,
) : NavigationAction()
data class OpenUrl(val url: String) : NavigationAction()

View file

@ -32,13 +32,13 @@ val navigationMiddleware: Middleware<AppState> = { _, state ->
AppScreen.Home,
AppScreen.Welcome,
-> {
navState?.activity?.get()?.popBackTo(screen = null, inclusive = true)
navState?.activity?.get()?.popBackTo(screen, action.inclusive)
if (navState?.backStack?.contains(screen) != true) {
store.dispatchOnMain(NavigationAction.NavigateTo(screen))
}
}
else -> {
navState?.activity?.get()?.popBackTo(screen = action.screen)
navState?.activity?.get()?.popBackTo(screen, action.inclusive)
}
}
}