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

Klaas Kabini

08/16/2020, 6:18 AM
@Adam Powell Which of the two is the recommended way of accessing ambients inside composable functions?
Copy code
1.
val density = DensityAmbient.current
//The code that uses density

2.
Providers(DensityAmbient provides density){
    // The code that use density
}
a

Adam Powell

08/16/2020, 2:47 PM
1 is the consumer and 2 is the producer. If you do 1 in code called from inside the block of 2, it will yield the provided value.