Skip to content

Commit 776db94

Browse files
committed
Read the subheader locale observably to satisfy lint
Reading Locale.getDefault() in a composable trips lint's NonObservableLocale (the header wouldn't recompose on a locale change). Read the locale from LocalConfiguration via ConfigurationCompat instead, matching the existing stats-card pattern, keeping the locale-aware uppercase.
1 parent e970f8f commit 776db94

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

WordPress/src/main/java/org/wordpress/android/ui/commentsrs/screens/CommentsRsListItem.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ import androidx.compose.ui.draw.clip
2929
import androidx.compose.ui.graphics.Color
3030
import androidx.compose.ui.graphics.vector.rememberVectorPainter
3131
import androidx.compose.ui.layout.ContentScale
32+
import androidx.compose.ui.platform.LocalConfiguration
3233
import androidx.compose.ui.res.stringResource
3334
import androidx.compose.ui.text.AnnotatedString
3435
import androidx.compose.ui.text.SpanStyle
3536
import androidx.compose.ui.text.buildAnnotatedString
3637
import androidx.compose.ui.text.font.FontWeight
3738
import androidx.compose.ui.text.style.TextOverflow
3839
import androidx.compose.ui.unit.dp
40+
import androidx.core.os.ConfigurationCompat
3941
import coil.compose.AsyncImage
4042
import org.wordpress.android.R
4143
import org.wordpress.android.ui.commentsrs.CommentRsUiModel
@@ -178,10 +180,12 @@ private fun AnnotatedString.Builder.boldRange(formatted: String, part: String) {
178180
/** A date-group subheader row, matching the legacy list's all-caps overline separators. */
179181
@Composable
180182
fun CommentsRsDateHeader(label: String, modifier: Modifier = Modifier) {
183+
// Locale-aware uppercase, like the legacy subheader's android:textAllCaps (Kotlin's no-arg
184+
// uppercase() is Locale.ROOT and would mis-case e.g. Turkish month names). Read the locale
185+
// observably from the composition so it tracks locale changes.
186+
val locale = ConfigurationCompat.getLocales(LocalConfiguration.current)[0] ?: Locale.ROOT
181187
Text(
182-
// Locale-aware uppercase, like the legacy subheader's android:textAllCaps (Kotlin's no-arg
183-
// uppercase() is Locale.ROOT and would mis-case e.g. Turkish month names).
184-
text = label.uppercase(Locale.getDefault()),
188+
text = label.uppercase(locale),
185189
style = MaterialTheme.typography.labelMedium,
186190
color = MaterialTheme.colorScheme.onSurfaceVariant,
187191
maxLines = 1,

0 commit comments

Comments
 (0)