https://kotlinlang.org logo
#compose-ios
Title
# compose-ios
s

Shoaib khalid

09/28/2023, 4:28 PM
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

Alejandro Rios

09/28/2023, 4:33 PM
s

Shoaib khalid

09/28/2023, 4:37 PM
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

Pablichjenkov

09/28/2023, 4:50 PM
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

Shoaib khalid

09/28/2023, 4:52 PM
@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

Pablichjenkov

09/28/2023, 4:54 PM
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

Shoaib khalid

09/28/2023, 4:59 PM
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

Pablichjenkov

09/28/2023, 5:12 PM
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

mohamed rejeb

09/28/2023, 6:12 PM
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

Arkadii Ivanov

09/28/2023, 10:34 PM
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

Pablichjenkov

09/29/2023, 3:46 AM
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

Shoaib khalid

10/18/2023, 12:08 PM
p

Pablichjenkov

10/18/2023, 1:38 PM
Ah great 😃
9 Views