Quick question: how can I see the preview of a Com...
# compose
n
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
add a `@Preview`annotation as shown there
n
It’s not working for me… 😕
a
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
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
Ahh, you meant the preview in the documentation. I didn’t know that existed 😄 sorry
n
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
Try with the fully qualified name instead
n
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
Don't put the parenthesis at the end
And definitely don't use _root etc
n
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
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