Skip to content

Commit

Permalink
Issue 220 - Fix dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Android Team committed Feb 21, 2022
1 parent 5f54211 commit 1a2e584
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.airbnb.android.showkase.ui

internal enum class ShowkaseComponentCardType {
BASIC,
DARK_MODE,
INVERSE_MODE,
RTL,
FONT_SCALE,
DISPLAY_SCALED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.airbnb.android.showkase.ui

import android.content.Context
import android.content.res.Configuration
import android.content.res.Configuration.UI_MODE_NIGHT_NO
import android.content.res.Configuration.UI_MODE_NIGHT_YES
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -83,7 +85,7 @@ internal fun ShowkaseComponentDetailScreen(
metadata
)
ShowkaseComponentCardType.RTL -> RTLComponentCard(metadata)
ShowkaseComponentCardType.DARK_MODE -> DarkModeComponentCard(metadata)
ShowkaseComponentCardType.INVERSE_MODE -> InverseModeComponentCard(metadata)
}
}
}
Expand Down Expand Up @@ -180,13 +182,14 @@ private fun RTLComponentCard(metadata: ShowkaseBrowserComponent) {
}

@Composable
private fun DarkModeComponentCard(metadata: ShowkaseBrowserComponent) {
val customConfiguration = Configuration(LocalConfiguration.current).apply {
uiMode = Configuration.UI_MODE_NIGHT_YES
}
private fun InverseModeComponentCard(metadata: ShowkaseBrowserComponent) {
val configuration = Configuration(LocalConfiguration.current)
val modeIsDark = (configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == UI_MODE_NIGHT_YES
configuration.uiMode = if (modeIsDark) UI_MODE_NIGHT_NO else UI_MODE_NIGHT_YES

ComponentCardTitle("${metadata.componentName} [Dark Mode]")
CompositionLocalProvider(LocalConfiguration provides customConfiguration) {
val inverseModeString = if (modeIsDark) "Light" else "Dark"
ComponentCardTitle("${metadata.componentName} [$inverseModeString Mode]")
CompositionLocalProvider(LocalConfiguration provides configuration) {
ComponentCard(metadata)
}
}
Expand Down

0 comments on commit 1a2e584

Please sign in to comment.