Ahmad Hassan
10/19/2023, 12:00 PMIvan Matkov
10/19/2023, 12:33 PMandroidx.lifecycle.* is currently Android-onlyAhmad Hassan
10/19/2023, 1:11 PMIvan Matkov
10/19/2023, 1:17 PMArkadii Ivanov
10/19/2023, 4:32 PMArkadii Ivanov
10/19/2023, 4:35 PMAhmad Hassan
10/26/2023, 11:34 AMArkadii Ivanov
10/26/2023, 11:41 AMAhmad Hassan
10/28/2023, 1:04 PMAhmad Hassan
10/28/2023, 1:15 PMArkadii Ivanov
10/28/2023, 2:09 PMLifecycleRegistry . Then just override applicationDidBecomeActive , applicationWillResignActive and applicationWillTerminate and drive the lifecycle. Take a look here.
Then you can create a composition local for Lifecycle so that it's available in every Composable.Arkadii Ivanov
10/28/2023, 2:12 PMComposeUIViewController {} function, then there is now the delegate property that can be used instead.Ahmad Hassan
10/28/2023, 4:15 PMArkadii Ivanov
10/28/2023, 4:58 PMComposeUIViewController {
val lifecycle = remember { LifecycleRegistry() }
delegate =
object : ComposeUIViewControllerDelegate {
override fun viewWillAppear() {
lifecycle.resume()
}
override fun viewDidDisappear() {
lifecycle.stop()
}
}
// The rest of the code
}
Though, I don't see any callback equivalent to onDestroy. In Swift we have deinit. So perhaps you could create and control the lifecycle in Swift and then just pass it to Compose and make it available with a composition local.
Or, if you have just one Composable for the entire app, then you can implement UIApplicationDelegate instead, which gives applicationWillTerminate callback.Ahmad Hassan
10/28/2023, 5:07 PM