From 5486e17190b27cc25a395c9f8d277e8a03452dcd Mon Sep 17 00:00:00 2001 From: Elijah Semyonov Date: Thu, 29 Feb 2024 15:36:31 +0100 Subject: [PATCH 1/4] Call setContent once on mediator creation. --- .../androidx/compose/ui/window/ComposeContainer.uikit.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/window/ComposeContainer.uikit.kt b/compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/window/ComposeContainer.uikit.kt index f6298cfbccc92..323a641a12f00 100644 --- a/compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/window/ComposeContainer.uikit.kt +++ b/compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/window/ComposeContainer.uikit.kt @@ -324,10 +324,10 @@ internal class ComposeContainer( composeSceneFactory = ::createComposeScene, ).also { this.mediator = it - } - mediator.setContent { - ProvideContainerCompositionLocals(this) { - content() + it.setContent { + ProvideContainerCompositionLocals(this) { + content() + } } } mediator.setLayout(SceneLayout.UseConstraintsToFillContainer) From f990e766e8fd5835794f360d9cdfb7dde728c2da Mon Sep 17 00:00:00 2001 From: Elijah Semyonov Date: Thu, 29 Feb 2024 15:52:18 +0100 Subject: [PATCH 2/4] Perform minor refactor --- .../androidx/compose/ui/window/ComposeContainer.uikit.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/window/ComposeContainer.uikit.kt b/compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/window/ComposeContainer.uikit.kt index 323a641a12f00..7573ae13c45e1 100644 --- a/compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/window/ComposeContainer.uikit.kt +++ b/compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/window/ComposeContainer.uikit.kt @@ -233,7 +233,7 @@ internal class ComposeContainer( super.viewWillAppear(animated) isInsideSwiftUI = checkIfInsideSwiftUI() - setContent(content) + createMediatorIfNeeded() configuration.delegate.viewWillAppear(animated) } @@ -313,7 +313,7 @@ internal class ComposeContainer( ) } - private fun setContent(content: @Composable () -> Unit) { + private fun createMediatorIfNeeded() { val mediator = mediator ?: ComposeSceneMediator( container = view, configuration = configuration, From 6d38676ab5bdca1572181e4c26000707a0882d1a Mon Sep 17 00:00:00 2001 From: Elijah Semyonov Date: Thu, 29 Feb 2024 15:52:50 +0100 Subject: [PATCH 3/4] Perform minor refactor --- .../androidx/compose/ui/window/ComposeContainer.uikit.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/window/ComposeContainer.uikit.kt b/compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/window/ComposeContainer.uikit.kt index 7573ae13c45e1..dc092788f166a 100644 --- a/compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/window/ComposeContainer.uikit.kt +++ b/compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/window/ComposeContainer.uikit.kt @@ -325,9 +325,7 @@ internal class ComposeContainer( ).also { this.mediator = it it.setContent { - ProvideContainerCompositionLocals(this) { - content() - } + ProvideContainerCompositionLocals(this, content) } } mediator.setLayout(SceneLayout.UseConstraintsToFillContainer) From 9b30afcba330e4ceaa8ca6d8099b9b599b5dfa87 Mon Sep 17 00:00:00 2001 From: Elijah Semyonov Date: Fri, 1 Mar 2024 10:27:08 +0100 Subject: [PATCH 4/4] Do minor refactor --- .../compose/ui/window/ComposeContainer.uikit.kt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/window/ComposeContainer.uikit.kt b/compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/window/ComposeContainer.uikit.kt index dc092788f166a..4bb608d12a6b0 100644 --- a/compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/window/ComposeContainer.uikit.kt +++ b/compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/window/ComposeContainer.uikit.kt @@ -314,7 +314,13 @@ internal class ComposeContainer( } private fun createMediatorIfNeeded() { - val mediator = mediator ?: ComposeSceneMediator( + if (mediator == null) { + mediator = createMediator() + } + } + + private fun createMediator(): ComposeSceneMediator { + val mediator = ComposeSceneMediator( container = view, configuration = configuration, focusStack = focusStack, @@ -322,13 +328,12 @@ internal class ComposeContainer( coroutineContext = coroutineDispatcher, renderingUIViewFactory = ::createSkikoUIView, composeSceneFactory = ::createComposeScene, - ).also { - this.mediator = it - it.setContent { - ProvideContainerCompositionLocals(this, content) - } + ) + mediator.setContent { + ProvideContainerCompositionLocals(this, content) } mediator.setLayout(SceneLayout.UseConstraintsToFillContainer) + return mediator } private fun dispose() {