joney
12/09/2021, 8:47 AMpackage androidx.compose.ui.res
provides access to resources as follows (src):
@Composable
@ReadOnlyComposable
private fun resources(): Resources {
LocalConfiguration.current //<---- why?
return LocalContext.current.resources
}
☝️ I wonder why a call to LocalConfiguration.current
is needed before accessing the resources
field. Is this a pattern which I should follow for any values provided with local composition?
👇 So should I do this in my own code?
@Composable
@ReadOnlyComposable
private fun myThing(): MyThing {
LocalThings.current //<---- why?
return LocalSomeThings.current.myThing
}
Albert Chang
12/09/2021, 9:25 AMLocalConfiguration
is read here to make sure when there is a configuration change the resources is re-retrieved as there are cases where configuration changes but context doesn't change. You don't need to do this unless you are sure it's necessary.joney
12/09/2021, 9:36 AMTolriq
12/09/2021, 7:19 PMAlbert Chang
12/10/2021, 12:40 AMTolriq
12/10/2021, 7:47 AMval X by XXX.collectAsState()
X
Causes problems with R8 (And the IDE also says X is unused)
Doing
val X = XXX.collectAsState()
X.value
Does work.
Since IDE behavior is consistent with R8 not sure it's R8 side. But maybe it's normal?Albert Chang
12/10/2021, 8:34 AMTolriq
12/10/2021, 9:00 AMAlbert Chang
12/10/2021, 9:07 AM@Suppress("unused")
. Reading a property (or whatever you like to call it) with delegate is actually invoking a function so as long as it is not side effect free it shouldn't be stripped out by R8. And by saying I can't reproduce it I mean R8 didn't stripped the invocation out.Tolriq
12/10/2021, 9:17 AM