Kotlin Multiplatform support #1206
Unanswered
blakelee
asked this question in
Show and tell
Replies: 1 comment
-
Here's a sample project with it running https://github.com/blakelee/WorkflowMultiplatform |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I was messing around with workflow to see if I could get it working for a KMP project and I managed to get it working for Compose Multiplatform. I was trying to manage state for a personal app I'm making and after seeing the existing solutions recommended on jetbrains' website, I decided it was worth a shot to see if I could make it myself. Here is a simple hello world showing it working
How did I do it?
workflow-core
andworkflow-runtime
already supported KMP.workflow-ui/compose
module so I imported all of those classes except forViewEnvironmentWithComposeSupport.kt
and removed the functions related toViewFactory
inScreenComposableFactory.kt
which left me with POKO's and nothing Android related.LocalLifecycleOwner
inWorkflowRendering.kt
but I needed a KMP solution. There was also this recent change which caused some friction.LocalLifecycleOwner
was moved toandroidx.lifecycle:lifecycle-runtime-compose
which doesn't have KMP binaries. Luckily for us Jetbrains just released their own version for KMP here which is available in the Compose plugin 1.6.10.compose.ui
in the compose plugin as well asorg.jetbrains.androidx.lifecycle:lifecycle-runtime-compose
, I could editWorkflowRendering.kt
to support our KMP lifecycle. Simply importandroidx.lifecycle.compose.LocalLifecycleOwner
then modify the functionrememberChildLifecycleOwner
where theparentLifecycle
will now beandroidx.compose.ui.platform.LocalLifecycleOwner.current.lifecycle
I faced a lot of dependency issues trying to figure this out. So as of right now I could only get it working on Android and iOS with Kotlin 2.0.0, Compose-plugin 1.6.10 and Lifecycle-runtime-compose 2.8.0.
If we wanted to make these changes public, we'd have to take the Android code out of
workflow-ui/compose
and possibly make another module for the Android View factories.Beta Was this translation helpful? Give feedback.
All reactions