Has anyone tried using workflow in a kotlin multip...
# squarelibraries
d
Has anyone tried using workflow in a kotlin multiplatform project with Android and iOS? Is it possible?
z
@Stephen Edwards
n
b
I pushed up a sample of workflow kotlin multiplatform if you wanna see how it works. iOS and Android targets both working. https://github.com/blakelee/WorkflowMultiplatform
🙌 2
🙌🏻 1
d
Blake this is great stuff, I spent a bit of today integrating this into my app. I wish the workflow module was a plugin or a standalone lib so I didn’t have to move it over. Thanks for sharing this!
Still a bit lost on how to animate a composable when there’s a back stack. I’d like to animate it from left to right. How can I do that in a KMP app?
b
I’ve been doing something like this in my composable
Copy code
updateTransition(targetState = screen)
          .Crossfade(
            contentKey = { targetState -> targetState::class }
          ) { targetState ->
            WorkflowRendering(targetState, viewEnvironment)
          }
It matters what key you use because if the key is the object itself then anytime that object changes you’ll see a crossfade, so instead I did the crossfade on the class type For slides you’d probably want something like this
Copy code
val slideBack = slideInHorizontally { -it } togetherWith
    slideOutHorizontally(targetOffsetX = { it })

val slideForward = slideInHorizontally { it } togetherWith
    slideOutHorizontally(targetOffsetX = { -it })

val transition = if (isBack) slideBack else slideForward

AnimatedContent(
  targetState = screen,
  contentKey = { targetState -> targetState::class },
  transitionSpec = { transition }
) { targetState ->
  WorkflowRendering(targetState, viewEnvironment)
}
d
Any tips on handling orientation changes with compose multiplatform, iOS is working fine
b
Hmm… Is it having issues with saving state? I think I took out all of the state saving stuff because it would need an expected/actual functions per platform. This is the snapshot in workflow
d
Ya it is, I figured that. I’m thinking I can probably make expect/actual classes for Android/iOS but is there something that’s multiplatform friendly? Or would I have to build it? It’d be nice not to have expect/actuals for each state.
b
I found this but I’d probably just looks at the existing impl of the
fun Parcelable.toSnapshot()
in the core-android library here. Since we don’t have Parcelable available to us in KMP we’d probably want some sort of adapter for the usuals like kotlinx-serialization and other libraries.
d
Sounds good, I was thinking about using Parcelable for Android and serialization-json for ios/others
QQ @blakelee - I’m building an app where I have a workflow
mainNavWorkflow
that returns a
navRendering
. There’s a
tabBarRendering
as a parameter in that rendering. Is it an anti-pattern to create a new instance of
tabBarRendering
and pass it
navRendering
? Or do I have to make a call to the render child to the
tabBarWorkflow
to get the
tabBarRendering
and pass that into the
navRendering
? Both of these approaches work since I have a
ScreenComposableFactory
registering both renderings. I’m just wondering if this is an anti pattern. (If you’re wondering,
tabBarWorkflow
is stateless)
b
I’m not quite sure I understand what you’re saying. If I understand correctly, for creating a new tabBarRendering I would do something like. Maybe we can move this thread to DM’s since it’s getting off topic from the initial thread
Copy code
context.eventHandler { newTabBarRendering ->
  state = state.copy(tabBarRendering = newTabBarRendering)
}