mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 11:47:04 +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
|
package dev.msfjarvis.claw.android.ui
|
||||||
|
|
||||||
import androidx.compose.foundation.isSystemInDarkTheme
|
|
||||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.MaterialTheme
|
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.NestedScrollConnection
|
||||||
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
|
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
|
||||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.platform.LocalUriHandler
|
import androidx.compose.ui.platform.LocalUriHandler
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
import androidx.navigation.compose.NavHost
|
import androidx.navigation.compose.NavHost
|
||||||
|
@ -92,12 +92,12 @@ fun LobstersApp(
|
||||||
currentDestination = destination.route ?: Destinations.Hottest
|
currentDestination = destination.route ?: Destinations.Hottest
|
||||||
}
|
}
|
||||||
LobstersTheme(
|
LobstersTheme(
|
||||||
darkTheme = isSystemInDarkTheme(),
|
|
||||||
providedValues =
|
providedValues =
|
||||||
arrayOf(
|
arrayOf(
|
||||||
LocalUriHandler provides urlLauncher,
|
LocalUriHandler provides urlLauncher,
|
||||||
LocalHTMLConverter provides htmlConverter,
|
LocalHTMLConverter provides htmlConverter,
|
||||||
),
|
),
|
||||||
|
colorScheme = decideColorScheme(LocalContext.current),
|
||||||
) {
|
) {
|
||||||
ProvideWindowInsets {
|
ProvideWindowInsets {
|
||||||
val statusBarColor = MaterialTheme.colorScheme.background
|
val statusBarColor = MaterialTheme.colorScheme.background
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package dev.msfjarvis.claw.common.theme
|
package dev.msfjarvis.claw.common.theme
|
||||||
|
|
||||||
import androidx.compose.foundation.isSystemInDarkTheme
|
import androidx.compose.material3.ColorScheme
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.darkColorScheme
|
import androidx.compose.material3.darkColorScheme
|
||||||
import androidx.compose.material3.lightColorScheme
|
import androidx.compose.material3.lightColorScheme
|
||||||
|
@ -11,7 +11,7 @@ import androidx.compose.ui.graphics.Color
|
||||||
|
|
||||||
val titleColor = Color(0xFF7395D9)
|
val titleColor = Color(0xFF7395D9)
|
||||||
|
|
||||||
private val LightThemeColors =
|
val LightThemeColors =
|
||||||
lightColorScheme(
|
lightColorScheme(
|
||||||
primary = md_theme_light_primary,
|
primary = md_theme_light_primary,
|
||||||
onPrimary = md_theme_light_onPrimary,
|
onPrimary = md_theme_light_onPrimary,
|
||||||
|
@ -40,7 +40,7 @@ private val LightThemeColors =
|
||||||
inverseSurface = md_theme_light_inverseSurface,
|
inverseSurface = md_theme_light_inverseSurface,
|
||||||
)
|
)
|
||||||
|
|
||||||
private val DarkThemeColors =
|
val DarkThemeColors =
|
||||||
darkColorScheme(
|
darkColorScheme(
|
||||||
primary = md_theme_dark_primary,
|
primary = md_theme_dark_primary,
|
||||||
onPrimary = md_theme_dark_onPrimary,
|
onPrimary = md_theme_dark_onPrimary,
|
||||||
|
@ -71,17 +71,11 @@ private val DarkThemeColors =
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun LobstersTheme(
|
fun LobstersTheme(
|
||||||
darkTheme: Boolean = isSystemInDarkTheme(),
|
|
||||||
providedValues: Array<ProvidedValue<*>> = emptyArray(),
|
providedValues: Array<ProvidedValue<*>> = emptyArray(),
|
||||||
|
colorScheme: ColorScheme,
|
||||||
content: @Composable () -> Unit,
|
content: @Composable () -> Unit,
|
||||||
) {
|
) {
|
||||||
val colors =
|
|
||||||
if (!darkTheme) {
|
|
||||||
LightThemeColors
|
|
||||||
} else {
|
|
||||||
DarkThemeColors
|
|
||||||
}
|
|
||||||
CompositionLocalProvider(*providedValues) {
|
CompositionLocalProvider(*providedValues) {
|
||||||
MaterialTheme(colorScheme = colors, typography = AppTypography, content = content)
|
MaterialTheme(colorScheme = colorScheme, typography = AppTypography, content = content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import androidx.compose.foundation.isSystemInDarkTheme
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.fillMaxHeight
|
import androidx.compose.foundation.layout.fillMaxHeight
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
@ -18,6 +19,8 @@ import dev.msfjarvis.claw.api.LobstersApi
|
||||||
import dev.msfjarvis.claw.common.posts.LobstersCard
|
import dev.msfjarvis.claw.common.posts.LobstersCard
|
||||||
import dev.msfjarvis.claw.common.posts.PostActions
|
import dev.msfjarvis.claw.common.posts.PostActions
|
||||||
import dev.msfjarvis.claw.common.posts.toDbModel
|
import dev.msfjarvis.claw.common.posts.toDbModel
|
||||||
|
import dev.msfjarvis.claw.common.theme.DarkThemeColors
|
||||||
|
import dev.msfjarvis.claw.common.theme.LightThemeColors
|
||||||
import dev.msfjarvis.claw.common.theme.LobstersTheme
|
import dev.msfjarvis.claw.common.theme.LobstersTheme
|
||||||
import dev.msfjarvis.claw.common.urllauncher.UrlLauncher
|
import dev.msfjarvis.claw.common.urllauncher.UrlLauncher
|
||||||
import dev.msfjarvis.claw.database.local.SavedPost
|
import dev.msfjarvis.claw.database.local.SavedPost
|
||||||
|
@ -59,8 +62,14 @@ fun main() = auroraApplication {
|
||||||
undecorated = true,
|
undecorated = true,
|
||||||
onCloseRequest = ::exitApplication,
|
onCloseRequest = ::exitApplication,
|
||||||
) {
|
) {
|
||||||
|
val colorScheme =
|
||||||
|
if (isSystemInDarkTheme()) {
|
||||||
|
DarkThemeColors
|
||||||
|
} else {
|
||||||
|
LightThemeColors
|
||||||
|
}
|
||||||
LobstersTheme(
|
LobstersTheme(
|
||||||
darkTheme = false,
|
colorScheme = colorScheme,
|
||||||
providedValues = arrayOf(LocalUriHandler provides urlLauncher),
|
providedValues = arrayOf(LocalUriHandler provides urlLauncher),
|
||||||
) {
|
) {
|
||||||
Box(
|
Box(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue