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

Pierfrancesco Gulinelli

10/26/2019, 1:26 PM
How to use
@Preview
when i need context object?
l

Luca Nicoletti

10/26/2019, 1:30 PM
Do you mean you accept
context
as a parameter in your function?
p

Pierfrancesco Gulinelli

10/26/2019, 1:38 PM
@Preview
doesn't accept parameters, so it must be used with default values; i need context object to load resources as default values
To;Dr; you can create a wrapper function which provides everything to your '@composable' function and annotate that function with '@preview'
p

Pierfrancesco Gulinelli

10/26/2019, 1:56 PM
I already do it, but
@Preview
works only outside Activity (or Fragment) , and outside Activity i haven't context object
l

Luca Nicoletti

10/26/2019, 1:58 PM
Wrong, you have access to context inside
@Composable
functions
Just retrieve it
val context = +ambient(ContextAmbient)
👍 1
p

Pierfrancesco Gulinelli

10/26/2019, 2:01 PM
that's what i missed. Thank you
l

Luca Nicoletti

10/26/2019, 2:01 PM
👍🏼
9 Views