Skip to content

Commit

Permalink
Merge pull request #172 from nhaarman/fix-notify-order
Browse files Browse the repository at this point in the history
Invoke Scene.onStart after listener notification for ReplacingNavigator
  • Loading branch information
nhaarman authored Oct 21, 2020
2 parents 37f638b + 0bb4684 commit e38f33a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ abstract class ReplacingNavigator(

override fun start(): StateTransition {
return StateTransition(Active(scene, listeners)) {
scene.onStart()
listeners.forEach { it.scene(scene) }
scene.onStart()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ abstract class StackNavigator(

override fun start(): StateTransition {
return StateTransition(Active(scenes, listeners)) {
// These lines should be swapped
listeners.forEach { it.scene(scenes.last(), null) }
scenes.last().onStart()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,21 @@ internal class ReplacingNavigatorTest {
verify(scene1).onStart()
}
}

@Test
fun `starting the navigator invokes listeners before starting the scene`() {
/* Given */
navigator.addNavigatorEventsListener(listener)

/* When */
navigator.onStart()

/* Then */
inOrder(listener, initialScene) {
verify(listener).scene(eq(initialScene), anyOrNull())
verify(initialScene).onStart()
}
}
}

private open class TestListener : Navigator.Events {
Expand Down

0 comments on commit e38f33a

Please sign in to comment.