From 884b69ac18d62610b44d94f3177e34c9b3601e4f Mon Sep 17 00:00:00 2001 From: Manel Martos Date: Fri, 12 Apr 2024 13:29:58 +0200 Subject: [PATCH 1/7] Node initialisation wasn't adding necesary plugins --- .../commonMain/kotlin/com/bumble/appyx/navigation/node/Node.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appyx-navigation/common/src/commonMain/kotlin/com/bumble/appyx/navigation/node/Node.kt b/appyx-navigation/common/src/commonMain/kotlin/com/bumble/appyx/navigation/node/Node.kt index 5d1c605ae..b71daa307 100644 --- a/appyx-navigation/common/src/commonMain/kotlin/com/bumble/appyx/navigation/node/Node.kt +++ b/appyx-navigation/common/src/commonMain/kotlin/com/bumble/appyx/navigation/node/Node.kt @@ -91,7 +91,7 @@ abstract class Node( val id: String get() = nodeContext.identifier - val plugins: List = plugins + listOfNotNull(this as? Plugin) + val plugins: List = plugins + appyxComponent + childAware + listOfNotNull(this as? Plugin) val ancestryInfo: AncestryInfo = nodeContext.ancestryInfo From 482f9322fd15adc0f01e44db17159269fb41cc79 Mon Sep 17 00:00:00 2001 From: Manel Martos Date: Fri, 12 Apr 2024 15:23:32 +0200 Subject: [PATCH 2/7] Update CHANGELOG + add test --- CHANGELOG.md | 1 + appyx-navigation/common/build.gradle.kts | 1 + .../bumble/appyx/helpers/DummyComponent.kt | 38 +++++++++++++++++ .../appyx/helpers/DummyComponentModel.kt | 32 +++++++++++++++ .../appyx/helpers/DummyVisualisation.kt | 32 +++++++++++++++ .../com/bumble/appyx/helpers/RootNode.kt | 33 +++++++++++++++ .../com/bumble/appyx/helpers/TargetUiState.kt | 41 +++++++++++++++++++ .../bumble/appyx/navigation/node/NodeTest.kt | 17 ++++++++ gradle/libs.versions.toml | 2 +- 9 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/helpers/DummyComponent.kt create mode 100644 appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/helpers/DummyComponentModel.kt create mode 100644 appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/helpers/DummyVisualisation.kt create mode 100644 appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/helpers/RootNode.kt create mode 100644 appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/helpers/TargetUiState.kt create mode 100644 appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/navigation/node/NodeTest.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 23ec1740f..0964237b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ ### Enhancement - [#679](https://github.com/bumble-tech/appyx/pull/679) – Simple api for backStackNode and spotlightNode +- [#694](https://github.com/bumble-tech/appyx/pull/694) – appyxComponent state not restored after configuration changes --- diff --git a/appyx-navigation/common/build.gradle.kts b/appyx-navigation/common/build.gradle.kts index 4b5df9db5..88570c903 100644 --- a/appyx-navigation/common/build.gradle.kts +++ b/appyx-navigation/common/build.gradle.kts @@ -61,6 +61,7 @@ kotlin { val commonTest by getting { dependencies { implementation(kotlin("test")) + implementation(libs.kotlin.coroutines.test) } } val androidMain by getting { diff --git a/appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/helpers/DummyComponent.kt b/appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/helpers/DummyComponent.kt new file mode 100644 index 000000000..c35124d61 --- /dev/null +++ b/appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/helpers/DummyComponent.kt @@ -0,0 +1,38 @@ +package com.bumble.appyx.helpers + +import androidx.compose.animation.core.AnimationSpec +import androidx.compose.animation.core.spring +import com.bumble.appyx.helpers.DummyComponentModel.State +import com.bumble.appyx.interactions.gesture.GestureFactory +import com.bumble.appyx.interactions.gesture.GestureSettleConfig +import com.bumble.appyx.interactions.model.BaseAppyxComponent +import com.bumble.appyx.interactions.model.backpresshandlerstrategies.BackPressHandlerStrategy +import com.bumble.appyx.interactions.model.backpresshandlerstrategies.DontHandleBackPress +import com.bumble.appyx.interactions.ui.Visualisation +import com.bumble.appyx.interactions.ui.context.TransitionBounds +import com.bumble.appyx.interactions.ui.context.UiContext +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.test.StandardTestDispatcher + +class DummyComponent( + scope: CoroutineScope = CoroutineScope(SupervisorJob() + StandardTestDispatcher()), + val model: DummyComponentModel, + visualisation: (UiContext) -> Visualisation>, + animationSpec: AnimationSpec = spring(), + gestureFactory: (TransitionBounds) -> GestureFactory> = { + GestureFactory.Noop() + }, + gestureSettleConfig: GestureSettleConfig = GestureSettleConfig(), + backPressStrategy: BackPressHandlerStrategy> = DontHandleBackPress(), + disableAnimations: Boolean = false, +) : BaseAppyxComponent>( + scope = scope, + model = model, + visualisation = visualisation, + gestureFactory = gestureFactory, + gestureSettleConfig = gestureSettleConfig, + backPressStrategy = backPressStrategy, + defaultAnimationSpec = animationSpec, + disableAnimations = disableAnimations +) diff --git a/appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/helpers/DummyComponentModel.kt b/appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/helpers/DummyComponentModel.kt new file mode 100644 index 000000000..100126a61 --- /dev/null +++ b/appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/helpers/DummyComponentModel.kt @@ -0,0 +1,32 @@ +package com.bumble.appyx.helpers + +import com.bumble.appyx.helpers.DummyComponentModel.State +import com.bumble.appyx.interactions.model.Element +import com.bumble.appyx.interactions.model.asElement +import com.bumble.appyx.interactions.model.transition.BaseTransitionModel +import com.bumble.appyx.utils.multiplatform.Parcelable +import com.bumble.appyx.utils.multiplatform.Parcelize +import com.bumble.appyx.utils.multiplatform.SavedStateMap + +class DummyComponentModel( + initialTarget: NavTarget, + savedStateMap: SavedStateMap?, +) : BaseTransitionModel>( + savedStateMap = savedStateMap, +) { + @Parcelize + data class State( + val target: Element + ) : Parcelable + + override val initialState: State = State(initialTarget.asElement()) + + override fun State.availableElements(): Set> = setOf(target) + + override fun State.removeDestroyedElement(element: Element): State = + this + + override fun State.removeDestroyedElements(): State = this + + override fun State.destroyedElements(): Set> = emptySet() +} diff --git a/appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/helpers/DummyVisualisation.kt b/appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/helpers/DummyVisualisation.kt new file mode 100644 index 000000000..c3bdb829a --- /dev/null +++ b/appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/helpers/DummyVisualisation.kt @@ -0,0 +1,32 @@ +package com.bumble.appyx.helpers + +import androidx.compose.animation.core.SpringSpec +import com.bumble.appyx.helpers.DummyComponentModel.State +import com.bumble.appyx.interactions.ui.DefaultAnimationSpec +import com.bumble.appyx.interactions.ui.context.UiContext +import com.bumble.appyx.interactions.ui.state.MatchedTargetUiState +import com.bumble.appyx.transitionmodel.BaseVisualisation + +class DummyVisualisation( + uiContext: UiContext, + defaultAnimationSpec: SpringSpec = DefaultAnimationSpec +) : BaseVisualisation, TargetUiState, MutableUiState>( + uiContext = uiContext, + defaultAnimationSpec = defaultAnimationSpec, +) { + override fun State.toUiTargets(): List> = + listOf( + MatchedTargetUiState( + element = target, + targetUiState = TargetUiState(0) + ) + ) + + override fun mutableUiStateFor( + uiContext: UiContext, + targetUiState: TargetUiState + ): MutableUiState = + targetUiState.toMutableUiState(uiContext) + + +} diff --git a/appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/helpers/RootNode.kt b/appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/helpers/RootNode.kt new file mode 100644 index 000000000..31d0dd152 --- /dev/null +++ b/appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/helpers/RootNode.kt @@ -0,0 +1,33 @@ +package com.bumble.appyx.helpers + +import androidx.compose.material.Text +import com.bumble.appyx.helpers.RootNode.NavTarget +import com.bumble.appyx.navigation.modality.NodeContext +import com.bumble.appyx.navigation.node.Node +import com.bumble.appyx.navigation.node.node + +class RootNode( + nodeContext: NodeContext, + dummyComponent: DummyComponent = DummyComponent( + model = DummyComponentModel( + initialTarget = NavTarget.Child1, + savedStateMap = nodeContext.savedStateMap + ), + visualisation = { DummyVisualisation(it) } + ) +) : Node( + nodeContext = nodeContext, + appyxComponent = dummyComponent, +) { + sealed interface NavTarget { + data object Child1 : NavTarget + data object Child2 : NavTarget + } + + override fun buildChildNode(navTarget: NavTarget, nodeContext: NodeContext): Node<*> = + when (navTarget) { + is NavTarget.Child1 -> node(nodeContext) { Text("Child 1") } + is NavTarget.Child2 -> node(nodeContext) { Text("Child 2") } + } + +} diff --git a/appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/helpers/TargetUiState.kt b/appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/helpers/TargetUiState.kt new file mode 100644 index 000000000..5d3dbf5e2 --- /dev/null +++ b/appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/helpers/TargetUiState.kt @@ -0,0 +1,41 @@ +package com.bumble.appyx.helpers + +import androidx.compose.animation.core.SpringSpec +import androidx.compose.ui.Modifier +import com.bumble.appyx.interactions.ui.context.UiContext +import com.bumble.appyx.interactions.ui.state.BaseMutableUiState +import kotlinx.coroutines.CoroutineScope + +class TargetUiState( + val id: Int, +) + +class MutableUiState( + uiContext: UiContext, + val id: Int, +) : BaseMutableUiState( + uiContext, emptyList() +) { + override val combinedMotionPropertyModifier: Modifier = Modifier + + override suspend fun snapTo(target: TargetUiState) = Unit + + override fun lerpTo( + scope: CoroutineScope, + start: TargetUiState, + end: TargetUiState, + fraction: Float + ) = Unit + + override suspend fun animateTo( + scope: CoroutineScope, + target: TargetUiState, + springSpec: SpringSpec + ) = Unit +} + +fun TargetUiState.toMutableUiState(uiContext: UiContext): MutableUiState = + MutableUiState( + uiContext = uiContext, + id = id, + ) diff --git a/appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/navigation/node/NodeTest.kt b/appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/navigation/node/NodeTest.kt new file mode 100644 index 000000000..29fb4962b --- /dev/null +++ b/appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/navigation/node/NodeTest.kt @@ -0,0 +1,17 @@ +package com.bumble.appyx.navigation.node + +import com.bumble.appyx.helpers.RootNode +import com.bumble.appyx.navigation.modality.NodeContext +import com.bumble.appyx.utils.multiplatform.SavedStateMap +import kotlin.test.Test +import kotlin.test.assertNotEquals + +class NodeTest { + @Test + fun WHEN_node_is_create_THEN_plugins_are_setup_as_expected() { + val savedStateMap: SavedStateMap = HashMap() + val node = RootNode(NodeContext.root(savedStateMap)) + + assertNotEquals(0, node.plugins.size, "Node should have some predefined plugins") + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index daf172cc1..4de97cc35 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -12,7 +12,7 @@ coil = "2.2.1" composePlugin = "1.6.1" composeBom = "2024.03.00" composeCompiler = "1.5.11" -coroutines = "1.6.4" +coroutines = "1.8.0" dependencyAnalysis = "1.27.0" detekt = "1.21.0" junit5 = "5.8.2" From d4b87a704246aded8d7e3dd37a15fc4658151d02 Mon Sep 17 00:00:00 2001 From: Manel Martos Date: Fri, 12 Apr 2024 15:24:45 +0200 Subject: [PATCH 3/7] Update CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0964237b2..e6e888808 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,11 +12,11 @@ - [#670](https://github.com/bumble-tech/appyx/pull/670) - Fixes ios lifecycle - [#673](https://github.com/bumble-tech/appyx/pull/673) – Fix canHandeBackPress typo - [#671](https://github.com/bumble-tech/appyx/issue/671) – Fix ui state saving issue +- [#694](https://github.com/bumble-tech/appyx/pull/694) – Fix appyxComponent state saving issue ### Enhancement - [#679](https://github.com/bumble-tech/appyx/pull/679) – Simple api for backStackNode and spotlightNode -- [#694](https://github.com/bumble-tech/appyx/pull/694) – appyxComponent state not restored after configuration changes --- From 06e6d4e0783b5f7bbeb12455dd427b248df0065a Mon Sep 17 00:00:00 2001 From: Manel Martos Date: Fri, 12 Apr 2024 15:58:46 +0200 Subject: [PATCH 4/7] Move test to UI --- .../bumble/appyx/helpers/DummyComponent.kt | 4 +-- .../appyx/helpers/DummyComponentModel.kt | 0 .../appyx/helpers/DummyVisualisation.kt | 0 .../com/bumble/appyx/helpers/RootNode.kt | 0 .../com/bumble/appyx/helpers/TargetUiState.kt | 0 .../bumble/appyx/navigation/node/NodeTest.kt | 25 +++++++++++++++++++ appyx-navigation/common/build.gradle.kts | 1 - .../bumble/appyx/navigation/node/NodeTest.kt | 17 ------------- 8 files changed, 27 insertions(+), 20 deletions(-) rename appyx-navigation/{common/src/commonTest => android/src/androidTest}/kotlin/com/bumble/appyx/helpers/DummyComponent.kt (92%) rename appyx-navigation/{common/src/commonTest => android/src/androidTest}/kotlin/com/bumble/appyx/helpers/DummyComponentModel.kt (100%) rename appyx-navigation/{common/src/commonTest => android/src/androidTest}/kotlin/com/bumble/appyx/helpers/DummyVisualisation.kt (100%) rename appyx-navigation/{common/src/commonTest => android/src/androidTest}/kotlin/com/bumble/appyx/helpers/RootNode.kt (100%) rename appyx-navigation/{common/src/commonTest => android/src/androidTest}/kotlin/com/bumble/appyx/helpers/TargetUiState.kt (100%) create mode 100644 appyx-navigation/android/src/androidTest/kotlin/com/bumble/appyx/navigation/node/NodeTest.kt delete mode 100644 appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/navigation/node/NodeTest.kt diff --git a/appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/helpers/DummyComponent.kt b/appyx-navigation/android/src/androidTest/kotlin/com/bumble/appyx/helpers/DummyComponent.kt similarity index 92% rename from appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/helpers/DummyComponent.kt rename to appyx-navigation/android/src/androidTest/kotlin/com/bumble/appyx/helpers/DummyComponent.kt index c35124d61..1b9a36962 100644 --- a/appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/helpers/DummyComponent.kt +++ b/appyx-navigation/android/src/androidTest/kotlin/com/bumble/appyx/helpers/DummyComponent.kt @@ -12,11 +12,11 @@ import com.bumble.appyx.interactions.ui.Visualisation import com.bumble.appyx.interactions.ui.context.TransitionBounds import com.bumble.appyx.interactions.ui.context.UiContext import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob -import kotlinx.coroutines.test.StandardTestDispatcher class DummyComponent( - scope: CoroutineScope = CoroutineScope(SupervisorJob() + StandardTestDispatcher()), + scope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main), val model: DummyComponentModel, visualisation: (UiContext) -> Visualisation>, animationSpec: AnimationSpec = spring(), diff --git a/appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/helpers/DummyComponentModel.kt b/appyx-navigation/android/src/androidTest/kotlin/com/bumble/appyx/helpers/DummyComponentModel.kt similarity index 100% rename from appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/helpers/DummyComponentModel.kt rename to appyx-navigation/android/src/androidTest/kotlin/com/bumble/appyx/helpers/DummyComponentModel.kt diff --git a/appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/helpers/DummyVisualisation.kt b/appyx-navigation/android/src/androidTest/kotlin/com/bumble/appyx/helpers/DummyVisualisation.kt similarity index 100% rename from appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/helpers/DummyVisualisation.kt rename to appyx-navigation/android/src/androidTest/kotlin/com/bumble/appyx/helpers/DummyVisualisation.kt diff --git a/appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/helpers/RootNode.kt b/appyx-navigation/android/src/androidTest/kotlin/com/bumble/appyx/helpers/RootNode.kt similarity index 100% rename from appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/helpers/RootNode.kt rename to appyx-navigation/android/src/androidTest/kotlin/com/bumble/appyx/helpers/RootNode.kt diff --git a/appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/helpers/TargetUiState.kt b/appyx-navigation/android/src/androidTest/kotlin/com/bumble/appyx/helpers/TargetUiState.kt similarity index 100% rename from appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/helpers/TargetUiState.kt rename to appyx-navigation/android/src/androidTest/kotlin/com/bumble/appyx/helpers/TargetUiState.kt diff --git a/appyx-navigation/android/src/androidTest/kotlin/com/bumble/appyx/navigation/node/NodeTest.kt b/appyx-navigation/android/src/androidTest/kotlin/com/bumble/appyx/navigation/node/NodeTest.kt new file mode 100644 index 000000000..c197c5c3a --- /dev/null +++ b/appyx-navigation/android/src/androidTest/kotlin/com/bumble/appyx/navigation/node/NodeTest.kt @@ -0,0 +1,25 @@ +package com.bumble.appyx.navigation.node + +import com.bumble.appyx.helpers.RootNode +import com.bumble.appyx.navigation.AppyxTestScenario +import com.bumble.appyx.navigation.modality.NodeContext +import org.junit.Assert.assertNotEquals +import org.junit.Rule +import org.junit.Test + +class NodeTest { + var nodeFactory: (nodeContext: NodeContext) -> Node<*> = { + RootNode(nodeContext = it) + } + + @get:Rule + val rule = AppyxTestScenario { nodeContext -> + nodeFactory(nodeContext) + } + + @Test + fun WHEN_node_is_create_THEN_plugins_are_setup_as_expected() { + rule.start() + assertNotEquals("Node should have some predefined plugins", 0, rule.node.plugins.size) + } +} diff --git a/appyx-navigation/common/build.gradle.kts b/appyx-navigation/common/build.gradle.kts index 88570c903..4b5df9db5 100644 --- a/appyx-navigation/common/build.gradle.kts +++ b/appyx-navigation/common/build.gradle.kts @@ -61,7 +61,6 @@ kotlin { val commonTest by getting { dependencies { implementation(kotlin("test")) - implementation(libs.kotlin.coroutines.test) } } val androidMain by getting { diff --git a/appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/navigation/node/NodeTest.kt b/appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/navigation/node/NodeTest.kt deleted file mode 100644 index 29fb4962b..000000000 --- a/appyx-navigation/common/src/commonTest/kotlin/com/bumble/appyx/navigation/node/NodeTest.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.bumble.appyx.navigation.node - -import com.bumble.appyx.helpers.RootNode -import com.bumble.appyx.navigation.modality.NodeContext -import com.bumble.appyx.utils.multiplatform.SavedStateMap -import kotlin.test.Test -import kotlin.test.assertNotEquals - -class NodeTest { - @Test - fun WHEN_node_is_create_THEN_plugins_are_setup_as_expected() { - val savedStateMap: SavedStateMap = HashMap() - val node = RootNode(NodeContext.root(savedStateMap)) - - assertNotEquals(0, node.plugins.size, "Node should have some predefined plugins") - } -} From b43149ed5fed7eec8ab6b3a9b5cd837291dace15 Mon Sep 17 00:00:00 2001 From: Manel Martos Date: Fri, 12 Apr 2024 17:11:13 +0200 Subject: [PATCH 5/7] Add extra test to make sure saveInstanceState has been invoked --- .../bumble/appyx/helpers/DummyComponent.kt | 14 ++++++++- .../com/bumble/appyx/helpers/RootNode.kt | 4 +-- .../bumble/appyx/navigation/node/NodeTest.kt | 29 +++++++++++++++++-- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/appyx-navigation/android/src/androidTest/kotlin/com/bumble/appyx/helpers/DummyComponent.kt b/appyx-navigation/android/src/androidTest/kotlin/com/bumble/appyx/helpers/DummyComponent.kt index 1b9a36962..1cc296fb7 100644 --- a/appyx-navigation/android/src/androidTest/kotlin/com/bumble/appyx/helpers/DummyComponent.kt +++ b/appyx-navigation/android/src/androidTest/kotlin/com/bumble/appyx/helpers/DummyComponent.kt @@ -8,6 +8,7 @@ import com.bumble.appyx.interactions.gesture.GestureSettleConfig import com.bumble.appyx.interactions.model.BaseAppyxComponent import com.bumble.appyx.interactions.model.backpresshandlerstrategies.BackPressHandlerStrategy import com.bumble.appyx.interactions.model.backpresshandlerstrategies.DontHandleBackPress +import com.bumble.appyx.interactions.state.MutableSavedStateMap import com.bumble.appyx.interactions.ui.Visualisation import com.bumble.appyx.interactions.ui.context.TransitionBounds import com.bumble.appyx.interactions.ui.context.UiContext @@ -35,4 +36,15 @@ class DummyComponent( backPressStrategy = backPressStrategy, defaultAnimationSpec = animationSpec, disableAnimations = disableAnimations -) +) { + var saveInstanceStateInvoked: Int = 0 + + fun resetSaveInstanceState() { + saveInstanceStateInvoked = 0 + } + + override fun saveInstanceState(state: MutableSavedStateMap) { + super.saveInstanceState(state) + saveInstanceStateInvoked += 1 + } +} diff --git a/appyx-navigation/android/src/androidTest/kotlin/com/bumble/appyx/helpers/RootNode.kt b/appyx-navigation/android/src/androidTest/kotlin/com/bumble/appyx/helpers/RootNode.kt index 31d0dd152..d54b32c0a 100644 --- a/appyx-navigation/android/src/androidTest/kotlin/com/bumble/appyx/helpers/RootNode.kt +++ b/appyx-navigation/android/src/androidTest/kotlin/com/bumble/appyx/helpers/RootNode.kt @@ -8,7 +8,7 @@ import com.bumble.appyx.navigation.node.node class RootNode( nodeContext: NodeContext, - dummyComponent: DummyComponent = DummyComponent( + appyxComponent: DummyComponent = DummyComponent( model = DummyComponentModel( initialTarget = NavTarget.Child1, savedStateMap = nodeContext.savedStateMap @@ -17,7 +17,7 @@ class RootNode( ) ) : Node( nodeContext = nodeContext, - appyxComponent = dummyComponent, + appyxComponent = appyxComponent, ) { sealed interface NavTarget { data object Child1 : NavTarget diff --git a/appyx-navigation/android/src/androidTest/kotlin/com/bumble/appyx/navigation/node/NodeTest.kt b/appyx-navigation/android/src/androidTest/kotlin/com/bumble/appyx/navigation/node/NodeTest.kt index c197c5c3a..974e71c47 100644 --- a/appyx-navigation/android/src/androidTest/kotlin/com/bumble/appyx/navigation/node/NodeTest.kt +++ b/appyx-navigation/android/src/androidTest/kotlin/com/bumble/appyx/navigation/node/NodeTest.kt @@ -1,5 +1,8 @@ package com.bumble.appyx.navigation.node +import com.bumble.appyx.helpers.DummyComponent +import com.bumble.appyx.helpers.DummyComponentModel +import com.bumble.appyx.helpers.DummyVisualisation import com.bumble.appyx.helpers.RootNode import com.bumble.appyx.navigation.AppyxTestScenario import com.bumble.appyx.navigation.modality.NodeContext @@ -8,8 +11,17 @@ import org.junit.Rule import org.junit.Test class NodeTest { - var nodeFactory: (nodeContext: NodeContext) -> Node<*> = { - RootNode(nodeContext = it) + private var appyxComponent: DummyComponent? = null + + private val nodeFactory: (nodeContext: NodeContext) -> Node<*> = { nodeContext -> + appyxComponent = DummyComponent( + model = DummyComponentModel( + initialTarget = RootNode.NavTarget.Child1, + savedStateMap = nodeContext.savedStateMap + ), + visualisation = { DummyVisualisation(it) } + ) + RootNode(nodeContext = nodeContext, appyxComponent = appyxComponent!!) } @get:Rule @@ -22,4 +34,17 @@ class NodeTest { rule.start() assertNotEquals("Node should have some predefined plugins", 0, rule.node.plugins.size) } + + @Test + fun WHEN_node_is_create_THEN_appyx_component_state_is_saved_during_recreation() { + rule.start() + appyxComponent!!.resetSaveInstanceState() + rule.activityScenario.recreate() + assertNotEquals( + "AppyxComponent state should be saved", + 0, + appyxComponent!!.saveInstanceStateInvoked + ) + } + } From c9cb504ad6408f22979ead023c294635dfcd4030 Mon Sep 17 00:00:00 2001 From: Manel Martos Date: Fri, 12 Apr 2024 17:15:29 +0200 Subject: [PATCH 6/7] Rollback coroutines version --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4de97cc35..b3656cfc2 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -12,7 +12,7 @@ coil = "2.2.1" composePlugin = "1.6.1" composeBom = "2024.03.00" composeCompiler = "1.5.11" -coroutines = "1.8.0" +coroutines = "1.6.3" dependencyAnalysis = "1.27.0" detekt = "1.21.0" junit5 = "5.8.2" From b54d89194ed2ce35da24be610596aa21216fe51b Mon Sep 17 00:00:00 2001 From: Manel Martos Date: Fri, 12 Apr 2024 17:38:20 +0200 Subject: [PATCH 7/7] Fix coroutine version --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b3656cfc2..daf172cc1 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -12,7 +12,7 @@ coil = "2.2.1" composePlugin = "1.6.1" composeBom = "2024.03.00" composeCompiler = "1.5.11" -coroutines = "1.6.3" +coroutines = "1.6.4" dependencyAnalysis = "1.27.0" detekt = "1.21.0" junit5 = "5.8.2"