From 0bb4684ab679c87efccaf58f34dac62492de3d4f Mon Sep 17 00:00:00 2001 From: Niek Haarman Date: Wed, 21 Oct 2020 17:03:58 +0200 Subject: [PATCH] Invoke Scene.onStart after listener notification for ReplacingNavigator This fix was already applied for a started Navigator, but now it is also applied when _starting_ the navigator. --- .../acorn/navigation/ReplacingNavigator.kt | 2 +- .../nhaarman/acorn/navigation/StackNavigator.kt | 1 - .../acorn/navigation/ReplacingNavigatorTest.kt | 15 +++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ext/acorn/src/main/java/com/nhaarman/acorn/navigation/ReplacingNavigator.kt b/ext/acorn/src/main/java/com/nhaarman/acorn/navigation/ReplacingNavigator.kt index d59b69b4..533eab0c 100644 --- a/ext/acorn/src/main/java/com/nhaarman/acorn/navigation/ReplacingNavigator.kt +++ b/ext/acorn/src/main/java/com/nhaarman/acorn/navigation/ReplacingNavigator.kt @@ -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() } } diff --git a/ext/acorn/src/main/java/com/nhaarman/acorn/navigation/StackNavigator.kt b/ext/acorn/src/main/java/com/nhaarman/acorn/navigation/StackNavigator.kt index 47a4c08b..cf102898 100644 --- a/ext/acorn/src/main/java/com/nhaarman/acorn/navigation/StackNavigator.kt +++ b/ext/acorn/src/main/java/com/nhaarman/acorn/navigation/StackNavigator.kt @@ -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() } diff --git a/ext/acorn/src/test/java/com/nhaarman/acorn/navigation/ReplacingNavigatorTest.kt b/ext/acorn/src/test/java/com/nhaarman/acorn/navigation/ReplacingNavigatorTest.kt index 5a2c1c6d..a43e4565 100644 --- a/ext/acorn/src/test/java/com/nhaarman/acorn/navigation/ReplacingNavigatorTest.kt +++ b/ext/acorn/src/test/java/com/nhaarman/acorn/navigation/ReplacingNavigatorTest.kt @@ -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 {