https://kotlinlang.org logo
Title
d

David W

12/02/2021, 5:28 PM
Does the preview tool actually work for others? It stopped working for me the instant I split things into multiple Composable methods/files.
m

mcpiroman

12/02/2021, 5:30 PM
It does not for me - after Rendering... is gone nothing is shown in the preview winodw
o

olonho

12/02/2021, 5:49 PM
cc: @alexey.tsvetkov
Please report an issue with reproducer
d

David W

12/02/2021, 6:24 PM
Thanks. I honestly didn't realize it was expected to be working :S
just to double-check, i'm not doing anything obviously wrong here, right?
compose plugin is installed and up to date, function is marked as
@Preview
, and there's no preview gutter icon nor tab. this is the latest stable version of IntelliJ Ultimate and compose 1.0.0
a

Asapha

12/02/2021, 8:11 PM
In your particular example, it doesn’t work due to the function’s receiver parameter, no?
d

David W

12/02/2021, 8:17 PM
You appear to be right...maybe I have a fundamental misunderstanding of things, then. How do we pass information to a
@Composable
function without being able to use a receiver parameter or arguments, since those disable previewing?
Or are you just SOL if your composable needs params?
a

Asapha

12/02/2021, 8:41 PM
You can create a
@Preview
that passes the necessary params to the “real”
@Composable
@Composable
fun MyAwesomeComposable(text: String) {
    Text(text)
}

@Preview
@Composable
fun MyAwesomeComposablePreview() {
    MyAwesomeComposable("Hello there")
}
1
c

Cody Mikol

12/02/2021, 8:44 PM
I do the same as the above and it seems to work fine
d

David W

12/02/2021, 9:03 PM
oh, that's a clever workaround
c

Cody Mikol

12/03/2021, 3:23 AM
I don't think its so much a workaround, its the intended use for @Preview
k

Kebbin

12/04/2021, 10:08 AM
Interesting! Thanks.
m

mcpiroman

12/04/2021, 6:45 PM
Actually I was checking with some recent RC and it did not work but now with 1.0 it does!