Does Compose Common support Preview yet? I feel li...
# compose-desktop
s
Does Compose Common support Preview yet? I feel like I remember reading something a few months back, but I haven't followed up on it.
a
Do you mean Desktop? That is supported yes. Albeit not with the same feature set as Android I suppose
a
also, i find it breaks very often, requiring an IDE restart. If the very first attempt to preview fails, you can get some error logs from it, but if you've had a successful preview in the past, you can no longer get an error message about what is wrong.
s
In briar-desktop we were a bit frustrated with the preview support in IDEA (it crashed often and then no previews worked at all until the IDE was restarted), so we took a different approach at least for the time being. We have a short
fun main()
for each UI component that requires a preview and we have created a little
preview()
helper method which launches a standalone preview window. The method accepts a bunch of parameters that can be modified in the upper part of the preview windows. It let's you see your component under varying circumstances. What's also nice about this is that you can also try out interaction with the component. It's not something that's a full-blown library at this point, so you'd need to craft something similar for your own codebase. Here's an example from our project:
a
Not out of the box I guess. But it should work if you place expect/actual Preview annotation in package
androidx.compose.desktop.ui.tooling.preview
. I'm using it in my samples for some time - https://github.com/arkivanov/Decompose/blob/master/sample/shared/compose/src/commonMain/kotlin/androidx/compose/desktop/ui/tooling/preview/Preview.kt The only issue with this approach is https://youtrack.jetbrains.com/issue/KTIJ-24082/
a
@Arkadii Ivanov But it works out of the box? If you include the compose.desktop.currentOS dep it adds the tooling dependency which contains Preview if I am not mistaken
a
a
ya I just do all of my @Previews in my desktop package
215 Views