Christopher Mederos
06/20/2024, 5:54 AMCompositionLocal
since units are usually 4-6 children deep in my composable hierarchy. I'm thinking of storing the setting in my cache (realm), making it available in a viewmodel, collecting the state and making it available via CompositionLocalProvider just above my NavHost. Then I'd pass the viewmodel method reference to update the setting values to my "settings screen" composable.
Is that reasonable? Is that easier than passing a UnitsPreference arg a bunch of times? Thanks!Christopher Mederos
06/20/2024, 5:55 AMStylianos Gakis
06/20/2024, 10:45 AMcurioustechizen
06/20/2024, 12:29 PMcurioustechizen
06/20/2024, 12:30 PMformatter.format(value)
It is the Formatter's responsibility to know what the unit is.Stylianos Gakis
06/20/2024, 1:06 PMa user setting that comes from the "data layer" somewhere so your formatter can observer the change in this value, without the Composable ever being involvedThis means that the formatter is still something that lives throughout the entire app's lifecycle and needs to somehow be present at those child composables right? Are you simply creating that at root level and then passing it down to the callers that need it, no matter the depth?
curioustechizen
06/20/2024, 1:12 PM@Composable
internal fun LocalDate.formatForSurveyHeader(): String {
val locale = LocalConfiguration.current.locales[0]
val formatter = remember(locale) {
DateTimeFormatter.ofPattern("EEEE d MMMM", locale)
}
return this.toJavaLocalDate().format(formatter)
}
So in essence this is indeed using a CompositionLocal (in this case LocalConfiguration
)Christopher Mederos
06/26/2024, 5:06 AMChristopher Mederos
06/26/2024, 8:00 AM