mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 16:27:06 +05:30
all: add support for dynamic colors
This commit is contained in:
parent
3f3da0ab18
commit
bac7611bee
4 changed files with 46 additions and 14 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue