From 6aee62de2f9662044a9e054d7d84ff7841e4cb93 Mon Sep 17 00:00:00 2001 From: andreykovalev Date: Sat, 21 Jan 2023 11:50:53 +0000 Subject: [PATCH 1/4] Ensure node was build before using API --- .../core/src/main/kotlin/com/bumble/appyx/core/node/Node.kt | 6 +++++- .../main/kotlin/com/bumble/appyx/core/node/ParentNode.kt | 1 + .../com/bumble/appyx/testing/ui/rules/AppyxViewTestRule.kt | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/libraries/core/src/main/kotlin/com/bumble/appyx/core/node/Node.kt b/libraries/core/src/main/kotlin/com/bumble/appyx/core/node/Node.kt index 1a05bfee2..721864551 100644 --- a/libraries/core/src/main/kotlin/com/bumble/appyx/core/node/Node.kt +++ b/libraries/core/src/main/kotlin/com/bumble/appyx/core/node/Node.kt @@ -75,7 +75,7 @@ open class Node( field = value } - private var wasBuilt = false + protected var wasBuilt = false val id = getNodeId(buildContext) @@ -230,6 +230,10 @@ open class Node( private fun handleUpNavigationByPlugins(): Boolean = plugins().any { it.handleUpNavigation() } + protected fun ensureNodeWasBuilt() { + require(wasBuilt) { "Node hasn't been built yet" } + } + companion object { private const val NODE_ID_KEY = "node.id" diff --git a/libraries/core/src/main/kotlin/com/bumble/appyx/core/node/ParentNode.kt b/libraries/core/src/main/kotlin/com/bumble/appyx/core/node/ParentNode.kt index 11a83c151..a1c7ddeb9 100644 --- a/libraries/core/src/main/kotlin/com/bumble/appyx/core/node/ParentNode.kt +++ b/libraries/core/src/main/kotlin/com/bumble/appyx/core/node/ParentNode.kt @@ -101,6 +101,7 @@ abstract class ParentNode( navTarget: NavTarget, decorator: @Composable (child: ChildRenderer) -> Unit ) { + ensureNodeWasBuilt() LaunchedEffect(navTarget) { permanentNavModel.addUnique(navTarget) } diff --git a/libraries/testing-ui/src/main/kotlin/com/bumble/appyx/testing/ui/rules/AppyxViewTestRule.kt b/libraries/testing-ui/src/main/kotlin/com/bumble/appyx/testing/ui/rules/AppyxViewTestRule.kt index 5b3db45cd..7421e07fc 100644 --- a/libraries/testing-ui/src/main/kotlin/com/bumble/appyx/testing/ui/rules/AppyxViewTestRule.kt +++ b/libraries/testing-ui/src/main/kotlin/com/bumble/appyx/testing/ui/rules/AppyxViewTestRule.kt @@ -9,6 +9,7 @@ import androidx.test.rule.ActivityTestRule import com.bumble.appyx.core.node.LocalNode import com.bumble.appyx.core.node.NodeView import com.bumble.appyx.core.node.ViewFactory +import com.bumble.appyx.core.node.build import com.bumble.appyx.testing.ui.utils.DummyParentNode import org.junit.rules.TestRule import org.junit.runner.Description @@ -47,7 +48,7 @@ open class AppyxViewTestRule( override fun beforeActivityLaunched() { AppyxTestActivity.composableView = { CompositionLocalProvider( - LocalNode provides DummyParentNode(), + LocalNode provides DummyParentNode().build(), ) { view.View(modifier = Modifier) } From 41eef35b2655e1eef6b0da4cbef49528380aec94 Mon Sep 17 00:00:00 2001 From: andreykovalev Date: Sat, 21 Jan 2023 12:15:22 +0000 Subject: [PATCH 2/4] Revert the check --- .../core/src/main/kotlin/com/bumble/appyx/core/node/Node.kt | 6 +----- .../main/kotlin/com/bumble/appyx/core/node/ParentNode.kt | 1 - 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/libraries/core/src/main/kotlin/com/bumble/appyx/core/node/Node.kt b/libraries/core/src/main/kotlin/com/bumble/appyx/core/node/Node.kt index 721864551..1a05bfee2 100644 --- a/libraries/core/src/main/kotlin/com/bumble/appyx/core/node/Node.kt +++ b/libraries/core/src/main/kotlin/com/bumble/appyx/core/node/Node.kt @@ -75,7 +75,7 @@ open class Node( field = value } - protected var wasBuilt = false + private var wasBuilt = false val id = getNodeId(buildContext) @@ -230,10 +230,6 @@ open class Node( private fun handleUpNavigationByPlugins(): Boolean = plugins().any { it.handleUpNavigation() } - protected fun ensureNodeWasBuilt() { - require(wasBuilt) { "Node hasn't been built yet" } - } - companion object { private const val NODE_ID_KEY = "node.id" diff --git a/libraries/core/src/main/kotlin/com/bumble/appyx/core/node/ParentNode.kt b/libraries/core/src/main/kotlin/com/bumble/appyx/core/node/ParentNode.kt index a1c7ddeb9..11a83c151 100644 --- a/libraries/core/src/main/kotlin/com/bumble/appyx/core/node/ParentNode.kt +++ b/libraries/core/src/main/kotlin/com/bumble/appyx/core/node/ParentNode.kt @@ -101,7 +101,6 @@ abstract class ParentNode( navTarget: NavTarget, decorator: @Composable (child: ChildRenderer) -> Unit ) { - ensureNodeWasBuilt() LaunchedEffect(navTarget) { permanentNavModel.addUnique(navTarget) } From bf898d2b29fc800d02d3866073d638807db4a43c Mon Sep 17 00:00:00 2001 From: andreykovalev Date: Sat, 21 Jan 2023 12:47:21 +0000 Subject: [PATCH 3/4] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62a8ead2f..537df5efb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Pending changes -– +- [#325](https://github.com/bumble-tech/appyx/pull/325) – **Fixes**: Crash when using PermanentChild API in View testing --- From 8951f466d055568ac45d5b39de98289bb11b8b2e Mon Sep 17 00:00:00 2001 From: Andrey Kovalev Date: Sat, 21 Jan 2023 13:18:20 +0000 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 537df5efb..6e79ad203 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Pending changes -- [#325](https://github.com/bumble-tech/appyx/pull/325) – **Fixes**: Crash when using PermanentChild API in View testing +- [#325](https://github.com/bumble-tech/appyx/pull/325) – **Fixed**: Crash when using PermanentChild API in View testing ---