Skip to content

Commit

Permalink
ETH-1058 - fixed navigation infinite recursion (#2217)
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardmaximovich authored Feb 26, 2024
1 parent 23d6ca8 commit 78ac73c
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions app/src/main/java/org/p2p/wallet/utils/NavigationExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,32 @@ fun Fragment.popAndReplaceFragment(
@AnimRes popEnter: Int = R.anim.nav_pop_enter,
@AnimRes popExit: Int = R.anim.nav_pop_exit,
fragmentManager: FragmentManager = requireActivity().supportFragmentManager
) = requireActivity().popAndReplaceFragment(
target = target,
popTo = popTo,
containerId = containerId,
addToBackStack = addToBackStack,
inclusive = inclusive,
enter = enter,
exit = exit,
popEnter = popEnter,
popExit = popExit,
fragmentManager = fragmentManager
)
) = whenStateAtLeast(Lifecycle.State.STARTED) {
requireActivity().hideKeyboard()
with(fragmentManager) {
// Override exit animation for popping fragment
if (this@popAndReplaceFragment is BaseFragmentContract) {
this@popAndReplaceFragment.overrideExitAnimation(exit)
}

// Make pop entering fragment invisible during transition
popTo?.java?.name
?.let { findFragmentByTag(it) as? BaseFragmentContract }
?.apply { overrideEnterAnimation(R.anim.nav_stay_transparent) }

popBackStack(
popTo?.java?.name,
if (inclusive) FragmentManager.POP_BACK_STACK_INCLUSIVE else 0
)

commit(allowStateLoss = true) {
// Preform immediate replace
setCustomAnimations(enter, 0, popEnter, popExit)
replace(containerId, target, target.javaClass.name)
if (addToBackStack) addToBackStack(target.javaClass.name)
}
}
}

fun FragmentActivity.popAndReplaceFragment(
target: Fragment,
Expand Down

0 comments on commit 78ac73c

Please sign in to comment.