Stylianos Gakis
03/22/2023, 10:40 PMresources()
marked as internal in androidx.compose.ui.res ?
I am in a place where I need to decide on a string to be used inside my ViewModel. As described here, I am only exposing the StringRes Int from there, and I need to then resolve that string inside my composable. Specifically, I am outside of a composable context since I am resolving it inside a lambda, so I can’t just use the stringResource()
function which uses this function internally.
So it turns out I need to do what stringResource()
does interally myself, which is
LocalConfiguration.current
return LocalContext.current.resources
So that I make sure I read LocalConfig in order to make sure I do not grab stale data.
resources()
already exists and does this exact thing, but it’s marked as internal, shouldn’t that just be a public function?dewildte
03/23/2023, 3:37 AMStylianos Gakis
03/23/2023, 8:10 AMStylianos Gakis
03/23/2023, 11:14 AMResources
the same way that resources()
does would be very valuable. I wrote this report to see what they think.myanmarking
03/23/2023, 11:42 AMdewildte
03/23/2023, 4:26 PMIt is perfectly fine to add a string to viewmodel, you just SHOULDN’T resolve it there. In your case, just create a layer of indirection to build the string lazilyAnd how does this work when Unit testing the ViewModel?
myanmarking
03/23/2023, 4:28 PMdewildte
03/23/2023, 4:34 PMdewildte
03/23/2023, 4:37 PMdewildte
03/23/2023, 4:39 PMmyanmarking
03/23/2023, 4:42 PMdewildte
03/23/2023, 4:55 PMmyanmarking
03/23/2023, 4:59 PMdewildte
03/23/2023, 5:36 PMmyanmarking
03/23/2023, 5:36 PMmyanmarking
03/23/2023, 5:37 PM