how would i override things like `shouldAutorotate...
# compose-ios
d
how would i override things like
shouldAutorotate
and
supportedInterfaceOrientations
when using
androidx.compose.ui.window.ComposeUIViewController
?
a
Unfortunately, for now there is no official way to do it. We're working to bring this ability. A workaround is to override these fields in the parent view controller of
ComposeUIViewController
.
d
ok, thanks for the response. unfortunately i am not too deep into IOS development. do you know any public example that uses a parent controller in conjunction with compose multiplatform
a
That depends on your usecase. What's the way you're presenting your compose controller? or you can check this example: https://pradeepkashyap.medium.com/addchild-and-didmove-methods-in-swift-in-details-d8649a06621d here, child controller will be your ComposeUIViewController
d
well, basically i have the generated code from the multiplatform wizard
Copy code
import SwiftUI
import ComposeApp

@main
struct iOSApp: App {
    init() {
        KoinBootstrapperKt.doInitKoin()
    }

    var body: some Scene {
        WindowGroup {
            ContentView().preferredColorScheme(.dark)
        }
    }
}
and:
Copy code
import UIKit
import SwiftUI
import ComposeApp

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

    func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
}

struct ContentView: View {
    var body: some View {
        ComposeView().ignoresSafeArea()
    }
}
my usecase is that i want to force the screen orientation dynamically
a
my usecase is that i want to force the screen orientation dynamically
Oh, that's a bad idea on iOS... never worked as intended. But if you want to try it, it's here:
Copy code
func makeUIViewController(context: Context) -> UIViewController {
        ParentViewController(child: MainViewControllerKt.MainViewController())
    }
And then:
Copy code
class ParentViewController: UIViewController {
    val child: UIViewController
    init(child: UIViewController) {
         self.child = child
    }

    func viewDidLoad() {
         // Here does code from the article
    }

    // override var supportedInterfaceOrientations.... 
}
d
thanks a lot, i will try