JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.24k stars 1.11k forks source link

Compose Desktop IDE Plugin doesn't show when using Jetbrains Preview annotation #4839

Open ellet0 opened 1 month ago

ellet0 commented 1 month ago

Describe the bug When creating a project in Kotlin Multiplatform Wizard (since Compose Multiplatform Desktop template is a little bit outdated, doesn't use Gradle Version catalog by default for example)

When using Compose Multiplatform IDE Support (which is for Compose desktop but the name indicates it's for Compose Multiplatform)

Let's say you have the following code snippet:


@Composable
@Preview
fun App() {
    var text by remember { mutableStateOf("Hello, World!") }

    MaterialTheme {
        Button(onClick = {
            text = "Hello, Desktop!"
        }) {
            Text(text)
        }
    }
}

The preview button image

Will only show up when the import of @Preview is from androidx.compose.desktop.ui.tooling.preview.Preview and not org.jetbrains.compose.ui.tooling.preview.Preview (the compose desktop template that is a little bit outdated is using androidx.compose.desktop.ui.tooling.preview.Preview and not org.jetbrains.compose.ui.tooling.preview.Preview (which is the default when using (kmp.jetbrains.com to create the compose desktop project)

Affected platforms

Versions

To Reproduce Steps to reproduce the behavior:

  1. Create a new Compose Desktop project (either by kmp.jetbrains.com or Compose Multiplatform Desktop template)
  2. Make sure to replace import androidx.compose.desktop.ui.tooling.preview.Preview with import org.jetbrains.compose.ui.tooling.preview.Preview or try out both
  3. You will notice the preview button only shows up when using import androidx.compose.desktop.ui.tooling.preview.Preview and not the new one from Jetbrains (which is designed for Compose Multiplatform and I believe it's used in Fleet IDE)

Expected behavior Compose desktop and Compose multiplatform have a great future, maybe we should make the process less confusing and exclude anything related to Android. this doesn't require any breaking changes, we can support both and use the one from JetBrains as a default

Screenshots If applicable, add screenshots to help explain your problem.

The preview button doesn't show up:

image

It shows up after using Preview annotation from Androidx Import: image

Additional information Not related to the issue, but maybe you should consider making the process easier since now we have multiple ways and places to create a Compose Desktop or Compose Multiplatform project, and each one has a default code that has advantages over the other, creating a CLI and add support for it in IDE would make the process much easier, like other frameworks (Flutter, React, etc)) which makes it more beginner-friendly and less confusing, I even created a very quick CLI utility (kmp-cli) just so I use it for creating Compose projects quickly

Thank you.

igordmn commented 1 month ago

We have inconsistency with Preview annotations, which will be solved in https://github.com/JetBrains/compose-multiplatform/issues/4869. Please, vote for it.