Does Compose multiplatform has interop to SwiftUI ...
# compose-ios
j
Does Compose multiplatform has interop to SwiftUI View somewhow? I found UIKitView interop, but was crazy ugly convert SwiftUi to that interop view:
Copy code
struct MainScreen<Content>: UIViewControllerRepresentable where Content : View {

    var view: Content
    init(content: () -> Content) {
        view = content()
    }

    func makeUIViewController(context: Context) -> some UIViewController {
        let size = CGSize(width: 400, height: 400)
        let sizeSubView = CGSize(width: 200, height: 200)

        let uiView = UIView(frame: CGRect(origin: .zero, size: size))
        uiView.backgroundColor = .systemBlue

        // this will be a container view for the Swift UI View
        let centerPointForSubView = CGRect(origin: CGPoint(x: 100, y: 100), size: sizeSubView)
        let uiViewSubView = UIView(frame: centerPointForSubView)
        uiViewSubView.backgroundColor = .white

        uiView.addSubview(uiViewSubView)
        let host = UIHostingController(rootView: view)
        let hostView = host.view!
        uiViewSubView.addSubview(hostView)
        return ScreenProvider.shared.createMainScreenController(uiView: hostView)
    }

    func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {}
}
Would like to avoid this 😄
K 1
👍 1
l
struct YourComposableToSwiftUI: UIViewControllerRepresentable { func makeUIViewController(context: Context) -> UIViewController { return YourComposableHere() } func updateUIViewController(_ uiViewController: UIViewController, context: Context) { } }
j
I need it in other direction. Need send in SwiftUi to compose 😁 what typed @Louis what I have wrapped around this.
d
We have a sample with interop inside SwiftUI here: https://github.com/JetBrains/compose-multiplatform/tree/master/examples/chat
j
@Dima Avdeev Thanks! Is it one of these files? https://github.com/JetBrains/compose-multiplatform/tree/master/examples%2Fchat%2FiosApp%2FiosApp I cant find any sample how send SwiftUi View to Kotlin? In my scenario A having a Compose slot API B and C, where creating A from Swift ui controller and send in slot B into it from a sub block swift ui. Needed to mix navigation container and tab content between iOS and Android.
d
Yes
j
In that case I cant find any code that refer to send SwiftUi back to Compose anywhere, only the other direction with ComposeUiController etc. Or which code block refer to having this?
In my scenario I am doing this:
Copy code
fun createMainScreenController(uiView: UIView, onLogin: () -> Unit) = ComposeUIViewController {
        MainScreen(
            mainViewModel = MainViewModel(),
            authContent = {
                UIKitView(
                    factory = { uiView },
                    modifier = Modifier.fillMaxSize(),
                )
            },
            loginContent = {
                LoginScreen(UsernameLoginViewModel(), onLogin)
            },
        )
    }
Mixing Compose and UiView in both directions nested. Here using UiKitView not supporting SwiftUi to have interop in compose for uikit. I want equivalent but fro SwiftUI View instead 🙂 Or some better way of doing it at least.
d
Yeah, for now it is not possible to use SwiftUI inside Compose. It is only possible to use UIKitView inside Compose.
j
Thanks, so not possible. Glad to hear I am not looked in wrong places then. Hopefully androidx navigation will become multiplatform soon or Decompose improved so I dont need this :)
d
As I understand, it is very hard to make androidx navigation multiplatform. (But I actually don't know exact plans)
j
https://issuetracker.google.com/issues/281774647 Some discussions around it. The main issue make compose viewmodel/lifecycle non Android SDK I think. I am not sure which library get first. I wished I have more time, would think about code it myself :)
746 Views