File tree 1 file changed +17
-6
lines changed
app/src/main/java/dev/davwheat/railway/gateline_errors/ui/theme
1 file changed +17
-6
lines changed Original file line number Diff line number Diff line change 1
1
package dev.davwheat.railway.gateline_errors.ui.theme
2
2
3
+ import android.os.Build
3
4
import androidx.compose.foundation.isSystemInDarkTheme
4
5
import androidx.compose.material3.MaterialTheme
5
6
import androidx.compose.material3.darkColorScheme
7
+ import androidx.compose.material3.dynamicDarkColorScheme
8
+ import androidx.compose.material3.dynamicLightColorScheme
6
9
import androidx.compose.material3.lightColorScheme
7
10
import androidx.compose.runtime.Composable
11
+ import androidx.compose.ui.platform.LocalContext
8
12
9
13
private val LightColors =
10
14
lightColorScheme(
@@ -74,12 +78,19 @@ private val DarkColors =
74
78
75
79
@Composable
76
80
fun AppTheme (useDarkTheme : Boolean = isSystemInDarkTheme(), content : @Composable () -> Unit ) {
77
- val colors =
78
- if (! useDarkTheme) {
79
- LightColors
80
- } else {
81
- DarkColors
81
+ val supportsDynamicColor = Build .VERSION .SDK_INT >= Build .VERSION_CODES .S
82
+
83
+ val colorScheme =
84
+ when {
85
+ supportsDynamicColor && useDarkTheme -> {
86
+ dynamicDarkColorScheme(LocalContext .current)
87
+ }
88
+ supportsDynamicColor && ! useDarkTheme -> {
89
+ dynamicLightColorScheme(LocalContext .current)
90
+ }
91
+ useDarkTheme -> DarkColors
92
+ else -> LightColors
82
93
}
83
94
84
- MaterialTheme (colorScheme = colors , content = content)
95
+ MaterialTheme (colorScheme = colorScheme , content = content)
85
96
}
You can’t perform that action at this time.
0 commit comments