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 993bac2f4fcc7..eedbf3d66dd1f 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 @@ -84,10 +84,10 @@ internal class ComposeContainer( * Initial value is arbitrarily chosen to avoid propagating invalid value logic * It's never the case in real usage scenario to reflect that in type system */ - val interfaceOrientationState: MutableState = mutableStateOf( + private val interfaceOrientationState: MutableState = mutableStateOf( InterfaceOrientation.Portrait ) - val systemThemeState: MutableState = mutableStateOf(SystemTheme.Unknown) + private val systemThemeState: MutableState = mutableStateOf(SystemTheme.Unknown) private val focusStack: FocusStack = FocusStackImpl() private val windowInfo = WindowInfoImpl().also { it.isWindowFocused = true @@ -260,13 +260,25 @@ internal class ComposeContainer( } composeSceneMediator = mediator mediator.setContent { - ProvideContainerCompositionLocals(this) { + ProvideContainerCompositionLocals { content() } } mediator.setLayout(SceneLayout.UseConstraintsToFillContainer) } + @OptIn(InternalComposeApi::class) + @Composable + internal fun ProvideContainerCompositionLocals(content: @Composable () -> Unit) = + CompositionLocalProvider( + LocalUIViewController provides this, + LocalLayerContainer provides view, + LocalInterfaceOrientation provides interfaceOrientationState.value, + LocalSystemTheme provides systemThemeState.value, + content = content + ) + + private fun dispose() { composeSceneMediator?.dispose() composeSceneMediator = null @@ -380,18 +392,3 @@ private fun getLayoutDirection() = UIUserInterfaceLayoutDirection.UIUserInterfaceLayoutDirectionRightToLeft -> LayoutDirection.Rtl else -> LayoutDirection.Ltr } - -@OptIn(InternalComposeApi::class) -@Composable -internal fun ProvideContainerCompositionLocals( - composeContainer: ComposeContainer, - content: @Composable () -> Unit, -) = with(composeContainer) { - CompositionLocalProvider( - LocalUIViewController provides this, - LocalLayerContainer provides view, - LocalInterfaceOrientation provides interfaceOrientationState.value, - LocalSystemTheme provides systemThemeState.value, - content = content - ) -} diff --git a/compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/window/UIViewComposeSceneLayer.uikit.kt b/compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/window/UIViewComposeSceneLayer.uikit.kt index f2a24dea8842c..b58e6f51f043c 100644 --- a/compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/window/UIViewComposeSceneLayer.uikit.kt +++ b/compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/window/UIViewComposeSceneLayer.uikit.kt @@ -94,7 +94,7 @@ internal class UIViewComposeSceneLayer( override fun setContent(content: @Composable () -> Unit) { mediator.setContent { - ProvideContainerCompositionLocals(composeContainer) { + composeContainer.ProvideContainerCompositionLocals { content() } }