Skip to content

Commit

Permalink
perf: colorScheme animation
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Jan 9, 2025
1 parent 2e26326 commit 1579a56
Showing 1 changed file with 56 additions and 2 deletions.
58 changes: 56 additions & 2 deletions app/src/main/kotlin/li/songe/gkd/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package li.songe.gkd.ui.theme

import android.os.Build
import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.ColorScheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
Expand All @@ -11,6 +14,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.core.view.WindowInsetsControllerCompat
import li.songe.gkd.MainActivity
Expand Down Expand Up @@ -43,6 +47,56 @@ fun AppTheme(
}
}
MaterialTheme(
colorScheme = colorScheme, content = content
colorScheme = colorScheme.animation(),
content = content,
)
}
}

@Composable
private fun Color.animation() = animateColorAsState(
targetValue = this,
animationSpec = tween(durationMillis = 500),
label = "animation"
).value

@Composable
private fun ColorScheme.animation(): ColorScheme {
return copy(
primary = primary.animation(),
onPrimary = onPrimary.animation(),
primaryContainer = primaryContainer.animation(),
onPrimaryContainer = onPrimaryContainer.animation(),
inversePrimary = inversePrimary.animation(),
secondary = secondary.animation(),
onSecondary = onSecondary.animation(),
secondaryContainer = secondaryContainer.animation(),
onSecondaryContainer = onSecondaryContainer.animation(),
tertiary = tertiary.animation(),
onTertiary = onTertiary.animation(),
tertiaryContainer = tertiaryContainer.animation(),
onTertiaryContainer = onTertiaryContainer.animation(),
background = background.animation(),
onBackground = onBackground.animation(),
surface = surface.animation(),
onSurface = onSurface.animation(),
surfaceVariant = surfaceVariant.animation(),
onSurfaceVariant = onSurfaceVariant.animation(),
surfaceTint = surfaceTint.animation(),
inverseSurface = inverseSurface.animation(),
inverseOnSurface = inverseOnSurface.animation(),
error = error.animation(),
onError = onError.animation(),
errorContainer = errorContainer.animation(),
onErrorContainer = onErrorContainer.animation(),
outline = outline.animation(),
outlineVariant = outlineVariant.animation(),
scrim = scrim.animation(),
surfaceBright = surfaceBright.animation(),
surfaceDim = surfaceDim.animation(),
surfaceContainer = surfaceContainer.animation(),
surfaceContainerHigh = surfaceContainerHigh.animation(),
surfaceContainerHighest = surfaceContainerHighest.animation(),
surfaceContainerLow = surfaceContainerLow.animation(),
surfaceContainerLowest = surfaceContainerLowest.animation(),
)
}

0 comments on commit 1579a56

Please sign in to comment.