Colton Idle
08/30/2023, 8:09 PMColton Idle
08/30/2023, 8:15 PMexpect fun launchExternalBrowser(url: String)
but my issue is that in my android code I need a context. and I can't seem pass that into the method along with the url.Colton Idle
08/30/2023, 8:16 PMColton Idle
08/30/2023, 8:16 PMjw
08/30/2023, 8:18 PMjw
08/30/2023, 8:18 PMjw
08/30/2023, 8:19 PMjw
08/30/2023, 8:20 PMColton Idle
08/30/2023, 8:22 PMStefan Oltmann
08/30/2023, 8:32 PMfunc openInBrowser(url: String) {
#if os(iOS)
UIApplication.shared.open(URL(string: url)!)
#endif
#if os(macOS)
NSWorkspace.shared.open(URL(string: url)!)
#endif
}
Stefan Oltmann
08/30/2023, 8:34 PMStefan Oltmann
08/30/2023, 8:36 PMStefan Oltmann
08/30/2023, 8:36 PMjw
08/30/2023, 8:38 PMStefan Oltmann
08/30/2023, 8:42 PMColton Idle
08/30/2023, 10:49 PMinterface BrowserLauncher{
fun launch(url: String)
}
@Composable
fun HomeContent(browserLauncher: BrowserLauncher) {
Button(onClick = {
browserLauncher.launch("<https://google.com>")
}) {
Text("Lunch Browser")
}
}
and then I guess I need to add the interface implementations in my android app module and then again in iOSApp module?jw
08/30/2023, 10:51 PMColton Idle
08/30/2023, 11:06 PMColton Idle
08/30/2023, 11:21 PMColton Idle
08/30/2023, 11:22 PMColton Idle
08/30/2023, 11:22 PMColton Idle
08/30/2023, 11:22 PMColton Idle
08/30/2023, 11:23 PMPablichjenkov
08/31/2023, 3:26 AMactual
and the compiler generates all the language bindings.
I think more often we use instances provided by the platform than global classes. A classic example is Android Context needed for almost everything, so that gives the interface injection a lot of usability.Michael Paus
08/31/2023, 6:20 AMval localUriHandler = LocalUriHandler.current
Then use it like this
localUriHandler.openUri("https://…")
to open your URL.Vlad
08/31/2023, 8:19 AMnot sure why shared/androidMain and shared/iosMain exist. My impl had to be in my android app module. so just wondering if I could/should blow both of those away?
Your impl can be there and there. But of course it is preferable to have it in the targetMain rather then in the app module. Because that way your KMP module is independent.
As for the start question - sure you can create objects to which you delegate doing some stuff (opening different apps). But well, if you need context in some particular actual function for android you can always simply get it from DI.rocketraman
08/31/2023, 12:11 PMnot sure why shared/androidMain and shared/iosMain exist. My impl had to be in my android app module. so just wondering if I could/should blow both of those away?Yeah I think the idea here is that your shared module can be re-used across multiple android/ios apps. Think about your shared code as a library that exports code for each platform. The consumer just imports the dependency in common main (or directly in the case of android/ios apps) and automatically gets all the common as well as platform specific code.
rocketraman
08/31/2023, 12:16 PMInterfaces ftw. im now not sure why expect/actual exists. lolThe other difference between expect/actual and interfaces is that expect/actual is compile-time binding. This can have perf implications, though the slower dynamic binding of interfaces is not an issue for most use cases.
Vlad
08/31/2023, 12:18 PMColton Idle
08/31/2023, 1:57 PMpers
09/08/2023, 3:57 PM