1
+ package org.care.packie.ui.theme
2
+
3
+ import android.app.Activity
4
+ import android.os.Build
5
+ import androidx.compose.foundation.isSystemInDarkTheme
6
+ import androidx.compose.material3.MaterialTheme
7
+ import androidx.compose.material3.darkColorScheme
8
+ import androidx.compose.material3.dynamicDarkColorScheme
9
+ import androidx.compose.material3.dynamicLightColorScheme
10
+ import androidx.compose.material3.lightColorScheme
11
+ import androidx.compose.runtime.Composable
12
+ import androidx.compose.runtime.SideEffect
13
+ import androidx.compose.ui.graphics.toArgb
14
+ import androidx.compose.ui.platform.LocalContext
15
+ import androidx.compose.ui.platform.LocalView
16
+ import androidx.core.view.WindowCompat
17
+
18
+ private val DarkColorScheme = darkColorScheme(
19
+ primary = Purple80 ,
20
+ secondary = PurpleGrey80 ,
21
+ tertiary = Pink80
22
+ )
23
+
24
+ private val LightColorScheme = lightColorScheme(
25
+ primary = Purple40 ,
26
+ secondary = PurpleGrey40 ,
27
+ tertiary = Pink40
28
+
29
+ /* Other default colors to override
30
+ background = Color(0xFFFFFBFE),
31
+ surface = Color(0xFFFFFBFE),
32
+ onPrimary = Color.White,
33
+ onSecondary = Color.White,
34
+ onTertiary = Color.White,
35
+ onBackground = Color(0xFF1C1B1F),
36
+ onSurface = Color(0xFF1C1B1F),
37
+ */
38
+ )
39
+
40
+ @Composable
41
+ fun PackieTheme (
42
+ darkTheme : Boolean = isSystemInDarkTheme(),
43
+ // Dynamic color is available on Android 12+
44
+ dynamicColor : Boolean = true,
45
+ content : @Composable () -> Unit
46
+ ) {
47
+ val colorScheme = when {
48
+ dynamicColor && Build .VERSION .SDK_INT >= Build .VERSION_CODES .S -> {
49
+ val context = LocalContext .current
50
+ if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
51
+ }
52
+
53
+ darkTheme -> DarkColorScheme
54
+ else -> LightColorScheme
55
+ }
56
+ val view = LocalView .current
57
+ if (! view.isInEditMode) {
58
+ SideEffect {
59
+ val window = (view.context as Activity ).window
60
+ window.statusBarColor = colorScheme.primary.toArgb()
61
+ WindowCompat .getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme
62
+ }
63
+ }
64
+
65
+ MaterialTheme (
66
+ colorScheme = colorScheme,
67
+ typography = Typography ,
68
+ content = content
69
+ )
70
+ }
0 commit comments