Hi! I have next construction to provide compose sc...
# compose-ios
v
Hi! I have next construction to provide compose screen to iOS: iOSmain module:
Copy code
actual class Platform actual constructor() {
    actual val platform: String = UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion
    public fun UserInfoViewController() = ComposeUIViewController { Profile() }
}
in iOS project when navigate to viewController let view = Platform().UserInfoViewController() But in does not work - I see empty screen but compose code in android work correctly. What else need to add that screen correctly show?
👍 1
d
Hello! You also need to add this UIViewController to view hierarchy. Like this on SwiftUI: https://github.com/JetBrains/compose-multiplatform-template/blob/main/iosApp/iosApp/ContentView.swift#L5 Or, if you want to add it without SwiftUI, you can write something similar like this:
Copy code
// some standart iOS logic to initialize Application and window:
let window = UIWindow(...) 
...
// adding Compose:
window.rootViewController = Platform().UserInfoViewController()
The easiest way is to start from our templates: https://github.com/JetBrains/compose-multiplatform-template
v
Ok, but if need add ComposeUIViewController as a child, not root - is it possible?
c
You can add ComposeUIViewController as a child. Actually, you can even add ComposeUIViewController as a child of another ComposeUIViewController like the following:
Copy code
@Composable
fun ModalSheet(content: @Composable () -> Unit) {
  val modalSheetController = remember {
    ComposeUIViewController {
      MaterialTheme(content = content)
    }
  }
  val uiViewController = LocalUIViewController.current
  DisposableEffect(uiViewController, modalSheetController) {
    uiViewController.presentViewController(modalSheetController, animated = true, completion = null)
    onDispose { ... }
  }
}
d
Ok, but if need add ComposeUIViewController as a child, not root - is it possible?
For now it is not working good with UIKit. But, you can use Compose as as Child with SwiftUI technology like in our samples: https://github.com/JetBrains/compose-multiplatform/blob/master/examples/chat/iosApp/iosApp/ComposeInsideSwiftUIScreen.swift#L18