So, do you put previews in Android source only? (w...
# compose-ios
e
So, do you put previews in Android source only? (with hope it will work on the common code at some point)
👍 4
v
I forgot they exist for now
d
I use a Composable wrapper with a preview in Android and reuse the same Compose function from
commonMain
.
e
Any example? Do you keep preview code in common?
v
Also worth to mention that in the Kotlin 1.9 change logs they mentioned that google takes implementation of the KMP plugin, I assume we just wait
d
For now we have preview only for Android and Desktop sourceSets. For Desktop, here is the plugin: https://plugins.jetbrains.com/plugin/16541-compose-multiplatform-ide-support But we are thinking about the possibility to add Preview to the commonMain sourceSet as well.
🎉 1
e
I’m waiting but would like to have something already. Compiling and running on device is not the fastest feedback.
d
Preview for iOS is not working for now. But there is a workaround to use additional expect annotation in commonMain with actual on JVM sourceSet to render it as JVM Preview. @Davgdafa mentioned it above.
e
Aha! Thank you!
d
We have an issue with adding the possibility to use Preview annotation in commonMain: https://github.com/JetBrains/compose-multiplatform/issues/2045 And in Issue description author added a link to project with workaround.
You can check the example here:https://github.com/IlyaGulya/compose-jb/tree/example/common-desktop-preview/experimental/examples/falling-balls-mpp
I've moved
GamePreview
to common sourceSet and added stub
androidx.compose.desktop.ui.tooling.preview.Preview
annotation to trigger Compose Multiplatform IDE Support plugin to add gutter icon on
GamePreview
function.
d
Just to add to the list of weird and wonderful solutions: I've been keeping a
previewMain
source set, common to Desktop and Android, which get 'realised' with the correct annotations by wrapping functions in each platform. A bit of maintenance overhead but... It's common previews alright.