Skip to content

Commit

Permalink
[1.226.*] Pre-release merge (#704)
Browse files Browse the repository at this point in the history
  • Loading branch information
tramline-github[bot] authored Aug 8, 2024
2 parents ffcfa4f + 8b388f8 commit b01f1cd
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import dev.sasikanth.rss.reader.search.ui.SearchScreen
import dev.sasikanth.rss.reader.settings.ui.SettingsScreen
import dev.sasikanth.rss.reader.share.LocalShareHandler
import dev.sasikanth.rss.reader.share.ShareHandler
import dev.sasikanth.rss.reader.ui.DynamicContentTheme
import dev.sasikanth.rss.reader.ui.AppTheme
import dev.sasikanth.rss.reader.ui.LocalDynamicColorState
import dev.sasikanth.rss.reader.ui.darkAppColorScheme
import dev.sasikanth.rss.reader.ui.lightAppColorScheme
Expand Down Expand Up @@ -102,7 +102,7 @@ fun App(

LaunchedEffect(useDarkTheme) { onThemeChange(useDarkTheme) }

DynamicContentTheme(useDarkTheme = useDarkTheme) {
AppTheme(useDarkTheme = useDarkTheme) {
ProvideStrings {
Box {
Children(
Expand Down Expand Up @@ -159,12 +159,12 @@ fun App(
)
}
is Screen.AddFeed -> {
DynamicContentTheme(useDarkTheme = true) {
AppTheme(useDarkTheme = true) {
AddFeedScreen(presenter = screen.presenter, modifier = fillMaxSizeModifier)
}
}
is Screen.GroupDetails -> {
DynamicContentTheme(useDarkTheme = true) {
AppTheme(useDarkTheme = true) {
GroupScreen(presenter = screen.presenter, modifier = fillMaxSizeModifier)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ import dev.sasikanth.rss.reader.resources.icons.Website
import dev.sasikanth.rss.reader.resources.strings.LocalStrings
import dev.sasikanth.rss.reader.share.LocalShareHandler
import dev.sasikanth.rss.reader.ui.AppTheme
import dev.sasikanth.rss.reader.ui.DynamicContentTheme
import dev.sasikanth.rss.reader.ui.SYSTEM_SCRIM
import dev.sasikanth.rss.reader.utils.KeyboardState
import dev.sasikanth.rss.reader.utils.keyboardVisibilityAsState
Expand All @@ -117,7 +116,7 @@ fun FeedInfoBottomSheet(
}
}

DynamicContentTheme(useDarkTheme = true) {
AppTheme(useDarkTheme = true) {
ModalBottomSheet(
modifier = Modifier.then(modifier),
onDismissRequest = { feedPresenter.dispatch(FeedEvent.BackClicked) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,11 @@ import dev.sasikanth.rss.reader.resources.icons.Add
import dev.sasikanth.rss.reader.resources.icons.TwineIcons
import dev.sasikanth.rss.reader.resources.strings.LocalStrings
import dev.sasikanth.rss.reader.ui.AppTheme
import dev.sasikanth.rss.reader.ui.DynamicContentTheme
import dev.sasikanth.rss.reader.ui.SYSTEM_SCRIM

@Composable
fun GroupSelectionSheet(presenter: GroupSelectionPresenter, modifier: Modifier = Modifier) {
DynamicContentTheme(useDarkTheme = true) {
AppTheme(useDarkTheme = true) {
ModalBottomSheet(
modifier = Modifier.then(modifier),
onDismissRequest = { presenter.dispatch(GroupSelectionEvent.BackClicked) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ import dev.sasikanth.rss.reader.resources.icons.Feed
import dev.sasikanth.rss.reader.resources.icons.TwineIcons
import dev.sasikanth.rss.reader.resources.strings.LocalStrings
import dev.sasikanth.rss.reader.ui.AppTheme
import dev.sasikanth.rss.reader.ui.DynamicContentTheme
import dev.sasikanth.rss.reader.ui.LocalDynamicColorState
import dev.sasikanth.rss.reader.utils.inverse
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -143,12 +142,12 @@ internal fun HomeScreen(
}
}

DynamicContentTheme(useDarkTheme = true) {
AppTheme(useDarkTheme = true) {
BottomSheetScaffold(
modifier = modifier,
scaffoldState = bottomSheetScaffoldState,
content = { _ ->
DynamicContentTheme(useDarkTheme = useDarkTheme) {
AppTheme(useDarkTheme = useDarkTheme) {
Box(
modifier =
Modifier.fillMaxSize().background(AppTheme.colorScheme.surfaceContainerLowest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package dev.sasikanth.rss.reader.ui

import androidx.collection.lruCache
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.Stable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -37,11 +36,6 @@ import dev.sasikanth.rss.reader.utils.Constants.EPSILON
import dev.sasikanth.rss.reader.utils.inverse
import kotlin.math.absoluteValue

@Composable
internal fun DynamicContentTheme(useDarkTheme: Boolean = false, content: @Composable () -> Unit) {
AppTheme(useDarkTheme = useDarkTheme, content = content)
}

@Composable
internal fun rememberDynamicColorState(
defaultLightAppColorScheme: AppColorScheme,
Expand All @@ -66,7 +60,7 @@ internal class DynamicColorState(
var darkAppColorScheme by mutableStateOf(defaultDarkAppColorScheme)
private set

private val cache = lruCache<String, DynamicColors>(maxSize = 4)
private val cache = lruCache<String, AppColorScheme>(maxSize = 4)

fun animate(fromSeedColor: Color, toSeedColor: Color, progress: Float) {
val normalizedProgress =
Expand All @@ -93,18 +87,21 @@ internal class DynamicColorState(
?: generateDynamicColorsFromSeedColor(useDarkTheme = true, seedColor = toSeedColor)

lightAppColorScheme =
defaultLightAppColorScheme.animate(
startColors = startLightColors,
endColors = endLightColors,
progress = normalizedProgress
)
if (startLightColors == endLightColors) {
startLightColors
} else {
startLightColors.animate(to = endLightColors, progress = normalizedProgress)
}

darkAppColorScheme =
defaultDarkAppColorScheme.animate(
startColors = startDarkColors,
endColors = endDarkColors,
progress = normalizedProgress,
)
if (startDarkColors == endDarkColors) {
startDarkColors
} else {
startDarkColors.animate(
to = endDarkColors,
progress = normalizedProgress,
)
}
}

fun reset() {
Expand All @@ -115,16 +112,22 @@ internal class DynamicColorState(
private fun generateDynamicColorsFromSeedColor(
useDarkTheme: Boolean,
seedColor: Color
): DynamicColors {
): AppColorScheme {
val scheme =
SchemeContent(
sourceColorHct = Hct.fromInt(seedColor.toArgb()),
isDark = useDarkTheme,
contrastLevel = 0.0
)
val dynamicColors = MaterialDynamicColors()
val defaultColorScheme =
if (useDarkTheme) {
defaultDarkAppColorScheme
} else {
defaultLightAppColorScheme
}

return DynamicColors(
return AppColorScheme(
tintedBackground =
DynamicColor.fromPalette(
palette = { s -> s.primaryPalette },
Expand Down Expand Up @@ -191,6 +194,8 @@ internal class DynamicColorState(
surfaceContainerLowest = dynamicColors.surfaceContainerLowest().toColor(scheme),
surfaceContainerHigh = dynamicColors.surfaceContainerHigh().toColor(scheme),
surfaceContainerHighest = dynamicColors.surfaceContainerHighest().toColor(scheme),
textEmphasisHigh = defaultColorScheme.textEmphasisHigh,
textEmphasisMed = defaultColorScheme.textEmphasisMed,
)
}

Expand All @@ -199,98 +204,35 @@ internal class DynamicColorState(
}
}

@Immutable
data class DynamicColors(
val tintedBackground: Color,
val tintedSurface: Color,
val tintedForeground: Color,
val tintedHighlight: Color,
val outline: Color,
val outlineVariant: Color,
val surface: Color,
val onSurface: Color,
val onSurfaceVariant: Color,
val surfaceContainer: Color,
val surfaceContainerLow: Color,
val surfaceContainerLowest: Color,
val surfaceContainerHigh: Color,
val surfaceContainerHighest: Color,
)

fun AppColorScheme.animate(
startColors: DynamicColors?,
endColors: DynamicColors?,
to: AppColorScheme?,
progress: Float,
): AppColorScheme {
if (startColors == null || endColors == null) return this
if (to == null) return this

return copy(
tintedBackground =
lerp(
start = startColors.tintedBackground,
stop = endColors.tintedBackground,
fraction = progress
),
tintedSurface =
lerp(start = startColors.tintedSurface, stop = endColors.tintedSurface, fraction = progress),
lerp(start = tintedBackground, stop = to.tintedBackground, fraction = progress),
tintedSurface = lerp(start = tintedSurface, stop = to.tintedSurface, fraction = progress),
tintedForeground =
lerp(
start = startColors.tintedForeground,
stop = endColors.tintedForeground,
fraction = progress
),
tintedHighlight =
lerp(
start = startColors.tintedHighlight,
stop = endColors.tintedHighlight,
fraction = progress
),
outline = lerp(start = startColors.outline, stop = endColors.outline, fraction = progress),
outlineVariant =
lerp(
start = startColors.outlineVariant,
stop = endColors.outlineVariant,
fraction = progress
),
surface = lerp(start = startColors.surface, stop = endColors.surface, fraction = progress),
onSurface =
lerp(start = startColors.onSurface, stop = endColors.onSurface, fraction = progress),
lerp(start = tintedForeground, stop = to.tintedForeground, fraction = progress),
tintedHighlight = lerp(start = tintedHighlight, stop = to.tintedHighlight, fraction = progress),
outline = lerp(start = outline, stop = to.outline, fraction = progress),
outlineVariant = lerp(start = outlineVariant, stop = to.outlineVariant, fraction = progress),
surface = lerp(start = surface, stop = to.surface, fraction = progress),
onSurface = lerp(start = onSurface, stop = to.onSurface, fraction = progress),
onSurfaceVariant =
lerp(
start = startColors.onSurfaceVariant,
stop = endColors.onSurfaceVariant,
fraction = progress
),
lerp(start = onSurfaceVariant, stop = to.onSurfaceVariant, fraction = progress),
surfaceContainer =
lerp(
start = startColors.surfaceContainer,
stop = endColors.surfaceContainer,
fraction = progress
),
lerp(start = surfaceContainer, stop = to.surfaceContainer, fraction = progress),
surfaceContainerLow =
lerp(
start = startColors.surfaceContainerLow,
stop = endColors.surfaceContainerLow,
fraction = progress
),
lerp(start = surfaceContainerLow, stop = to.surfaceContainerLow, fraction = progress),
surfaceContainerLowest =
lerp(
start = startColors.surfaceContainerLowest,
stop = endColors.surfaceContainerLowest,
fraction = progress
),
lerp(start = surfaceContainerLowest, stop = to.surfaceContainerLowest, fraction = progress),
surfaceContainerHigh =
lerp(
start = startColors.surfaceContainerHigh,
stop = endColors.surfaceContainerHigh,
fraction = progress
),
lerp(start = surfaceContainerHigh, stop = to.surfaceContainerHigh, fraction = progress),
surfaceContainerHighest =
lerp(
start = startColors.surfaceContainerHighest,
stop = endColors.surfaceContainerHighest,
fraction = progress
),
lerp(start = surfaceContainerHighest, stop = to.surfaceContainerHighest, fraction = progress),
)
}

Expand Down

0 comments on commit b01f1cd

Please sign in to comment.