From f219b2bd5c6cc22618581cda7b36308244306b4e Mon Sep 17 00:00:00 2001 From: Ryan Brooks Date: Wed, 27 Sep 2023 14:27:57 -0700 Subject: [PATCH] Fix locale not working --- .../com/emergetools/snapshots/sample/ui/TextRowWithIcon.kt | 4 ++-- .../snapshots/compose/SnapshotVariantProvider.kt | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/snapshots/sample/app/src/main/kotlin/com/emergetools/snapshots/sample/ui/TextRowWithIcon.kt b/snapshots/sample/app/src/main/kotlin/com/emergetools/snapshots/sample/ui/TextRowWithIcon.kt index a144627c..fe51e2e4 100644 --- a/snapshots/sample/app/src/main/kotlin/com/emergetools/snapshots/sample/ui/TextRowWithIcon.kt +++ b/snapshots/sample/app/src/main/kotlin/com/emergetools/snapshots/sample/ui/TextRowWithIcon.kt @@ -40,8 +40,8 @@ fun TextRowWithIconPreviewFromMain() { @Composable fun TextRowWithIconPreviewFromMainJustMultiPreview() { TextRowWithIcon( - titleText = "Title", - subtitleText = "Subtitle" + titleText = stringResource(com.emergetools.snapshots.sample.R.string.sample_title), + subtitleText = stringResource(com.emergetools.snapshots.sample.R.string.sample_subtitle) ) } diff --git a/snapshots/snapshots/src/main/kotlin/com/emergetools/snapshots/compose/SnapshotVariantProvider.kt b/snapshots/snapshots/src/main/kotlin/com/emergetools/snapshots/compose/SnapshotVariantProvider.kt index 24e9edff..792e9cc2 100644 --- a/snapshots/snapshots/src/main/kotlin/com/emergetools/snapshots/compose/SnapshotVariantProvider.kt +++ b/snapshots/snapshots/src/main/kotlin/com/emergetools/snapshots/compose/SnapshotVariantProvider.kt @@ -4,6 +4,7 @@ import android.content.res.Configuration import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.platform.LocalConfiguration +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.unit.Density import com.emergetools.snapshots.shared.ComposePreviewSnapshotConfig @@ -19,11 +20,12 @@ fun SnapshotVariantProvider( val localConfiguration = Configuration(LocalConfiguration.current).apply { config.uiMode?.let { uiMode = it } - config.locale?.let { setLocale(Locale(it)) } + val locale = config.locale?.let { Locale(it) } ?: Locale.getDefault() + setLocale(locale) } val providedValues = arrayOf( - LocalConfiguration provides localConfiguration, + LocalContext provides LocalContext.current.createConfigurationContext(localConfiguration), config.fontScale?.let { LocalDensity provides fontScaleDensity } ) CompositionLocalProvider(