https://kotlinlang.org logo
Title
n

Nikola Milovic

06/03/2021, 7:39 AM
Hello everyone, how do you share resource loading between desktop and android when utilizing Decompose/MVI? To access resources on Android you need reference to resources, and to get resources you need some kind of context that you cannot seem to get in commonMain. Making a simple weather app, I have an expect/actual fun that loads imageBitmaps (from res/drawable on android, and resources/images on desktop), but for the android one I need to get access to resources from context but I cannot access context in the commonMain to pass it to the expect fun. And desktop doesn't seem to support Painter API so I have to use imageBitmaps. This seems like a common thing to share ( anything with images really), so there must be a way I am missing out on. (Architecture is the same as Jetbrains/ Todo Sample)
a

Arkadii Ivanov

06/03/2021, 9:32 AM
There many ways I think. One of the options is Moko Resources: https://github.com/icerockdev/moko-resources Or you can create an interface with whatever data you need and provide implementations from outside. Just one think to notice - ideally Stores should not depend on resources, but mappers/transformers/UI can depend.
n

Nikola Milovic

06/04/2021, 7:17 AM
@Arkadii Ivanov This seems to be iOS & Android, while my use case requires something for Android/Desktop?
a

Arkadii Ivanov

06/04/2021, 7:27 AM
Yeah, missed that part. Maybe raise an issue and they will add JVM support? Otherwise I would stick with a custom solution. I would create a common module and put Resources interface there, which would contain everything. All other modules that require resources would depend on the Resources interface.