Skip to content

Commit ff21481

Browse files
authored
Fix Compose Previews in the Reply sample (#1358)
Currenly, Compose Previews don't support UIModeManager, so any previews using the ContrastAwareReplyTheme will fail to render when trying to apply contrast. While UIModeManager support is not added, we can work around this issue by not adding contrast in Compose Previews.
2 parents 1c7bac4 + 21ba1d0 commit ff21481

File tree

1 file changed

+4
-1
lines changed
  • Reply/app/src/main/java/com/example/reply/ui/theme

1 file changed

+4
-1
lines changed

Reply/app/src/main/java/com/example/reply/ui/theme/Theme.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import androidx.compose.runtime.Composable
3030
import androidx.compose.runtime.SideEffect
3131
import androidx.compose.ui.graphics.toArgb
3232
import androidx.compose.ui.platform.LocalContext
33+
import androidx.compose.ui.platform.LocalInspectionMode
3334
import androidx.compose.ui.platform.LocalView
3435
import androidx.core.view.WindowCompat
3536

@@ -269,7 +270,9 @@ fun isContrastAvailable(): Boolean {
269270
fun selectSchemeForContrast(isDark: Boolean,): ColorScheme {
270271
val context = LocalContext.current
271272
var colorScheme = if (isDark) darkScheme else lightScheme
272-
if (isContrastAvailable()) {
273+
val isPreview = LocalInspectionMode.current
274+
// TODO(b/336693596): UIModeManager is not yet supported in preview
275+
if (!isPreview && isContrastAvailable()) {
273276
val uiModeManager = context.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager
274277
val contrastLevel = uiModeManager.contrast
275278

0 commit comments

Comments
 (0)