https://kotlinlang.org logo
#getting-started
Title
# getting-started
h

Hozaifa Bhutta

03/16/2022, 11:08 PM
I know how to launch a new activity in native android. But I want to have a single shared function that launches a new activity in iOS and Android
i

Igor Milakovic

03/16/2022, 11:11 PM
There's no such thing as an "activity" in iOS, there are view controllers. Main purpose of KMP is to share the code than can be shared, not platform specific stuff
👍 1
h

Hozaifa Bhutta

03/17/2022, 1:45 AM
So how would you create a kotlin multiplatform app that can change views?
s

Scott Kruse

03/17/2022, 1:59 AM
Look into expect / actual functions
h

Hozaifa Bhutta

03/17/2022, 2:01 AM
I understand that (kind of), but what would the function return?
i

Igor Milakovic

03/17/2022, 3:29 PM
I wouldn't - I'd just have a use case in the shared KMP module, and handle the navigation in iosApp/androidApp. For example, imagine having SignInUseCase. I'd simply call e.g.
Copy code
signInUseCase.execute(email: "<mailto:test@test.com|test@test.com>", password: "securemuch")
from view models in iOS/Android. And then in completion block I'd handle the navigation. This way KMP does all the heavy lifting, and navigation is trivial anyway. It's not like you're saving some actual time by forcing that into the shared code. Hope this makes sense!
h

Hozaifa Bhutta

03/17/2022, 8:11 PM
It helps!
👍 1