|
|
@@ -1,29 +1,20 @@
|
|
|
package io.legado.app.ui.widget.components.button
|
|
|
|
|
|
-import androidx.compose.animation.AnimatedVisibility
|
|
|
import androidx.compose.animation.animateColorAsState
|
|
|
import androidx.compose.animation.core.tween
|
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
|
import androidx.compose.foundation.layout.PaddingValues
|
|
|
import androidx.compose.foundation.layout.Row
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
-import androidx.compose.foundation.layout.size
|
|
|
import androidx.compose.material3.ButtonDefaults
|
|
|
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
|
|
|
-import androidx.compose.material3.FilledTonalIconButton
|
|
|
import androidx.compose.material3.Icon
|
|
|
import androidx.compose.material3.IconButton
|
|
|
-import androidx.compose.material3.IconButtonDefaults
|
|
|
import androidx.compose.material3.OutlinedIconButton
|
|
|
-import androidx.compose.material3.OutlinedIconToggleButton
|
|
|
import androidx.compose.material3.Text
|
|
|
import androidx.compose.material3.TonalToggleButton
|
|
|
import androidx.compose.runtime.Composable
|
|
|
-import androidx.compose.runtime.LaunchedEffect
|
|
|
import androidx.compose.runtime.getValue
|
|
|
-import androidx.compose.runtime.mutableStateOf
|
|
|
-import androidx.compose.runtime.remember
|
|
|
-import androidx.compose.runtime.setValue
|
|
|
import androidx.compose.ui.Alignment
|
|
|
import androidx.compose.ui.Modifier
|
|
|
import androidx.compose.ui.graphics.Color
|
|
|
@@ -32,25 +23,25 @@ import androidx.compose.ui.unit.dp
|
|
|
import io.legado.app.ui.theme.LegadoTheme
|
|
|
import io.legado.app.ui.theme.LegadoTheme.composeEngine
|
|
|
import io.legado.app.ui.theme.ThemeResolver
|
|
|
-import kotlinx.coroutines.delay
|
|
|
import top.yukonga.miuix.kmp.theme.MiuixTheme
|
|
|
import top.yukonga.miuix.kmp.basic.Icon as MiuixIcon
|
|
|
import top.yukonga.miuix.kmp.basic.IconButton as MiuixIconButton
|
|
|
import top.yukonga.miuix.kmp.basic.Text as MiuixText
|
|
|
|
|
|
-
|
|
|
@Composable
|
|
|
fun MediumIconButton(
|
|
|
onClick: () -> Unit,
|
|
|
imageVector: ImageVector,
|
|
|
tint: Color = LegadoTheme.colorScheme.onSurface,
|
|
|
modifier: Modifier = Modifier,
|
|
|
+ enabled: Boolean = true,
|
|
|
contentDescription: String? = null
|
|
|
) {
|
|
|
if (ThemeResolver.isMiuixEngine(composeEngine)) {
|
|
|
MiuixIconButton(
|
|
|
onClick = onClick,
|
|
|
- modifier = modifier
|
|
|
+ modifier = modifier,
|
|
|
+ enabled = enabled
|
|
|
) {
|
|
|
MiuixIcon(
|
|
|
imageVector = imageVector,
|
|
|
@@ -61,7 +52,8 @@ fun MediumIconButton(
|
|
|
} else {
|
|
|
IconButton(
|
|
|
onClick = onClick,
|
|
|
- modifier = modifier
|
|
|
+ modifier = modifier,
|
|
|
+ enabled = enabled
|
|
|
) {
|
|
|
Icon(
|
|
|
imageVector = imageVector,
|
|
|
@@ -77,13 +69,14 @@ fun MediumOutlinedIconButton(
|
|
|
onClick: () -> Unit,
|
|
|
imageVector: ImageVector,
|
|
|
modifier: Modifier = Modifier,
|
|
|
+ enabled: Boolean = true,
|
|
|
contentDescription: String? = null
|
|
|
) {
|
|
|
- val isMiuix = ThemeResolver.isMiuixEngine(composeEngine)
|
|
|
- if (isMiuix) {
|
|
|
+ if (ThemeResolver.isMiuixEngine(composeEngine)) {
|
|
|
MiuixIconButton(
|
|
|
onClick = onClick,
|
|
|
modifier = modifier,
|
|
|
+ enabled = enabled,
|
|
|
backgroundColor = LegadoTheme.colorScheme.surfaceContainerHigh
|
|
|
) {
|
|
|
MiuixIcon(
|
|
|
@@ -93,135 +86,10 @@ fun MediumOutlinedIconButton(
|
|
|
}
|
|
|
} else {
|
|
|
OutlinedIconButton(
|
|
|
- onClick = onClick,
|
|
|
- border = ButtonDefaults.outlinedButtonBorder()
|
|
|
- ) {
|
|
|
- Icon(
|
|
|
- imageVector = imageVector,
|
|
|
- contentDescription = contentDescription
|
|
|
- )
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-@Composable
|
|
|
-fun MediumOutlinedButton(
|
|
|
- onClick: () -> Unit,
|
|
|
- imageVector: ImageVector,
|
|
|
- text: String,
|
|
|
- modifier: Modifier = Modifier,
|
|
|
- contentDescription: String? = null
|
|
|
-) {
|
|
|
- val isMiuix = ThemeResolver.isMiuixEngine(composeEngine)
|
|
|
- if (isMiuix) {
|
|
|
- MiuixIconButton(
|
|
|
onClick = onClick,
|
|
|
modifier = modifier,
|
|
|
- backgroundColor = LegadoTheme.colorScheme.surfaceContainerHigh
|
|
|
- ) {
|
|
|
- Row(
|
|
|
- verticalAlignment = Alignment.CenterVertically,
|
|
|
- horizontalArrangement = Arrangement.spacedBy(8.dp)
|
|
|
- ) {
|
|
|
- MiuixIcon(
|
|
|
- imageVector = imageVector,
|
|
|
- contentDescription = contentDescription
|
|
|
- )
|
|
|
- MiuixText(text = text)
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- OutlinedIconButton(
|
|
|
- onClick = onClick,
|
|
|
+ enabled = enabled,
|
|
|
border = ButtonDefaults.outlinedButtonBorder()
|
|
|
- ) {
|
|
|
- Row(
|
|
|
- verticalAlignment = Alignment.CenterVertically,
|
|
|
- horizontalArrangement = Arrangement.spacedBy(8.dp)
|
|
|
- ) {
|
|
|
- Icon(
|
|
|
- imageVector = imageVector,
|
|
|
- contentDescription = contentDescription
|
|
|
- )
|
|
|
- Text(text = text)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-@Composable
|
|
|
-fun MediumTonalIconButton(
|
|
|
- onClick: () -> Unit,
|
|
|
- imageVector: ImageVector,
|
|
|
- modifier: Modifier = Modifier,
|
|
|
- contentDescription: String? = null
|
|
|
-) {
|
|
|
- val isMiuix = ThemeResolver.isMiuixEngine(composeEngine)
|
|
|
-
|
|
|
- if (isMiuix) {
|
|
|
- MiuixIconButton(
|
|
|
- onClick = onClick,
|
|
|
- modifier = modifier,
|
|
|
- backgroundColor = LegadoTheme.colorScheme.surfaceContainer
|
|
|
- ) {
|
|
|
- MiuixIcon(
|
|
|
- imageVector = imageVector,
|
|
|
- contentDescription = contentDescription
|
|
|
- )
|
|
|
- }
|
|
|
- } else {
|
|
|
- FilledTonalIconButton(
|
|
|
- onClick = onClick,
|
|
|
- modifier = modifier.size(40.dp),
|
|
|
- colors = IconButtonDefaults.filledTonalIconButtonColors()
|
|
|
- ) {
|
|
|
- Icon(
|
|
|
- imageVector = imageVector,
|
|
|
- contentDescription = contentDescription
|
|
|
- )
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-@Composable
|
|
|
-fun MediumOutlinedIconToggleButton(
|
|
|
- checked: Boolean,
|
|
|
- onCheckedChange: (Boolean) -> Unit,
|
|
|
- imageVector: ImageVector,
|
|
|
- modifier: Modifier = Modifier,
|
|
|
- contentDescription: String? = null
|
|
|
-) {
|
|
|
- val isMiuix = ThemeResolver.isMiuixEngine(composeEngine)
|
|
|
-
|
|
|
- if (isMiuix) {
|
|
|
- val containerColor by animateColorAsState(
|
|
|
- targetValue = if (checked) LegadoTheme.colorScheme.primaryContainer else LegadoTheme.colorScheme.surfaceContainer,
|
|
|
- animationSpec = tween(150),
|
|
|
- label = "MiuixToggleContainerColor"
|
|
|
- )
|
|
|
-
|
|
|
- val iconTint by animateColorAsState(
|
|
|
- targetValue = if (checked) LegadoTheme.colorScheme.onPrimaryContainer else LegadoTheme.colorScheme.onSurfaceVariant,
|
|
|
- animationSpec = tween(150),
|
|
|
- label = "MiuixToggleIconTint"
|
|
|
- )
|
|
|
-
|
|
|
- MiuixIconButton(
|
|
|
- onClick = { onCheckedChange(!checked) },
|
|
|
- modifier = modifier,
|
|
|
- backgroundColor = containerColor
|
|
|
- ) {
|
|
|
- MiuixIcon(
|
|
|
- imageVector = imageVector,
|
|
|
- contentDescription = contentDescription,
|
|
|
- tint = iconTint
|
|
|
- )
|
|
|
- }
|
|
|
- } else {
|
|
|
- OutlinedIconToggleButton(
|
|
|
- checked = checked,
|
|
|
- onCheckedChange = onCheckedChange,
|
|
|
- modifier = modifier
|
|
|
) {
|
|
|
Icon(
|
|
|
imageVector = imageVector,
|
|
|
@@ -242,20 +110,7 @@ fun MediumAnimatedActionButton(
|
|
|
inactiveText: String,
|
|
|
modifier: Modifier = Modifier
|
|
|
) {
|
|
|
- var showText by remember { mutableStateOf(false) }
|
|
|
- var lastCheckedState by remember { mutableStateOf(checked) }
|
|
|
-
|
|
|
- LaunchedEffect(showText) {
|
|
|
- if (showText) {
|
|
|
- delay(1000)
|
|
|
- showText = false
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- val isMiuix = ThemeResolver.isMiuixEngine(composeEngine)
|
|
|
-
|
|
|
- if (isMiuix) {
|
|
|
-
|
|
|
+ if (ThemeResolver.isMiuixEngine(composeEngine)) {
|
|
|
val containerColor by animateColorAsState(
|
|
|
targetValue = if (checked) MiuixTheme.colorScheme.primaryContainer else MiuixTheme.colorScheme.surfaceContainerHigh,
|
|
|
animationSpec = tween(150),
|
|
|
@@ -265,72 +120,97 @@ fun MediumAnimatedActionButton(
|
|
|
val contentColor by animateColorAsState(
|
|
|
targetValue = if (checked) MiuixTheme.colorScheme.onPrimaryContainer else MiuixTheme.colorScheme.onSurface,
|
|
|
animationSpec = tween(150),
|
|
|
- label = "MiuixActionButtonContainer"
|
|
|
+ label = "MiuixActionButtonContent"
|
|
|
)
|
|
|
|
|
|
- MiuixIconButton(
|
|
|
- onClick = {
|
|
|
- lastCheckedState = !checked
|
|
|
- onCheckedChange(!checked)
|
|
|
- showText = true
|
|
|
- },
|
|
|
- backgroundColor = containerColor
|
|
|
- ) {
|
|
|
- Row(
|
|
|
- verticalAlignment = Alignment.CenterVertically,
|
|
|
- horizontalArrangement = Arrangement.Center,
|
|
|
- modifier = Modifier.padding(horizontal = 8.dp)
|
|
|
- ) {
|
|
|
- MiuixIcon(
|
|
|
- tint = contentColor,
|
|
|
- imageVector = if (checked) iconChecked else iconUnchecked,
|
|
|
- contentDescription = null
|
|
|
- )
|
|
|
-
|
|
|
- AnimatedVisibility(
|
|
|
- visible = showText
|
|
|
+ AnimatedActionButtonCore(
|
|
|
+ checked = checked,
|
|
|
+ onCheckedChange = onCheckedChange,
|
|
|
+ iconChecked = iconChecked,
|
|
|
+ iconUnchecked = iconUnchecked,
|
|
|
+ activeText = activeText,
|
|
|
+ inactiveText = inactiveText,
|
|
|
+ modifier = modifier,
|
|
|
+ iconSize = 24.dp,
|
|
|
+ textStyle = LegadoTheme.typography.labelMedium,
|
|
|
+ textStartPadding = 8.dp,
|
|
|
+ contentColor = contentColor,
|
|
|
+ button = { buttonModifier, onToggle, content ->
|
|
|
+ MiuixIconButton(
|
|
|
+ onClick = { onToggle(!checked) },
|
|
|
+ modifier = buttonModifier,
|
|
|
+ backgroundColor = containerColor
|
|
|
) {
|
|
|
- MiuixText(
|
|
|
- text = if (lastCheckedState) activeText else inactiveText,
|
|
|
- color = contentColor,
|
|
|
- style = LegadoTheme.typography.labelMedium,
|
|
|
- modifier = Modifier.padding(start = 8.dp),
|
|
|
- maxLines = 1,
|
|
|
- softWrap = false
|
|
|
+ Row(
|
|
|
+ verticalAlignment = Alignment.CenterVertically,
|
|
|
+ horizontalArrangement = Arrangement.Center,
|
|
|
+ modifier = Modifier.padding(horizontal = 8.dp),
|
|
|
+ content = content
|
|
|
)
|
|
|
}
|
|
|
+ },
|
|
|
+ icon = { imageVector, iconModifier, tint ->
|
|
|
+ MiuixIcon(
|
|
|
+ imageVector = imageVector,
|
|
|
+ contentDescription = null,
|
|
|
+ modifier = iconModifier,
|
|
|
+ tint = tint ?: Color.Unspecified
|
|
|
+ )
|
|
|
+ },
|
|
|
+ text = { label, textModifier, style, color ->
|
|
|
+ MiuixText(
|
|
|
+ text = label,
|
|
|
+ color = color ?: Color.Unspecified,
|
|
|
+ style = style,
|
|
|
+ modifier = textModifier,
|
|
|
+ maxLines = 1,
|
|
|
+ softWrap = false
|
|
|
+ )
|
|
|
}
|
|
|
- }
|
|
|
+ )
|
|
|
} else {
|
|
|
- TonalToggleButton(
|
|
|
+ AnimatedActionButtonCore(
|
|
|
checked = checked,
|
|
|
- onCheckedChange = {
|
|
|
- lastCheckedState = it
|
|
|
- onCheckedChange(it)
|
|
|
- showText = true
|
|
|
- },
|
|
|
- contentPadding = PaddingValues(horizontal = 8.dp)
|
|
|
- ) {
|
|
|
- Row(
|
|
|
- verticalAlignment = Alignment.CenterVertically,
|
|
|
- horizontalArrangement = Arrangement.Center
|
|
|
- ) {
|
|
|
- AnimatedIcon(
|
|
|
- imageVector = if (checked) iconChecked else iconUnchecked,
|
|
|
- contentDescription = null
|
|
|
- )
|
|
|
-
|
|
|
- AnimatedVisibility(
|
|
|
- visible = showText
|
|
|
+ onCheckedChange = onCheckedChange,
|
|
|
+ iconChecked = iconChecked,
|
|
|
+ iconUnchecked = iconUnchecked,
|
|
|
+ activeText = activeText,
|
|
|
+ inactiveText = inactiveText,
|
|
|
+ modifier = modifier,
|
|
|
+ iconSize = 24.dp,
|
|
|
+ textStyle = LegadoTheme.typography.labelMedium,
|
|
|
+ textStartPadding = 8.dp,
|
|
|
+ button = { buttonModifier, onToggle, content ->
|
|
|
+ TonalToggleButton(
|
|
|
+ checked = checked,
|
|
|
+ onCheckedChange = onToggle,
|
|
|
+ modifier = buttonModifier,
|
|
|
+ contentPadding = PaddingValues(horizontal = 8.dp)
|
|
|
) {
|
|
|
- Text(
|
|
|
- text = if (lastCheckedState) activeText else inactiveText,
|
|
|
- modifier = Modifier.padding(start = 8.dp),
|
|
|
- maxLines = 1,
|
|
|
- softWrap = false
|
|
|
+ Row(
|
|
|
+ verticalAlignment = Alignment.CenterVertically,
|
|
|
+ horizontalArrangement = Arrangement.Center,
|
|
|
+ content = content
|
|
|
)
|
|
|
}
|
|
|
+ },
|
|
|
+ icon = { imageVector, iconModifier, _ ->
|
|
|
+ AnimatedIcon(
|
|
|
+ imageVector = imageVector,
|
|
|
+ contentDescription = null,
|
|
|
+ modifier = iconModifier
|
|
|
+ )
|
|
|
+ },
|
|
|
+ text = { label, textModifier, style, color ->
|
|
|
+ Text(
|
|
|
+ text = label,
|
|
|
+ modifier = textModifier,
|
|
|
+ style = style,
|
|
|
+ color = color ?: Color.Unspecified,
|
|
|
+ maxLines = 1,
|
|
|
+ softWrap = false
|
|
|
+ )
|
|
|
}
|
|
|
- }
|
|
|
+ )
|
|
|
}
|
|
|
}
|