When considering using CMP with a kmp navigation library, a CMP view inside SwiftUi Navigation, combinations of SwiftUI & CMP, etc. - how can go about understanding the implications for "life cycle" management?
I'm already using KMP (with Koin) for shared business logic supporting a SwiftUI and Android Compose app. I'm now considering adding some new screens written in CMP. However, I'm not sure what questions I should be asking to understand the implications. Does anyone have any recommendations on what I can search / read up on to understand this more?
k
Karen Frangulyan
01/16/2025, 12:18 AM
I started my hobby project with KMP and CMP and only after a month into the development I realized that the project template I started with actually had all the configuration changes on Android disabled. I was looking into it since at some points I started wondering why is a simple ‘remember’ doing a great job while it should’ve been ‘rememberSaveable’.
Now it is still useful in case you use the rest of the multiplatform libraries, like navigation, viewmodel, etc (and even savedstatehandle, which sounds very android-specific). But when you have all these weird configuration changes out of your way (even though Google says you still cannot turn them all off), the conceptual part of the View/Composable lifecycle becomes pretty similar on both platforms. Basically, boils down to “Appearing/Entering Composition”, “Updating/Recomposing” and “Disappearing/Leaving Composition”.
The answer depends on how are you going to use that CMP composable on different platforms. In my case my whole app is in CMP, but you will most probably wrap it in some kind of container and put it into your SwiftUI hierarchy (haven’t done this till now). So this container will most probably do the lifecycle “translation” between SwiftUI and Compose.
As for resources, here are some really good ones from TouchLab:
First, a talk on using CMP and SwiftUI together: