Hi Everyone, is there dependency available in Kotl...
# multiplatform
s
Hi Everyone, is there dependency available in Kotlin multiplatform for compose multiplatform preview
p
Yes,
s
Source link please
p
I swear the official get-started templates on GitHub had these but don't see it. Let me check in my repos
Check this gradle file, you need
uiTooling
and
Preview
in Android target and also in jvm target if interested in Desktop previews. https://github.com/pablichjenkov/component-toolkit/blob/master/component-toolkit/build.gradle.kts#L245 Also for Android you need this: https://github.com/pablichjenkov/component-toolkit/blob/master/component-toolkit/build.gradle.kts#L314
l
You can't use previews in commonMain yet. You'll have to define your previews in androidMain/jvmMain depending on which frame you want (mobile vs desktop).
p
s
@Pablichjenkov didn't help in commonMain We Want to have in commonMain as @Landry Norris saying it currently not available,
l
It's possible to typealias the jvm desktop preview using OptionalExpectation and use it in commonMain, but you'll get a desktop preview, not mobile (and you need a jvm module). People have had issues doing this with the android preview annotation. Personally, I usually have a Previews.kt file in androidMain.
s
Yes desktop is possible but we wanted to have both in iOS and Android using commonMain()
👍 1
p
But remember commonMain is really not a target, is basically where all your project targets intersect. In other words, commonMain doesn't have an emulator or output to render the code. It relies on real actual targets for that. The closest is desktop since it seats in the same Mac you are. Have you tried using the previews in
shared/androidMain
or
shared/jvmMain
l
See the following for an example of the optional expectation. You'll be able to preview Composables for android/ios, but they'll render as a desktop preview. You'll also need a jvm source set. https://github.com/arkivanov/Decompose/blob/master/sample/shared/compose/src/commonMain/kotlin/androidx/compose/desktop/ui/tooling/preview/Preview.kt
The ideal solution would be if JetBrains and Google unified the preview engines, then in commonMain, had a dropdown to select android/desktop, but that would require a lot of time that could be better spent stabilizing Compose on iOS.
1
p
Yeah that was my point, seeing the iOS preview in Android Studio is basically copying the buffer output from an iOS emulator and displaying it in AS. But the real rendering is happening in iOS target not common. So yeah it is more comfortable in the sense that you don't have to switch to Xcode but nothing else than that
l
Getting an iOS preview at all in AS/IJ is unfortunately likely a while away. They'd probably be much better off starting with a desktop/android toggle for previews.
2
p
In case I really need it, I am fine with embedding the composable in a swift UI preview. It requires more writing but in case you want to be completely assured how it looks. For most cases I just use the Android preview and bet 🤞for it to be the same in the other platforms 🤷🏻‍♂️
💯 2
s
Yes ideally Google or Jetbrain should come up with the standard solution for preview, rather than we doing tweaks or work arounds
👍 2
a
Is @Preview still unavailable in the commonMain?
s
Seems yes
🥲 1