Merge pull request #1509 from fansangg/fix/theme-switch-delay
fix:菜单切换深浅色一些按钮变化延迟的问题
This commit is contained in:
4 files changed
+47
-25
No files matched your search
@@ -5,6 +5,7 @@ import androidx.compose.material3.lightColorScheme
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.ReadOnlyComposable
|
import androidx.compose.runtime.ReadOnlyComposable
|
||||||
import androidx.compose.runtime.compositionLocalOf
|
import androidx.compose.runtime.compositionLocalOf
|
||||||
|
import androidx.compose.runtime.staticCompositionLocalOf
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.text.TextStyle
|
import androidx.compose.ui.text.TextStyle
|
||||||
import com.materialkolor.PaletteStyle
|
import com.materialkolor.PaletteStyle
|
||||||
@@ -109,15 +110,15 @@ data class LegadoTypography(
|
|||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
val LocalLegadoColorScheme = compositionLocalOf<LegadoColorScheme> {
|
val LocalLegadoColorScheme = staticCompositionLocalOf<LegadoColorScheme> {
|
||||||
error("No ColorScheme provided")
|
error("No ColorScheme provided")
|
||||||
}
|
}
|
||||||
|
|
||||||
val LocalLegadoTypography = compositionLocalOf<LegadoTypography> {
|
val LocalLegadoTypography = staticCompositionLocalOf<LegadoTypography> {
|
||||||
error("No Typography provided")
|
error("No Typography provided")
|
||||||
}
|
}
|
||||||
|
|
||||||
val LocalLegadoThemeColors = compositionLocalOf {
|
val LocalLegadoThemeColors = staticCompositionLocalOf {
|
||||||
LegadoThemeMode(
|
LegadoThemeMode(
|
||||||
colorScheme = lightColorScheme(),
|
colorScheme = lightColorScheme(),
|
||||||
isDark = false,
|
isDark = false,
|
||||||
|
|||||||
@@ -95,23 +95,13 @@ fun ProvideColorSchemeOverride(
|
|||||||
overrideIsDark: Boolean? = null,
|
overrideIsDark: Boolean? = null,
|
||||||
content: @Composable () -> Unit,
|
content: @Composable () -> Unit,
|
||||||
) {
|
) {
|
||||||
val themeAnimationSpec = tween<Color>(
|
|
||||||
durationMillis = 700,
|
|
||||||
easing = FastOutSlowInEasing
|
|
||||||
)
|
|
||||||
val baseThemeMode = LocalLegadoThemeColors.current
|
val baseThemeMode = LocalLegadoThemeColors.current
|
||||||
val animatedColorScheme = colorScheme.animateColorSchemeAsState(themeAnimationSpec)
|
val legadoColorScheme = remember(colorScheme) { colorScheme.toLegadoColorScheme() }
|
||||||
val animatedSeedColor = animateColorAsState(
|
|
||||||
targetValue = seedColor,
|
|
||||||
animationSpec = themeAnimationSpec,
|
|
||||||
label = "theme_seed_animation"
|
|
||||||
).value
|
|
||||||
val legadoColorScheme = remember(animatedColorScheme) { animatedColorScheme.toLegadoColorScheme() }
|
|
||||||
val resolvedIsDark = overrideIsDark ?: baseThemeMode.isDark
|
val resolvedIsDark = overrideIsDark ?: baseThemeMode.isDark
|
||||||
val overrideThemeMode = remember(baseThemeMode, animatedColorScheme, animatedSeedColor, resolvedIsDark) {
|
val overrideThemeMode = remember(baseThemeMode, colorScheme, seedColor, resolvedIsDark) {
|
||||||
baseThemeMode.copy(
|
baseThemeMode.copy(
|
||||||
colorScheme = animatedColorScheme,
|
colorScheme = colorScheme,
|
||||||
seedColor = animatedSeedColor,
|
seedColor = seedColor,
|
||||||
isDark = resolvedIsDark,
|
isDark = resolvedIsDark,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -131,7 +121,7 @@ fun ProvideColorSchemeOverride(
|
|||||||
isMiuixEngine,
|
isMiuixEngine,
|
||||||
miuixColorSchemeMode,
|
miuixColorSchemeMode,
|
||||||
overrideThemeMode.isDark,
|
overrideThemeMode.isDark,
|
||||||
animatedSeedColor,
|
seedColor,
|
||||||
miuixPaletteStyle,
|
miuixPaletteStyle,
|
||||||
miuixColorSpec
|
miuixColorSpec
|
||||||
) {
|
) {
|
||||||
@@ -140,7 +130,7 @@ fun ProvideColorSchemeOverride(
|
|||||||
} else {
|
} else {
|
||||||
ThemeController(
|
ThemeController(
|
||||||
colorSchemeMode = miuixColorSchemeMode,
|
colorSchemeMode = miuixColorSchemeMode,
|
||||||
keyColor = animatedSeedColor,
|
keyColor = seedColor,
|
||||||
paletteStyle = miuixPaletteStyle,
|
paletteStyle = miuixPaletteStyle,
|
||||||
colorSpec = miuixColorSpec,
|
colorSpec = miuixColorSpec,
|
||||||
isDark = overrideThemeMode.isDark
|
isDark = overrideThemeMode.isDark
|
||||||
@@ -155,7 +145,7 @@ fun ProvideColorSchemeOverride(
|
|||||||
if (miuixController != null) {
|
if (miuixController != null) {
|
||||||
MiuixTheme(controller = miuixController) {
|
MiuixTheme(controller = miuixController) {
|
||||||
MaterialTheme(
|
MaterialTheme(
|
||||||
colorScheme = animatedColorScheme,
|
colorScheme = colorScheme,
|
||||||
typography = materialTypography,
|
typography = materialTypography,
|
||||||
shapes = materialShapes
|
shapes = materialShapes
|
||||||
) {
|
) {
|
||||||
@@ -164,7 +154,7 @@ fun ProvideColorSchemeOverride(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
MaterialTheme(
|
MaterialTheme(
|
||||||
colorScheme = animatedColorScheme,
|
colorScheme = colorScheme,
|
||||||
typography = materialTypography,
|
typography = materialTypography,
|
||||||
shapes = materialShapes
|
shapes = materialShapes
|
||||||
) {
|
) {
|
||||||
|
|||||||
+17
-2
@@ -19,9 +19,13 @@ import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
|
|||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButtonDefaults
|
import androidx.compose.material3.IconButtonDefaults
|
||||||
import androidx.compose.material3.ripple
|
import androidx.compose.material3.ripple
|
||||||
|
import androidx.compose.animation.core.snap
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.runtime.SideEffect
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
@@ -69,13 +73,24 @@ internal fun SeriesButton(
|
|||||||
selectedContentColor: Color = LegadoTheme.colorScheme.onPrimaryContainer,
|
selectedContentColor: Color = LegadoTheme.colorScheme.onPrimaryContainer,
|
||||||
content: @Composable (Color) -> Unit
|
content: @Composable (Color) -> Unit
|
||||||
) {
|
) {
|
||||||
|
var lastEnabled by remember { mutableStateOf(enabled) }
|
||||||
|
var lastSelected by remember { mutableStateOf(selected) }
|
||||||
|
val isStateChanged = enabled != lastEnabled || selected != lastSelected
|
||||||
|
|
||||||
|
SideEffect {
|
||||||
|
lastEnabled = enabled
|
||||||
|
lastSelected = selected
|
||||||
|
}
|
||||||
|
|
||||||
|
val animSpec = if (isStateChanged) tween<Color>(150) else snap()
|
||||||
|
|
||||||
val containerColor by animateColorAsState(
|
val containerColor by animateColorAsState(
|
||||||
targetValue = when {
|
targetValue = when {
|
||||||
!enabled -> disabledContainerColor(style)
|
!enabled -> disabledContainerColor(style)
|
||||||
selected -> selectedContainerColor
|
selected -> selectedContainerColor
|
||||||
else -> containerColor ?: containerColor(style)
|
else -> containerColor ?: containerColor(style)
|
||||||
},
|
},
|
||||||
animationSpec = tween(150),
|
animationSpec = animSpec,
|
||||||
label = "SeriesIconContainerColor"
|
label = "SeriesIconContainerColor"
|
||||||
)
|
)
|
||||||
val resolvedContentColor by animateColorAsState(
|
val resolvedContentColor by animateColorAsState(
|
||||||
@@ -84,7 +99,7 @@ internal fun SeriesButton(
|
|||||||
selected -> selectedContentColor
|
selected -> selectedContentColor
|
||||||
else -> contentColor
|
else -> contentColor
|
||||||
},
|
},
|
||||||
animationSpec = tween(150),
|
animationSpec = animSpec,
|
||||||
label = "SeriesIconContentColor"
|
label = "SeriesIconContentColor"
|
||||||
)
|
)
|
||||||
val shape = IconButtonDefaults.extraSmallRoundShape
|
val shape = IconButtonDefaults.extraSmallRoundShape
|
||||||
|
|||||||
@@ -8,8 +8,15 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
|||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.animation.core.snap
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.runtime.SideEffect
|
||||||
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
@@ -26,6 +33,15 @@ fun CardTabRow(
|
|||||||
onTabSelected: (Int) -> Unit,
|
onTabSelected: (Int) -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
|
var lastSelectedTabIndex by remember { mutableIntStateOf(selectedTabIndex) }
|
||||||
|
val isSelectionChanged = selectedTabIndex != lastSelectedTabIndex
|
||||||
|
|
||||||
|
SideEffect {
|
||||||
|
lastSelectedTabIndex = selectedTabIndex
|
||||||
|
}
|
||||||
|
|
||||||
|
val animSpec = if (isSelectionChanged) tween<Color>(durationMillis = 200) else snap()
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
modifier = modifier.fillMaxWidth(),
|
modifier = modifier.fillMaxWidth(),
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
@@ -38,7 +54,7 @@ fun CardTabRow(
|
|||||||
} else {
|
} else {
|
||||||
LegadoTheme.colorScheme.surfaceContainerLow
|
LegadoTheme.colorScheme.surfaceContainerLow
|
||||||
},
|
},
|
||||||
animationSpec = tween(durationMillis = 200),
|
animationSpec = animSpec,
|
||||||
label = "tabColor",
|
label = "tabColor",
|
||||||
)
|
)
|
||||||
val contentColor by animateColorAsState(
|
val contentColor by animateColorAsState(
|
||||||
@@ -47,7 +63,7 @@ fun CardTabRow(
|
|||||||
} else {
|
} else {
|
||||||
LegadoTheme.colorScheme.onSurfaceVariant
|
LegadoTheme.colorScheme.onSurfaceVariant
|
||||||
},
|
},
|
||||||
animationSpec = tween(durationMillis = 200),
|
animationSpec = animSpec,
|
||||||
label = "tabContentColor",
|
label = "tabContentColor",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user