Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) }
Expand Down