compose-multiplatform icon indicating copy to clipboard operation
compose-multiplatform copied to clipboard

Preview annotation in commonMain sourceSet

Open IlyaGulya opened this issue 2 years ago • 12 comments

It is good to have multiplatform Preview annotation for all target platforms in commonMain sourceSet.


Hello! Currently desktop preview rendering is possible only in desktop sourceSet because ui-tooling-preview publishes androidx.compose.desktop.ui.tooling.preview.Preview annotation only for desktop sourceSet.

However, I've been able to successfully use current Compose Multiplatform IDE Support plugin to render preview defined in common sourceSet.

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.

I think Compose MPP team should consider publishing androidx.compose.desktop.ui.tooling.preview.Preview annotation for common sourceSet instead of desktop.

IlyaGulya avatar Apr 30 '22 12:04 IlyaGulya

This would be really helpful. Also it would be nice to have a drop down in preview tab to select target platform/device for preview as well as other features from android preview like multiple previews, zoom, grid view, interactive mode, etc. Is it on roadmap somewhere? I can't find any information regarding plans

syt0r avatar Mar 07 '23 12:03 syt0r

Any update on this?

hm-tamim avatar Jul 19 '23 04:07 hm-tamim

not yet

pjBooms avatar Jul 19 '23 14:07 pjBooms

Any updates on this issue?

SerggioC avatar Aug 06 '23 14:08 SerggioC

any update ?

anwarpro avatar Aug 09 '23 03:08 anwarpro

It is good to have multiplatform Preview annotation for all target platforms in commonMain sourceSet.

Hello! Currently desktop preview rendering is possible only in desktop sourceSet because ui-tooling-preview publishes androidx.compose.desktop.ui.tooling.preview.Preview annotation only for desktop sourceSet.

However, I've been able to successfully use current Compose Multiplatform IDE Support plugin to render preview defined in common sourceSet.

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.

I think Compose MPP team should consider publishing androidx.compose.desktop.ui.tooling.preview.Preview annotation for common sourceSet instead of desktop.

and need to install Compose Multiplatform IDE Support

amirhossein320 avatar Aug 28 '23 15:08 amirhossein320

It would be perfect to make use of Android Studio preview feature for composables from commonMain, at least for android target for now. So it will show how composable preview function from common code will look like on Android, in AS's preview ide view. (right in commonMain, without creating preview function in androidMain)

I assume it could be easier to do, than making a full spectrum of it's feature for Compose Multiplatform desktop IDE plugin from scratch. And maybe it's just a matter of configuration, because even AS's Layout Inspector works for kmp composables if you use androidx compose compiler in android target.

senk0n avatar Aug 30 '23 06:08 senk0n

I think this is very important to have @Preview working in shared compose ui code.

Burtan avatar Nov 02 '23 09:11 Burtan

I was wondering what the suggested workflow currently is for creating Composables without the Preview? Just good old fashioned rebuild or creating the composables within androidApp and then after finishing, copying them over to shared?

anox1337 avatar Nov 10 '23 13:11 anox1337

You don't have to write it in androidMain and copy to commonMain. You write it in commonMain and reference it from androidMain.

 // This is in androidMain files or Android App
 AndroidPreviewOfMyComposable {
  // Bellow lives is commonMain
  MyComposableFromCommon
}

Another alternative is, Android Studio gives a gutter icon to deploy un device instead of the IDE previewer. I found that to be really fast. Another alternative is using the Desktop target, build times are faster. Another alternative is using the JS target with continuous refresh enabled. It does hot reload in a decent time too.

pablichjenkov avatar Nov 10 '23 14:11 pablichjenkov

Any updates on this issue?

SirFilbido avatar Apr 02 '24 13:04 SirFilbido

This is probably my top feature right now, everything else is pretty good state (at least less of a priority right now), without previews live updating in common editing/updating/building screens is really slow/painful, while we can put previews in androidDebug, the screen living in commonMain means we need to manually build and refresh vs "native" compose dev where previews living in the same srcSet auto compile as you edit them.

  • As a stop gap, updating the KMM plugin to allow build and refresh on save from the common would be a really big intial win, means don't have to keep switching windows/tabs etc.

chrisjenx avatar May 01 '24 16:05 chrisjenx

This works in latest Fleet release (link), but (at least in my experience) it's very slow (a refresh takes 5-10 sec on M1 macbook) and doesn't support all bells and whistles of @Preview from native Android. Still, good progress.

bartekpacia avatar May 30 '24 00:05 bartekpacia

Even the preview workaround using androidMain do not work when the commonMain composable is loading a resource. I'm getting this exception org.jetbrains.compose.resources.MissingResourceException: Missing resource with path: composeResources/mobileapp.composeapp.generated.resources/drawable/splash_bg.jpg Any idea?

coud avatar Jun 05 '24 14:06 coud

Even the preview workaround using androidMain do not work when the commonMain composable is loading a resource. I'm getting this exception org.jetbrains.compose.resources.MissingResourceException: Missing resource with path: composeResources/mobileapp.composeapp.generated.resources/drawable/splash_bg.jpg Any idea?

Yeah there is another ticket for this, the Preview plugin doesn't support common resources.

chrisjenx avatar Jun 05 '24 14:06 chrisjenx

Let's keep this as a meta issue for other children tasks:

  • https://github.com/JetBrains/compose-multiplatform/issues/4869
  • https://github.com/JetBrains/compose-multiplatform/issues/5078

igordmn avatar Jul 08 '24 12:07 igordmn

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

okushnikov avatar Jul 14 '24 14:07 okushnikov

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

But why move to YouTrack? Are all Compose issues gonna be on YouTrack now?

acmpo6ou avatar Jul 14 '24 15:07 acmpo6ou