Theme: fix themes for composables
This commit is contained in:
@@ -17,24 +17,33 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.colorResource
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.util.Preferences
|
||||
|
||||
/**
|
||||
* App theme for Aurora Store based on [MaterialTheme]
|
||||
*/
|
||||
@Composable
|
||||
fun AuroraTheme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable () -> Unit) {
|
||||
val colorScheme = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
if (darkTheme) {
|
||||
dynamicDarkColorScheme(LocalContext.current)
|
||||
} else {
|
||||
dynamicLightColorScheme(LocalContext.current)
|
||||
}
|
||||
fun AuroraTheme(content: @Composable () -> Unit) {
|
||||
val context = LocalContext.current
|
||||
val themeStyle = Preferences.getInteger(context, Preferences.PREFERENCE_THEME_STYLE)
|
||||
val isDynamicColorSupported = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
|
||||
|
||||
val lightScheme = if (isDynamicColorSupported) {
|
||||
dynamicLightColorScheme(context)
|
||||
} else {
|
||||
if (darkTheme) {
|
||||
darkColorScheme(primary = colorResource(id = R.color.colorAccent))
|
||||
} else {
|
||||
lightColorScheme(primary = colorResource(id = R.color.colorAccent))
|
||||
}
|
||||
lightColorScheme(primary = colorResource(id = R.color.colorAccent))
|
||||
}
|
||||
|
||||
val darkScheme = if (isDynamicColorSupported) {
|
||||
dynamicDarkColorScheme(context)
|
||||
} else {
|
||||
darkColorScheme(primary = colorResource(id = R.color.colorAccent))
|
||||
}
|
||||
|
||||
val colorScheme = when (themeStyle) {
|
||||
1 -> lightScheme
|
||||
2 -> darkScheme
|
||||
else -> if (isSystemInDarkTheme()) darkScheme else lightScheme
|
||||
}
|
||||
|
||||
MaterialTheme(colorScheme = colorScheme, typography = Typography(), content = content)
|
||||
|
||||
Reference in New Issue
Block a user