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