https://kotlinlang.org logo
#ballast
Title
# ballast
a

Adrian Witaszak

01/16/2023, 9:02 AM
Hi. I only found out about Ballast last night and will give it a go today. The Ballast seems very nice, I like the readability it provides. In my KMM project, Android and iOS, I share UI in the
commonMain
using the Jetbrains Compose. Do you have any recommendations for using Ballast in this use case? Expect/Actuals for ViewModels?
c

Casey Brooks

01/16/2023, 3:11 PM
Since you’re using Compose UI for the iOS UI, I think your life will be much easier than trying to use it in native iOS UIs. You should be able to define the ViewModel using
BasicViewModel
and scope it to
rememberCoroutineScope()
, and keep it all in common code. The Compose desktop snippet is how you’d set it up. You’ll probably need to keep the EventHandler for each VM platform-specific, either with DI or expect/actual. More generally, best practices for using Ballast on iOS is a bit of an open question, since I changed teams at work before we could get the iOS app migrated to KMM. There’s a discussion thread on the repo if you’ve got thoughts on how you think it should be handled, or if you notice any issues with the approach outlined above.
a

Adrian Witaszak

01/16/2023, 3:13 PM
heheh i already gave it a go, and it all works nice and smoothly. Forked your repo, and I'll add an example to it. 🙂
Example of shared JB Compose UI with: • Android • iOS with .xcodeproj • Compose iOS • Desktop • Compose Web (trying to make this one work right now)
c

Casey Brooks

01/16/2023, 3:17 PM
That would be wonderful, thank you!
a

Adrian Witaszak

01/16/2023, 6:13 PM
Created the PR, but without Web. No time to fight it today 🙂
c

Casey Brooks

01/16/2023, 6:20 PM
No problem, I just merged it in. It looks great, this is my first time actually running a Compose iOS app! I’m really excited to see this technology mature
a

Adrian Witaszak

01/16/2023, 6:21 PM
Me too, but it will be better if it fills the full screen 🙂
But it gives us hope for full kotlin app for all platforms in the future.
7 Views