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

Shoaib khalid

10/22/2023, 10:07 AM
How can i override activity lifecycle methods in a composable? i've a composable called "HomeScreen" now i want to have all activity lifecycle methods in it. Currently i've ios and android in commonMain.
d

Dima Avdeev

10/30/2023, 3:01 AM
in iOS where are no Activity. Is's analogue calls UIViewController. For Android you can read Android docs. You need to use Lifecycle callbacks. https://developer.android.com/guide/components/activities/activity-lifecycle For iOS you can use this approach:
Copy code
ComposeUIViewController(
    configure = {
        delegate = object: ComposeUIViewControllerDelegate {
            override fun viewDidLoad() {
                // Some reaction
            }
            override fun viewWillAppear(animated: Boolean) {
                // Some reaction
            }
            override fun viewDidAppear(animated: Boolean) {
                // Some reaction
            }
            override fun viewWillDisappear(animated: Boolean) {
                // Some reaction
            }
            override fun viewDidDisappear(animated: Boolean) {
                // Some reaction
            }
        }
    }
) {
    Text("Here your Compose code")
}
3 Views