https://kotlinlang.org logo
#compose
Title
# compose
n

nglauber

09/25/2020, 3:23 AM
Quick question: how can I see the preview of a Composable into the inline documentation? Like @romainguy is showing here:

https://youtu.be/U5BwfqBpiWU?t=475

a

allan.conda

09/25/2020, 3:23 AM
add a `@Preview`annotation as shown there
n

nglauber

09/25/2020, 3:23 AM
It’s not working for me… 😕
a

allan.conda

09/25/2020, 3:25 AM
Check the error? And try to use the latest AS canary. Usually, you would have a separate function with the
@Preview
, where you could pass mock data
n

nglauber

09/25/2020, 3:26 AM
I’m doing a very simple stuff…
Copy code
/**
 * Simple text on the screen
 * @sample DefaultPreview
 */
@Composable
fun Greeting(name: String) {
    Text(text = "Hello $name!")
}

@Preview(showBackground = true)
@Composable
fun DefaultPreview() {
    MyAppTheme {
        Greeting("Androids")
    }
}
What I’m expecting is: If I type “Gre”, and then Ctrl+Space, I should see the preview of my
Greeting
composable. I’m using AS 4.2 Canary 12
This is what I get 👇
a

allan.conda

09/25/2020, 3:30 AM
Ahh, you meant the preview in the documentation. I didn’t know that existed 😄 sorry
n

nglauber

09/25/2020, 3:35 AM
No worries… 😉 This feature is also mentioned by Tor Norbye here (

https://youtu.be/NMFGuy6TRqk?t=429

) but it has never worked for me… 😞
r

romainguy

09/25/2020, 3:42 AM
Try with the fully qualified name instead
n

nglauber

09/25/2020, 3:45 AM
Do you mean in
@sample
?
I tried this
Copy code
@sample _root_ide_package_.com.example.waldyrtest.DefaultPreview()
and this
Copy code
@sample com.example.waldyrtest.DefaultPreview()
r

romainguy

09/25/2020, 3:50 AM
Don't put the parenthesis at the end
And definitely don't use _root etc
n

nglauber

09/25/2020, 3:52 AM
Same thing 😞
I put this in a separate file:
Copy code
/**
 * Simple text on the screen
 *
 * @sample com.example.waldyrtest.DefaultPreview
 */
@Composable
fun Greeting(name: String) {
    Text(text = "Hello $name!")
}

@Preview(showBackground = true)
@Composable
fun DefaultPreview() {
    MyAppTheme {
        Greeting("Androids")
    }
}
Then when I type the function name in the activity file… 👇
I remember that I asked this same question in July… https://kotlinlang.slack.com/archives/CJLTWPH7S/p1594749573264000 😩
Two months later… still not working… 😞
@Leland Richardson [G] could you help me on this?
l

Leland Richardson [G]

09/25/2020, 8:48 PM
hmm. I am not actually very familiar with how this feature works and haven’t used it myself. cc @nosuid who will likely know more. can you help us out?
😞 1
(sorry i cant be of more help)
🙏 1