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

Alex Styl

03/20/2024, 11:32 AM
How can I use Compose from a Share Extension app? I am using this code in my UiController
viewDidLoad
but all I get is a blank screen when I share to my app
Copy code
DispatchQueue.main.async {
            // host the SwiftU view
            let contentView : UIViewController = MainViewControllerKt.ShareViewController()

            self.addChild(contentView)
            self.view.addSubview(contentView.view)

            // set up constraints
            contentView.view.translatesAutoresizingMaskIntoConstraints = false
            contentView.view.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true
            contentView.view.bottomAnchor.constraint (equalTo: self.view.bottomAnchor).isActive = true
            contentView.view.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
            contentView.view.rightAnchor.constraint (equalTo: self.view.rightAnchor).isActive = true
        }
Copy code
// MainViewController.kt

fun ShareViewController() = ComposeUIViewController {
    MaterialTheme {
        Text(
            text = "Deep Linking App",
            modifier = Modifier.background(Color.White).fillMaxSize()
        )
    }
}
3 Views