Happy new year. I finally released a first prototy...
# multiplatform
t
Happy new year. I finally released a first prototype of my Compose Multiplatform HotPreview plugin. Just see following link for details: https://github.com/timo-drick/Mutliplatform-Preview Please keep in mind that it is an early prototype and if anyone wants to help me continue developing it would be great.
๐ŸŽ‰ 18
f
Very nice ๐Ÿ˜„ ! You might want to mention this in #C0BJ0GTE2 as well
๐Ÿ‘ 1
m
Looks like I am first to install the plugin ๐Ÿ˜› Or at least among the first.
I couldn't make it work though
t
Did you followed the instructions on the Github page?
Would be really geat if you could give me some feedback what is unclear. And indeed maybe you are the first one trying it ๐Ÿ˜„
Maybe one important thing. After adding a @HotPreview annotation in a file you have to close it and open it again so the plugin starts working.
The Android Studio preview plugin handles it this way that the plugin is active for all kotlin files in general. And i didn't wanted this to happen because than the normal @Preview annotation would not work anymore.
j
@marcinmoskala it doesn't work with iOS Targets
t
Maybe i should at least show an error message when the annotation is created in a platform target that is not supported.
๐Ÿ‘ 1
Ok i had a major break through at the weekend. The plugin is now able to preview itself ๐Ÿ˜„ I also added macos and windows support (Yes it turned out that i forgot to include the runtimes for all platforms)
The plugin can now also preview compose 1.8.0-alpha02 And some limitations regarding resources are gone.
j
but iOS Targets are still missing?
t
Using lib version:
Copy code
dependencies {
    implementation("de.drick.compose:hotpreview:0.1.4")
}
And HotPReview plugin 0.2.0 from the marketplace All should work.
The iOS targets where there from the beginning. But i had to compile the library on a macos machine. So the library is now build on a macos machine. Looks like linux and windows can be crosscompiled.
j
Ah okay. I installed everything and updated the plugin, but where can I see my previews now?
currently looks like the following for me
t
You have to close and open the file with @HotPreview annotations after installing the plugin
Can you please check. Maybe also you have to restart the IDE after installing the plugin.
j
yeah, I think I have to restart the IDE
t
Ok this is maybe when you try to put the annotation to a iOS or Android target
It only works in common or jvm/desktop target
For Android targets you an of course just use the Android preview annotation
j
ah okay, makes sense. Since my project only targets android and iOS
t
Ok yes this is not possible for now.
In theory it should be possible to make everything work with enough development resources ๐Ÿ˜„
So you can use it in a multiplatform porject. But it can only preview compose UI that is located in the common or jvm part.
So we still missing preview for iOS and webassm.
If you want to see the preview you can checkout this project: https://github.com/timo-drick/compose_desktop_dev_challenge
But maybe one more thing. If you have common UI parts in you project. Just also configure jvm target than you can preview them. So it is as easy as just adding
jvm("desktop"
to the kotlin section in the gradle file. And also the jvm plugin
j
I think my main problem is, that I have some modules which targets only mobile
t
ok i see.
j
But I have to check it again, maybe it should work for jvm also
would be great, since it is painful to compile a debug build for iOS. Since I'm using some cinterop things
t
I think the iOS target compose code should be possible to move to common target
So the main idea of this thing is to reuse compose UI for Android and iOS right?
j
yes
I think the main problem is, that my viewmodels are also holding the state for my screens and executing my usecases and besides that, I didn't use the usecase pattern for my interop things. That's why I have to restructure some parts of my project to get it to work
For example here, the KmpCalendar is a native module which targets only for iOS and Android
t
Yes i am also still struggling finding a good solution for this. In theory maybe creating expect/actual implementations for the viewmodel should be the way to go. So you do have different implementations for the viewmodel depending on the target platform
j
and thats where it will break with adding a jvm target
t
Yes ok i see
But the native Android Studio preview also do not support viewmodels.