Coverage Summary for Class: Theme_androidKt (com.javiersc.samples.features._theme)
Class |
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
Theme_androidKt |
0%
(0/2)
|
0%
(0/30)
|
0%
(0/11)
|
0%
(0/135)
|
Theme_androidKt$AndroidConfig$1 |
0%
(0/1)
|
|
0%
(0/3)
|
0%
(0/22)
|
Theme_androidKt$AndroidConfig$2 |
|
Total |
0%
(0/3)
|
0%
(0/30)
|
0%
(0/14)
|
0%
(0/157)
|
package com.javiersc.samples.features._theme
import android.app.Activity
import android.os.Build
import androidx.compose.material3.ColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
import androidx.core.view.WindowCompat
@Composable
actual fun colorScheme(dynamicColor: Boolean, isDarkTheme: Boolean): ColorScheme =
when {
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
val context = LocalContext.current
if (isDarkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
}
isDarkTheme -> DarkColorScheme
else -> LightColorScheme
}
@Composable
actual fun AndroidConfig(colorScheme: ColorScheme, isDarkTheme: Boolean) {
val view = LocalView.current
if (!view.isInEditMode) {
SideEffect {
val window = (view.context as Activity).window
window.statusBarColor = colorScheme.primary.toArgb()
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = isDarkTheme
}
}
}