https://kotlinlang.org logo
#compose-ios
Title
# compose-ios
t

Trey

10/24/2023, 3:59 PM
Can somebody suggest a pattern that allows common compose logic to initiate calling an external activity for result on Android? I'm trying to implement PKCE authentication in my app and so far, all of the UI is compose multiplatform. This is the first time that I must invoke activity for result on Android to launch the browser.
p

Pablichjenkov

10/24/2023, 4:47 PM
Make your ComposableApp receive an interface named PlatformBridge or PlatformCallback or PlatformNavigator, whatever you like. This interface will have a function named navigate or goTo again you pick the name. Implement it AndroidPlatformNavigator(activity: Activity) : PlatformNavigator { navigate (route: EnumRoute) { activity.startActivity() } } You pass the implementation in ComposeApp(AndroidPlatformNavigator(activity))
👍 2
t

Trey

10/24/2023, 7:06 PM
Thanks
👍 1
Have you used this approach before? When I try it, I get errors about activity not being Parcelable. I'm thinking that everything passed down into the Composable functions as to be Parcelable.
p

Pablichjenkov

10/24/2023, 10:56 PM
Are you using rememberSaveable? If so you won't be able to save an instance of a callback object. But you can just use remember or not use remember at all, if you use it as a function param. I haven't used that specific approach to launch another activity but I have used a similar approach of holding a reference to an interface implementation in the platform without any problem
v

Vlad

10/25/2023, 12:50 PM
Don't save it in parcer. There are no reason to, this is just communication interface. You probably can put it into LocalComposition on top of your tree so you can easily access it from anywhere down the tree
👍 2
4 Views