Hi, is it correct that MainViewController is calle...
# compose-ios
j
Hi, is it correct that MainViewController is called twice of the compose-multiplatform-ios-android template? More in thread:
If I run the app for iOS the code within main.ios.kt is called twice:
Copy code
fun MainViewController() = ComposeUIViewController {

    println("MainViewController")

    App()
}
and my log output is:
Copy code
Debugger attached to process 44790
MainViewController
MainViewController
l
Composable functions can be called as many times as the Composer decides is necessary. Any side effects should be using LanchedEffect or some other Effect.
j
hm ... but thats not a composable function.
ok, got it. my MainViewController was wrong:
Copy code
fun MainViewController(): UIViewController {
    
    println("MainViewController")

    return ComposeUIViewController {
        App()
    }

}
s
@Jan i'm facing a similar problem. Did you also face it? https://kotlinlang.slack.com/archives/C0346LWVBJ4/p1695918487627549
l
The ComposeUIViewController block is a composable lambda. Composable lambdas can be called any time the composer decides to. I know the ViewController handles some iOS state internally, so it's possible it decides to update some theme or something after the first composition, triggering another. This is what you are seeing, and is within allowed behavior for the composer.