Hey folks, Do all three Compose ui libraries (Jet...
# compose-desktop
m
Hey folks, Do all three Compose ui libraries (Jetpack, Desktop, Web Compose) have different foundation implementations? EDIT: Remove Compose for Web from that equation, I just noticed that it has a very different implementation from its two counterparts. I’m thinking about writing a simple graphing library and trying to see if there’s a way to avoid having separate projects for all three the two since it’s just UI code with some light modelling that should - at least in theory - be identical across all both platforms. (this may yet prove itself a folly of course) Sorry for any silly questions, this is the first time I’m having to think about deploying a library to three two similar implementations of a given technology. 😄 Thanks for any eventual answers.
z
Compose Desktop and Compose Android have identical graphics and input apis, at least at all but the very lowest interop level
s
Web will be getting a canvas based approach, and at some point so will iOS (I assume). As long as you aren’t accessing the underlying canvas or playform APIs, any Composable you write should theoretically be usable with few changes between all the platforms in the future..
m
The Compose Canvas and DrawScope APIs are identical on desktop and Android (and probably will be in iOS/Web in the future). The differences start when you try to access the native Canvas. On Android you will get the traditional Android Canvas whereas on desktop you will get the Skiko (Skia-wrapper) Canvas. But in some cases you might also experience differences between Android versions due to known differences in the implementations of the Android canvases for different Android versions. E.g., I recently had the case that some graphics just vanished (with a logged error message) on an Android 8 device but was ok on Android 10/11.
m
Thanks for the input guys. The news about Web getting a Canvas based approach in the future is swell. So if I’m reading you correctly, I’m still supposed to have 3 different libraries i.e.: graphipng-lib-compose-android, graphing-lib-compose-desktop, graphing-lib-compose-web along with a smalled shared modelling lib. Having a unified library would not be feasible but the code should for the most part be nearly identical across the three platforms (once web gets Canvas or something akin to Canvas). Am I reading that right?
b
You can unify most of the android/desktop parts, I think. just not web (yet)
s
So if I’m reading you correctly, I’m still supposed to have 3 different libraries
So I’d make sure you have a good understanding of how Kotlin Multiplatform libraries work. You should be able to create a single Kotlin multiplatform Gradle moudle with most, if not all of the code in the
commonMain
directory. Anything inside of
commonMain
is compiled to any target platform. Theoretically when all this is released, you’ll be able to target
android
`jvm`(desktop),
ios
,
tvos
, and `js`(browser). Any code in
commonMain
should easily compile to all those targets with little modification.
As things stand, you can create a multiplatform module that just targets
android
and
jvm
and share code between them via
commonMain
source set. When you publish the results to a maven repository, Kotlin Multiplatform will automatically handle creating the different artifacts of
<your lib>-android
<your lib>-jvm
, and when you add more targets it will automatically add the others as well. It’s a very convenient system. Then when people use your lib, you can point them to your
<your lib>
artifact, and based on their targets, it will automatically pull in the correct platform artifacts.
m
@spierce7 Wow, this is beautiful. Thank you for the detailed answers. Truth be told I was looking at these separate and not thinking about multiplatform. This will definitely require more research from my side but seems like it will pay off in the end. Thank you once again, being headed in the right direction is the most important things when dealing with things like these I feel.
👍 1
g
@Marin Tolić Have you seen this project? https://github.com/humawork/compose-charts I just submitted a pull request that replaces the few Android Canvas uses they had with Compose Canvas. It probably won't take much more to now convert this into a multiplatform project. There aren't a lot of graph types or options implemented yet, but it's a start.