Skip to content

Commit

Permalink
animate color change
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed Dec 8, 2023
1 parent 4c6b7f0 commit c0f6dd7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ kotlin {
api(libs.ktor.content.negotiation)
api(libs.ktor.serialization.json)

api("dev.datlag.kast:kast:0.1.6-SNAPSHOT")
api("dev.datlag.kast:kast:0.1.7-SNAPSHOT")

api(project(":model"))
api(project(":network"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package dev.datlag.burningseries.shared.common

import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.AnimationSpec
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.spring
import androidx.compose.foundation.focusable
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.gestures.waitForUpOrCancellation
Expand All @@ -12,11 +16,13 @@ import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.grid.GridItemSpan
import androidx.compose.foundation.lazy.grid.LazyGridItemScope
import androidx.compose.foundation.lazy.grid.LazyGridScope
import androidx.compose.material3.ColorScheme
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.draw.clip
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.unit.DpSize
Expand Down Expand Up @@ -140,4 +146,30 @@ fun Modifier.focusScale(
scaleY = scale
}
}
}

@Composable
fun ColorScheme.animate(spec: AnimationSpec<Color> = spring(stiffness = Spring.StiffnessLow)): ColorScheme {
return this.copy(
primary = animateColorAsState(this.primary, spec).value,
onPrimary = animateColorAsState(this.onPrimary, spec).value,
primaryContainer = animateColorAsState(this.primaryContainer, spec).value,
onPrimaryContainer = animateColorAsState(this.onPrimaryContainer, spec).value,
secondary = animateColorAsState(this.secondary, spec).value,
onSecondary = animateColorAsState(this.onSecondary, spec).value,
secondaryContainer = animateColorAsState(this.secondaryContainer, spec).value,
onSecondaryContainer = animateColorAsState(this.onSecondaryContainer, spec).value,
tertiary = animateColorAsState(this.tertiary, spec).value,
onTertiary = animateColorAsState(this.onTertiary, spec).value,
tertiaryContainer = animateColorAsState(this.tertiaryContainer, spec).value,
onTertiaryContainer = animateColorAsState(this.onTertiaryContainer, spec).value,
background = animateColorAsState(this.background, spec).value,
onBackground = animateColorAsState(this.onBackground, spec).value,
surface = animateColorAsState(this.surface, spec).value,
onSurface = animateColorAsState(this.onSurface, spec).value,
error = animateColorAsState(this.error, spec).value,
onError = animateColorAsState(this.onError, spec).value,
errorContainer = animateColorAsState(this.errorContainer, spec).value,
onErrorContainer = animateColorAsState(this.onErrorContainer, spec).value
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.Painter
import dev.datlag.burningseries.color.theme.Theme
import dev.datlag.burningseries.shared.LocalDarkMode
import dev.datlag.burningseries.shared.common.animate
import dev.datlag.burningseries.shared.common.launchIO
import dev.datlag.burningseries.shared.common.lifecycle.collectAsStateWithLifecycle
import dev.datlag.burningseries.shared.common.withIOContext
Expand Down Expand Up @@ -162,10 +163,10 @@ fun SchemeTheme(key: Any?, content: @Composable () -> Unit) {
val scheme = (if (LocalDarkMode.current) themeHolder?.dark else themeHolder?.light) ?: MaterialTheme.colorScheme

MaterialTheme(
colorScheme = scheme
colorScheme = scheme.animate()
) {
androidx.compose.material.MaterialTheme(
colors = scheme.toLegacyColors(LocalDarkMode.current)
colors = MaterialTheme.colorScheme.toLegacyColors(LocalDarkMode.current)
) {
SchemeThemeSystemProvider(scheme) {
content()
Expand Down
5 changes: 1 addition & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ android-core = "1.12.0"
appcompat = "1.6.1"
appdirs = "1.2.2"
blurhash = "0.1.0"
cast = "21.3.0"
compose = "1.5.11"
complete-kotlin = "1.1.0"
context-menu = "0.2.0"
Expand All @@ -29,7 +28,7 @@ kcef = "2023.10.13"
kodein = "7.21.1"
kotlin = "1.9.21"
ksp = "1.9.21-1.0.15"
ktor = "2.3.6"
ktor = "2.3.7"
ktorfit = "1.11.0"
ktsoup = "0.3.0"
lang = "3.14.0"
Expand Down Expand Up @@ -63,8 +62,6 @@ android = { group = "androidx.core", name = "core-ktx", version.ref = "android-c
appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
appdirs = { group = "net.harawata", name = "appdirs", version.ref = "appdirs" }
blurhash = { group = "com.vanniktech", name = "blurhash", version.ref = "blurhash" }
cast = { group = "com.google.android.gms", name = "play-services-cast", version.ref = "cast" }
cast-framework = { group = "com.google.android.gms", name = "play-services-cast-framework", version.ref = "cast" }
compose-ui-util = { group = "org.jetbrains.compose.ui", name = "ui-util", version.ref = "compose" }
context-menu = { group = "io.github.dzirbel", name = "compose-material-context-menu", version.ref = "context-menu" }
coroutines = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "coroutines" }
Expand Down

0 comments on commit c0f6dd7

Please sign in to comment.