I am trying to render Compose on a share extension...
# compose-ios
a
I am trying to render Compose on a share extension. No matter what I tried, the view renders black. Any ideas how to tackle this? (code in 🧵 )
I tried creating a Swift UI view and include a ComposeUIController in there:
Copy code
class ShareViewController: UIViewController {
...
override func viewDidLoad() {
        super.viewDidLoad()

        //... at the end of viewDidLoad()
        let rootView = ComposeView()
                        .frame(maxWidth: .infinity, maxHeight: .infinity)
                        .background(.blue)
        let controller = UIHostingController(rootView: rootView)
        
        let controller = controller
        controller.view.frame = self.view.bounds
        controller.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        controller.view.backgroundColor = .clear
        
        addChild(controller)
        view.addSubview(controller.view)
        controller.didMove(toParent: self)
    }
}

struct ComposeView: UIViewControllerRepresentable {
    func makeUIViewController(context: Context) -> UIViewController {
        MainViewControllerKt.MainViewController()
    }

    func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
}
I also tried using the
MainViewController()
directly instead of creating a
UIHostingController
and the results are identical.