Hello All Is there any way to enable @Preview for ...
# multiplatform
n
Hello All Is there any way to enable @Preview for Composable from common shared code base ? Like any dependecies which we can use in
commonMain
so it can be preview from common components ?
j
You should ask (or search) in #compose, but you already did, so perhaps avoid cross posting which only serves to fragment discussion and prevent searching for answers in the future.
n
I tried to search first. but mostly i found like using tooling preview dependecies which can be declared in
androidMain
not in
commonMain
or any explanation or alternative. Could you please help me with that if you have any link handy ? I can understand multiple channel have same question is not good so please let me know if you want me to remove this convesation from any of the channel . @jw
p
The problem is
commonMain
is not a platform itself, how do you expect to preview something in common? You expect the previewer showing the 4 most used platforms? - that would require some UI redesign in intellij itself, at least in the preview panel section to have more space. The options so far are, specific previews on Android, Desktop or, for iOS you can create a utility controller to wrap your Composable and use the swiftui previewer.
android eyes 1
d
@Pablichjenkov That doesn't sound like such a hard design problem to solve (to say nothing of the underlying technicals) - couldn't the Preview panel have a selector for which engine to render; with only selections for enabled targets being available? Besides, I think the platforms render closely enough to one another; that most of us would be grateful just to see a 'Desktop Preview' work on @Previews held in common - the main pain point is availability of the feature at all, rather than accuracy.
p
I agree Chris. My comment was basically to highlight the fact that real previews running on each target is a bit complex and resource consuming. For iOS it would need some mechanism to encapsulate the compose code in a swiftui interop view and then pull the Xcode preview output and display it somewhere in Android Studio. Same for the Web, run compose on the browser then display the output in AS. But I really think most devs are ok with only rendering previews on the JVM target. Then trust CMP will render "the same" in the other targets. And we don't even have this one yet, unless you use Fleet but then other issues arrive.