I'm trying to use ComposeUIViewControllerDelegate ...
# kotlin-native
t
I'm trying to use ComposeUIViewControllerDelegate so that I can create a cross platform lifecycle to use for with my common components. I'm noticing that viewDidLoad(), viewWillAppear(), and viewDidAppear() get called, but not viewWillDisappear() or viewDidDisappear(). Is this a known issue or did I miss a configuration setting?
Copy code
val log = KotlinDependencies.getLogger("ComposeUIViewController")
return ComposeUIViewController( configure = {
    /**
     * A delegate to track composeViewControllers lifecycle callbacks
     */
    delegate = object : ComposeUIViewControllerDelegate {
        override fun viewDidAppear(animated: Boolean) {
            super.viewDidAppear(animated)
            log.i("lifecycleCallback: sending onResume}")
        }
        override fun viewDidLoad() {
            super.viewDidLoad()
            log.i("lifecycleCallback: sending onCreate}")
        }
        override fun viewWillDisappear(animated: Boolean) {
            super.viewWillDisappear(animated)
            log.i("lifecycleCallback: sending onPause}")
        }
        override fun viewWillAppear(animated: Boolean) {
            super.viewWillAppear(animated)
            log.i("lifecycleCallback: sending onStart}")
        }
        override fun viewDidDisappear(animated: Boolean) {
            super.viewDidDisappear(animated)
            log.i("lifecycleCallback: sending onDestroy}")
        }
    }
}) { App() }
p
Are you using swift-ui
t
No. I'm using Compose Multiplatform
p
But I mean, the integration is using swift-ui or UiKit?
t
SwiftUI to integrate
The view for the app uses code like this:
Copy code
struct ComposeView: UIViewControllerRepresentable {
    func makeUIViewController(context: Context) -> UIViewController {
        Main_iosKt.MainViewController()
    }

    func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
}
The MainViewController() returns the code from my first block.
p
Last time I tried I remember a a problem where UiViewControllerRepresentable don't receive the proper lifecycle events. Is a problem in the Apple API
I am trying to find the issue in compose multiplatform repo
👍 1
Check bellow issue: https://github.com/JetBrains/compose-multiplatform/issues/3462#issuecomment-1901579032 I ended up using the new approach, which is basically the port of Android Lifecycle API to KMP
t
Thank you
👍 1