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

Mehdi Haghgoo

05/18/2022, 7:15 AM
Hi, what does
with(LocalDensity.current){sizeDp.toPx()}
really do?
f

Filip Wiesner

05/18/2022, 7:18 AM
You can look at the implementation
m

Mehdi Haghgoo

05/18/2022, 7:36 AM
I know, but what is the effect of calling Dp.toPx() inside
with(){}
?
f

Filip Wiesner

05/18/2022, 7:42 AM
You can't call it otherwise. You have to be in
Density
context (
this is Density
) to access this conversion extension function. You could also do
LocalDensity.current.run { sizeDp.toPx() }
❤️ 1
It's because this extension function is defined in
Density
interface so it has two receivers (contexts). One is
Density
and one is
Dp
defined on the function
❤️ 1
14 Views