https://kotlinlang.org logo
#compose
Title
# compose
c

Colton Idle

05/13/2022, 6:00 PM
If I'm using my own custom Material theme (MyAppTheme), should I be trying to access something like
isLight
via
MaterialTheme.colors.isLight
or should I basically never be touching MaterialTheme static accessors? (themeing still confuses me, sorry 🙃 )
z

Zach Klippenstein (he/him) [MOD]

05/13/2022, 6:04 PM
I would be more concerned about explicitly checking for light mode vs just using the colors that are specified. But if you have a good reason, I don't think there's anything wrong with looking at theme values directly.
t

Tolriq

05/13/2022, 6:04 PM
M3 themes no more expose isLight so you might already look for something different to manage this state.
c

Colton Idle

05/13/2022, 6:32 PM
This is what I'm doing
Copy code
val systemUiController = rememberSystemUiController()
val useDarkIcons = MaterialTheme.colors.isLight

SideEffect {
  // Update all of the system bar colors to be transparent, and use dark icons if we're in light
  // theme
  systemUiController.setSystemBarsColor(color = Color.Transparent, darkIcons = useDarkIcons)
}
t

Tolriq

05/13/2022, 6:43 PM
I did the same but after M3 I know use
Copy code
val LocalThemeDarkMode: ProvidableCompositionLocal<Boolean> =
    staticCompositionLocalOf { error("LocalThemeDarkMode not initialized") }
👍 1
o

Oleksandr Balan

05/13/2022, 7:08 PM
Could you use
androidx.compose.foundation.isSystemInDarkTheme()
directly as default theme wrapper use it to check which palette to provide?
t

Tolriq

05/13/2022, 7:13 PM
You can have the system in dark mode and offer an light theme.
c

Chris Sinco [G]

05/13/2022, 9:53 PM
Do you want to know if the device is in dark or light theme or if your app user setting is set to light or dark?
t

Thomas

05/13/2022, 11:17 PM
I am using the following workaround in material3 because isLight is missing:
Copy code
val ColorScheme.isLight get() = background.luminance() > 0.5f
2 Views