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

dimsuz

02/08/2022, 1:54 PM
I'm curious why is
LocalConfiguration.current
present in the Compose's
resources()
. Does it have the effect of recomposing when
Configuration
changes?
Copy code
@Composable
@ReadOnlyComposable
private fun resources(): Resources {
    LocalConfiguration.current
    return LocalContext.current.resources
}
s

sindrenm

02/08/2022, 2:03 PM
Yeah, I think it's to make sure it recomposes when
LocalConfiguration.current
changes. 👍
Here's the CR for it, you can have a look at the conversation in the comments for more insight.
d

dimsuz

02/08/2022, 2:39 PM
Great, thank you!
a

Arjun Achatz

02/08/2022, 5:34 PM
Oh jeez.. this is gonna make reading compose code a bit more difficult 😅
d

dimsuz

02/08/2022, 5:35 PM
Well, this seems more like an exception. Above linked PR contains some details on this particular instance.
z

Zach Klippenstein (he/him) [MOD]

02/09/2022, 8:00 PM
Yea, this is a weird case because of the way the underlying state can change.
resources
can change out from under us whenever a config change happens, but the
Context
itself doesn’t change, so we have to explicitly observe the configuration object to know when the resources might have changed.
👍 1
👍🏻 1
Oh jeez.. this is gonna make reading compose code a bit more difficult
It shouldn’t – this implementation detail is to ensure that callers of this
resources()
function are restarted whenever the resources might have changed, which is standard behavior for composable functions – they restart when state they consume is changed.
18 Views