I am looking for a guide to setting up @Preview fo...
# compose-desktop
v
I am looking for a guide to setting up @Preview for Jetpack Compose DESKTOP, on either IntelliJ Ultimate or Android Studio. I have installed the plugin (Compose Multiplatform IDE Support), I have added
implementation(compose.preview)
to
destktopMain
source set in the shared module, and I've added the
androidx.compose.desktop.ui.tooling.preview.Preview
annotation to my function. But I see nothing in either IntelliJ or Android Studio. I'm not sure what version of Compose I'm using though!
p
Try also adding
implementation (compose.uiTooling)
If if doesn't work, then you know, full cleanup, invalidate caches, restart IDE ...
v
Should there be a preview window or icon in the gutter?
p
Yes a gutter icon
Shows next to the Preview annotation,
v
I can see one in the android code, but not in the desktop code. (Android is entirely broken on my project, but that's a question for another day!)
p
After adding uITooling , remove the Preview import and try again. I don't recall if yours is the right import
v
Hmm. I have desktop preview in code in the desktopApp\jvmModule. But not working in the shared\desktopMain module. Is that expected?
Just all the Jetbrains examples/samples have essentially no code at all in
destopApp
- just a main() function which launches the app. All the code is in the shared module, none of them have @Preview, and as far as I tell, none of them even have any platform-specific UI composable functions. https://github.com/JetBrains/compose-multiplatform/blob/master/examples
p
Yeah they haven't added to the samples yet
You have to add the dependencies there too
Or use api() instead of implementation in shared.
v
OK, thank you, seems to be working with api().
👍 1
g
Do your desktopMain deps look something like this?
Copy code
val desktopMain by getting {
            dependencies {
                dependsOn(commonMain)
                implementation(compose.desktop.common)
                api(compose.uiTooling)
            }
        }