all: add support for dynamic colors

This commit is contained in:
Harsh Shandilya 2021-12-31 01:16:31 +05:30
parent 3f3da0ab18
commit bac7611bee
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80
4 changed files with 46 additions and 14 deletions

View file

@ -0,0 +1,29 @@
package dev.msfjarvis.claw.android.ui
import android.content.Context
import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.ColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.runtime.Composable
import dev.msfjarvis.claw.common.theme.DarkThemeColors
import dev.msfjarvis.claw.common.theme.LightThemeColors
@Composable
fun decideColorScheme(context: Context): ColorScheme {
val isDarkTheme = isSystemInDarkTheme()
return if (Build.VERSION.SDK_INT >= 31) {
if (isDarkTheme) {
dynamicDarkColorScheme(context)
} else {
dynamicLightColorScheme(context)
}
} else {
if (isDarkTheme) {
DarkThemeColors
} else {
LightThemeColors
}
}
}

View file

@ -1,6 +1,5 @@
package dev.msfjarvis.claw.android.ui
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
@ -18,6 +17,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalUriHandler
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.compose.NavHost
@ -92,12 +92,12 @@ fun LobstersApp(
currentDestination = destination.route ?: Destinations.Hottest
}
LobstersTheme(
darkTheme = isSystemInDarkTheme(),
providedValues =
arrayOf(
LocalUriHandler provides urlLauncher,
LocalHTMLConverter provides htmlConverter,
),
colorScheme = decideColorScheme(LocalContext.current),
) {
ProvideWindowInsets {
val statusBarColor = MaterialTheme.colorScheme.background