diff --git a/magellan-library/src/main/java/com/wealthfront/magellan/navigation/NavigationDelegate.kt b/magellan-library/src/main/java/com/wealthfront/magellan/navigation/NavigationDelegate.kt index 8e827e83..f5f5f6bb 100644 --- a/magellan-library/src/main/java/com/wealthfront/magellan/navigation/NavigationDelegate.kt +++ b/magellan-library/src/main/java/com/wealthfront/magellan/navigation/NavigationDelegate.kt @@ -94,11 +94,13 @@ public open class NavigationDelegate( } } - val from = navigateFrom(oldBackStackCopy.currentNavigable) + val fromNavigable = oldBackStackCopy.currentNavigable + val from = navigateFrom(fromNavigable) val newBackStack = backStack.map { it.navigable } findBackstackChangesAndUpdateStates(oldBackStack = oldBackStack, newBackStack = newBackStack) - val to = navigateTo(backStack.currentNavigable!!, direction) - animateAndRemove(from, to, direction, transition) + val toNavigable = backStack.currentNavigable!! + val to = navigateTo(toNavigable, direction) + animateAndRemove(fromNavigable, from, toNavigable, to, direction, transition) } private fun findBackstackChangesAndUpdateStates( @@ -129,7 +131,9 @@ public open class NavigationDelegate( joinToString(prefix = "[", postfix = "]") { it::class.java.simpleName } protected open fun animateAndRemove( + fromNavigable: NavigableCompat?, from: View?, + toNavigable: NavigableCompat, to: View?, direction: Direction, magellanTransition: MagellanTransition @@ -144,6 +148,9 @@ public open class NavigationDelegate( NoAnimationTransition() } transition.animate(from, to, direction) { + if (fromNavigable != null && lifecycleRegistry.children.contains(fromNavigable)) { + lifecycleRegistry.updateMaxState(fromNavigable, CREATED) + } if (context != null && containerView != null) { containerView!!.removeView(from) currentNavigable!!.transitionFinished() @@ -174,7 +181,6 @@ public open class NavigationDelegate( protected open fun navigateFrom(currentNavigable: NavigableCompat?): View? { return currentNavigable?.let { oldNavigable -> val currentView = templatedViewMap[oldNavigable] ?: oldNavigable.view - lifecycleRegistry.updateMaxState(oldNavigable, CREATED) navigationPropagator.onNavigatedFrom(oldNavigable) templatedViewMap.remove(oldNavigable) currentView diff --git a/magellan-library/src/test/java/com/wealthfront/magellan/navigation/DefaultLinearNavigatorTest.kt b/magellan-library/src/test/java/com/wealthfront/magellan/navigation/DefaultLinearNavigatorTest.kt index 39d0ed6f..9399fc55 100644 --- a/magellan-library/src/test/java/com/wealthfront/magellan/navigation/DefaultLinearNavigatorTest.kt +++ b/magellan-library/src/test/java/com/wealthfront/magellan/navigation/DefaultLinearNavigatorTest.kt @@ -17,6 +17,7 @@ import com.wealthfront.magellan.lifecycle.LifecycleState.Resumed import com.wealthfront.magellan.lifecycle.LifecycleState.Shown import com.wealthfront.magellan.lifecycle.transitionToState import com.wealthfront.magellan.transitions.DefaultTransition +import com.wealthfront.magellan.transitions.NoAnimationTransition import com.wealthfront.magellan.transitions.ShowTransition import io.mockk.MockKAnnotations.init import io.mockk.every @@ -198,15 +199,19 @@ class DefaultLinearNavigatorTest { @Test fun goBack_multipleScreen_removeScreenFromBackstack() { linearNavigator.transitionToState(Resumed(context)) - linearNavigator.goTo(step1) - linearNavigator.goTo(step2) + linearNavigator.goTo(step1, NoAnimationTransition()) + step1.view!!.measure(200, 200) + step1.view!!.viewTreeObserver.dispatchOnPreDraw() + linearNavigator.goTo(step2, NoAnimationTransition()) + step2.view!!.measure(200, 200) + step2.view!!.viewTreeObserver.dispatchOnPreDraw() val didNavigate = linearNavigator.goBack() assertThat(didNavigate).isTrue() assertThat(linearNavigator.backStack.size).isEqualTo(1) assertThat(linearNavigator.backStack.first().navigable).isEqualTo(step1) assertThat(linearNavigator.backStack.first().magellanTransition.javaClass) - .isEqualTo(DefaultTransition::class.java) + .isEqualTo(NoAnimationTransition::class.java) verify { navigableListener.beforeNavigation() } verify { navigableListener.onNavigatedFrom(step2) }