Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support common org.jetbrains.compose.ui.tooling.preview.Preview in IDEA and Android Studio #5078

Closed
igordmn opened this issue Jul 8, 2024 · 17 comments
Labels
enhancement New feature or request ide IDE related issue preview

Comments

@igordmn
Copy link
Contributor

igordmn commented Jul 8, 2024

State on 08-07-2024 (Compose 1.6.11):

  • added commonMain org.jetbrains.compose.ui.tooling.preview.Preview (in implementation(compose.components.uiToolingPreview))
  • it is supported only in Fleet, IDEA/Android Studio support needs to be added separately
  • there is currently multiple Preview's that confuses people. It is tracked in Reduce variety of Preview annotations #4869
@igordmn igordmn added enhancement New feature or request ide IDE related issue preview labels Jul 8, 2024
@igordmn
Copy link
Contributor Author

igordmn commented Jul 8, 2024

Parent task: #2045

@Him188
Copy link

Him188 commented Jul 8, 2024

Is it possible to render Android previews from commonMain if android target is enabled?

Desktop previews lack features such as device sizes, light/dark, interactive mode, layout inspector, animations, etc.
Given these limitations, I don't like and don't use desktop previews at all. I always open a separate editor tab and place all previews in androidMain.

It could be very nice if a common @Preview annoatation can somehow trigger Android previews in Android Studio, before we implement these features in compose multiplatform previews.

@igordmn
Copy link
Contributor Author

igordmn commented Jul 8, 2024

Is it possible to render Android previews from commonMain if android target is enabled?

At the moment, it isn't possible officially. There can be workarounds, but I haven't checked them.

A current working official (but cumbersome) way is defining your android-only @androidx.compose.ui.tooling.preview.Preview previews in androidMain and call a common defined Composable in it.

@Andrew0000
Copy link

Andrew0000 commented Jul 8, 2024

@igordmn How soon can we expect this feature to arrive? Is there any plan?
This would be really useful in terms of productivity and would make the transition from Jetpack Compose to CMP easier.

@Him188
Copy link

Him188 commented Jul 8, 2024

A current working official (but cumbersome) way is defining your android-only @androidx.compose.ui.tooling.preview.Preview previews in androidMain and call a common defined Composable in it.

Thanks, that's what I have been doing. The problem is it separates code and previews, making it hard for collaborators to find them. A separate IDE tab is also needed. Switching between tabs is frustrating.

Common @Preview is the feature that I want most. However, whether I will use it in production is still questionable, due to the lack of features compared with Android previews. It's likely that I will continue writing previews in androidMain even if it's frustrating. But at least I might start using common @Preview for very small composables that do not need interactive mode or considering device sizes.

@brucemax
Copy link

Just came here to see if anything changed after several month, unfortunately no. I just want to write UI and see preview right in the same file..

@hmy65
Copy link

hmy65 commented Jul 12, 2024

How could fleet support commonMain preivew? That's strange.

@gulabsagevadiya
Copy link

Is it possible to render Android previews from commonMain if android target is enabled?

At the moment, it isn't possible officially. There can be workarounds, but I haven't checked them.

A current working official (but cumbersome) way is defining your android-only @androidx.compose.ui.tooling.preview.Preview previews in androidMain and call a common defined Composable in it.

yes i did the same but it is not showing preview like jetpack compose does in android. when i did like you said preview runs on emulator not showing in side by side

@igordmn
Copy link
Contributor Author

igordmn commented Jul 15, 2024

is not showing preview like jetpack compose does in android

You can check how it is done in https://kmp.jetbrains.com/:
image

The important parts are in composeApp/build.gradle.kts:

androidMain.dependencies {
    ...
    implementation(compose.preview)
    ...
}
...
android {
    ...
    buildFeatures {
        compose = true
    }
    ...
}

@gulabsagevadiya
Copy link

is not showing preview like jetpack compose does in android

You can check how it is done in https://kmp.jetbrains.com/: image

The important parts are in composeApp/build.gradle.kts:

androidMain.dependencies {
    ...
    implementation(compose.preview)
    ...
}
...
android {
    ...
    buildFeatures {
        compose = true
    }
    ...
}

yes this worked fine. can you help me little more as i am using common resource in kmp. when i use any drawable from common resource render gets fail

@igordmn
Copy link
Contributor Author

igordmn commented Jul 16, 2024

when i use any drawable from common resource render gets fail

Maybe this is what you encounter. Try the latest dev version

@Andrew0000
Copy link

@igordmn sorry for asking again, but is there any time frame when we can expect Preview to work in commonMain in IDEA/AS?

For me this is a quite important feature that stops me from using CMP more.

@igordmn
Copy link
Contributor Author

igordmn commented Aug 14, 2024

but is there any time frame when we can expect Preview to work in commonMain in IDEA/AS

We don't have public ETA

@okushnikov
Copy link
Collaborator

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

@storytellerF
Copy link

Fleet compose preview only work for fun App()?

@adamglin0
Copy link

Fleet compose preview only work for fun App()?

It support all composable function

@ubarua123
Copy link

ubarua123 commented Sep 15, 2024

This is unfair on Jetbrains part where they are trying to upsell Fleet so that all compose multiplatform devs switch to Fleet. So now not only do I need to learn multiplatform coding, I need to learn how to use Fleet (which is going to be a Paid tool like Intellij)

I am still stuck where it gives the "missing resource" error (my previews are in androidMain) even with their Compose Multiplatform support plugin. If someone has a good solution please write it here.

I ended up copying ALL my vector drawables to androidMain -> res -> Drawable and now I can see my screens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ide IDE related issue preview
Projects
None yet
Development

No branches or pull requests

10 participants