If I'm using my own custom Material theme (MyAppTh...
# compose
c
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
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
M3 themes no more expose isLight so you might already look for something different to manage this state.
c
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
I did the same but after M3 I know use
Copy code
val LocalThemeDarkMode: ProvidableCompositionLocal<Boolean> =
    staticCompositionLocalOf { error("LocalThemeDarkMode not initialized") }
👍 1
o
Could you use
androidx.compose.foundation.isSystemInDarkTheme()
directly as default theme wrapper use it to check which palette to provide?
t
You can have the system in dark mode and offer an light theme.
c
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
I am using the following workaround in material3 because isLight is missing:
Copy code
val ColorScheme.isLight get() = background.luminance() > 0.5f