created a Compose Multiplatform project form <Comp...
# compose-ios
s
created a Compose Multiplatform project form Compose Multiplatform Wizard. When i ran it on ios simulator it called the
ComposeUIViewController
callback twice, though
MainViewController
called only once. I've following code in my
composeApp/src/iosMain/kotlin/main.kt
Copy code
fun MainViewController(systemAppearance: (isLight: Boolean) -> Unit): UIViewController {
    println("Outside ComposeUIViewController")

    return ComposeUIViewController {
        println("Inside ComposeUIViewController")
        App() }
}
below is the output.
a
s
Thanks @Alejandro Rios but in my case MainViewController is called once but ComposeUiViewController is called twice which is weird. I don't know if it's default behaviour or something else.
p
I think you are printing any time it recomposes. In compose a Composable down the tree can perfectly trigger recomposition in its parents scope.
s
@Pablichjenkov App() composable is empty so there's no chance it's gonna recompose.
Copy code
@Composable
internal fun App(){
}
whenever i run app it calls ComposeUiViewController lambda twice.
p
Yeah sounds like it shouldn't do it but internally it may trigger recomposition. I started noticing that I believe after Safe area modifiers were added
Perhaps they need 2 compositions to compute some layout values. But let's wait if someone comes up with a better response
s
if that's the case it'll be a big disappointment as it's so weird.
Is it the same case with your compose multiplatform project?
p
I will let you know but most likely. Far from the Mac now I will verify later. But I believe last time I checked same thing. I don't care much about recompositions to be honest. Although I agree that minimizing them is important.
👍 2
m
what about priniting inside a LaunchedEffect it's more important but having 2 recompositions is not a big deal, the second recomposition could be ignored by childs.
👍 1
a
There shouldn't be any issues as long as there is only one composition. I.e. all
remember
-ed values are retained,
DisposableEffect.onDispose
is not called, etc.
👍 2
p
So yes Shoaib just checked and on my side, I see the same behaviour. Notice it only happens the first time the App launches. Subsequent calls of ViewDidDisappear/ViewDidAppear don’t print anything. LaunchEffect printed only once as expected too.
👍 1
s
p
Ah great 😃