From c0f6dd71067d2b16d06aa18c6a5969e1b0999351 Mon Sep 17 00:00:00 2001 From: DatLag Date: Fri, 8 Dec 2023 14:25:49 +0100 Subject: [PATCH] animate color change --- app/shared/build.gradle.kts | 2 +- .../shared/common/ExtendCompose.kt | 32 +++++++++++++++++++ .../shared/ui/theme/SchemeTheme.kt | 5 +-- gradle/libs.versions.toml | 5 +-- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/app/shared/build.gradle.kts b/app/shared/build.gradle.kts index f6cf2727..29043121 100644 --- a/app/shared/build.gradle.kts +++ b/app/shared/build.gradle.kts @@ -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")) diff --git a/app/shared/src/commonMain/kotlin/dev/datlag/burningseries/shared/common/ExtendCompose.kt b/app/shared/src/commonMain/kotlin/dev/datlag/burningseries/shared/common/ExtendCompose.kt index 3bc8f706..bf1dab3b 100644 --- a/app/shared/src/commonMain/kotlin/dev/datlag/burningseries/shared/common/ExtendCompose.kt +++ b/app/shared/src/commonMain/kotlin/dev/datlag/burningseries/shared/common/ExtendCompose.kt @@ -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 @@ -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 @@ -140,4 +146,30 @@ fun Modifier.focusScale( scaleY = scale } } +} + +@Composable +fun ColorScheme.animate(spec: AnimationSpec = 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 + ) } \ No newline at end of file diff --git a/app/shared/src/commonMain/kotlin/dev/datlag/burningseries/shared/ui/theme/SchemeTheme.kt b/app/shared/src/commonMain/kotlin/dev/datlag/burningseries/shared/ui/theme/SchemeTheme.kt index 7d1ffb09..52ba89c5 100644 --- a/app/shared/src/commonMain/kotlin/dev/datlag/burningseries/shared/ui/theme/SchemeTheme.kt +++ b/app/shared/src/commonMain/kotlin/dev/datlag/burningseries/shared/ui/theme/SchemeTheme.kt @@ -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 @@ -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() diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4e1d1c34..56554505 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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" @@ -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" @@ -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" }