Compose multi platform with several activities

Hi everyone !

From native Android development, I’m just beginning compose multiplatform. I would like to know if it’s possible to have multiple activities in my app.

I managed to do it on Android part with classical Intent.
However, is it possible to do it on iOS part (I don’t know anything about this language). Should I have another ComposeUIViewController like the MainViewController ? If so, how to navigate from the MainViewController to my second one ?

Thank you :slightly_smiling_face:

Of course it is possible:
declare expect/actual fun launchSecondScreeen() where actual android implementation will send broadcast action which is handled by second activity(declared in intent-filter in AndroidManifest.xml)
When second activity is launched then like in the first activity just setContentView { ComposeFun() }

Hmmm OK, I think I see about Android. What about iOS ?

i am not familiar with ios, but this approach is abstract, for example for desktop method launchSecondScreen will launch separate Window with its own Compose root function. So, you just need to adapt launchSecondScreen to ios api available to control window stack.

OK, so I tried some things, looking on internet and documentation. I think I’m almost good…
Here where I am now :

Common interface :

expect interface Navigator {
    fun navigateToSecondActivity()
}

Android implementation : It works :white_check_mark:

actual interface Navigator {
    actual fun navigateToSecondActivity()
}

class AndroidNavigator(private val context: Context) : Navigator {
  override fun navigateToSecondActivity() {
      val intent = Intent(context, SecondActivity::class.java)
      context.startActivity(intent)
    }
}

IOS implementation :

actual interface Navigator {
    actual fun navigateToSecondActivity()
}

class IosNavigator : Navigator {

    private var rootViewController: UIViewController? = null

    fun bind(rootViewController: UIViewController) {
        this.rootViewController = UIViewController()
    }


    override fun navigateToSecondActivity() {
        val secondViewController = SecondViewController()
        rootViewController?.presentViewController(
            secondViewController,
            animated = true,
            completion = null
        )
    }
}

Then, I have this for the iOS viewcontrollers :

fun MainViewController() = ComposeUIViewController {
    val navigator = IosNavigator()

    navigator.bind(...) // !! Here, I don't know what to put ... !!

    App(navigator = navigator)
}

fun SecondViewController() = ComposeUIViewController {
    TestSecondScreenContent()
}

And my App :

@Composable
fun App(
    navigator: Navigator
) {
    MaterialTheme {
        FirstScreen(
            onNewActivity = {
                navigator.navigateToSecondActivity()
             }
        )
     }
}

So, I think I “just” have to find a way to bind my iOS navigator with the UIViewController of the current screen flow. But for now, I didn’t manage to get it inside the Compose multiplatform ComposeUIViewController function.

Maybe someone could have an idea ? :slightly_smiling_face: