Hi :) hope you are doing well. I am working on a...
# multiplatform
a
Hi :) hope you are doing well. I am working on a compose multi platform project (android,iOS) and I want to start a new activity/controller. Do you know the best approach to implement it? Guess I need an expect/actual approach but not sure what is the best on iOS (SwiftUI). Thanks in advance.
j
What's the reason you need a separate activity/controller? I've found it's easiest to keep things in a single Android Activity and iOS UIViewController and use Composable functions for separate screens. If this is possible, you'll probably find this easier than expect/actual for platform specific activity/controller navigation, unless you have existing native code you're bridging between.
a
I don’t need it, but it’s a way to keep code cleaner. In fact I am continuing with Compose. But I just wanted to know how do it if I require to separate responsibilities. I am migrating a native android app and it’s the first time I work with iOS and Compose, so I don’t know if compose handles memory in a better way, etc.
j
You should be able to keep Composables segregated and code clean in a similar way without using multiple Activities or UIViewControllers. You can separate by package or module. And how much memory is used is really dependent on what you use and retain between Composable screens.
👍 1
If you use the Compose Multiplatform template, it will ignore all configuration change events for reconstructing the Activity by default. So you can even avoid the need to retain state across configuration changes in most cases. You may still need to handle platform-specific lifecycle events for other reasons though.
👍 1
p
If Jeff didn't convince you to try to stay in compose land most of the time. To achieve what you want is as simple as defining a Callback interface in commonMain and as you mentioned do the actual implementation on each platform. Then you would pass it in
Copy code
composeApp(PlatformNavigationCallbackImpl)
as an input parameter.
👍 1
a
Thanks guys, Both are great opinions. I just want to learn about the different approaches, guess I will continue with Compose by this moment and master different things.
j
Even if you don't use it for navigating between activities/controllers, Pablichenko's guidance is always valuable for any dependency you need to pass down from native code. This way you can implement it in Swift for iOS if needed. If you implement in Kotlin, you can also expect/actual or inject a platform-specific interface implementation using something like Koin too.
👍 2
a
That’s valuable. Because always there is something native to implement and use within the common module.
💯 1