mirror of
https://github.com/BetterAndroid/FlexiUI.git
synced 2025-09-08 11:34:18 +08:00
refactor: correct some colors and style in Dropdown
This commit is contained in:
@@ -89,6 +89,8 @@ import androidx.compose.ui.platform.LocalFocusManager
|
|||||||
import androidx.compose.ui.platform.LocalInputModeManager
|
import androidx.compose.ui.platform.LocalInputModeManager
|
||||||
import androidx.compose.ui.platform.debugInspectorInfo
|
import androidx.compose.ui.platform.debugInspectorInfo
|
||||||
import androidx.compose.ui.semantics.Role
|
import androidx.compose.ui.semantics.Role
|
||||||
|
import androidx.compose.ui.text.TextStyle
|
||||||
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.unit.Density
|
import androidx.compose.ui.unit.Density
|
||||||
import androidx.compose.ui.unit.Dp
|
import androidx.compose.ui.unit.Dp
|
||||||
import androidx.compose.ui.unit.DpOffset
|
import androidx.compose.ui.unit.DpOffset
|
||||||
@@ -108,12 +110,14 @@ import com.highcapable.flexiui.ColorsDescriptor
|
|||||||
import com.highcapable.flexiui.PaddingDescriptor
|
import com.highcapable.flexiui.PaddingDescriptor
|
||||||
import com.highcapable.flexiui.ShapesDescriptor
|
import com.highcapable.flexiui.ShapesDescriptor
|
||||||
import com.highcapable.flexiui.SizesDescriptor
|
import com.highcapable.flexiui.SizesDescriptor
|
||||||
|
import com.highcapable.flexiui.TypographyDescriptor
|
||||||
import com.highcapable.flexiui.component.interaction.rippleClickable
|
import com.highcapable.flexiui.component.interaction.rippleClickable
|
||||||
import com.highcapable.flexiui.resources.FlexiIcons
|
import com.highcapable.flexiui.resources.FlexiIcons
|
||||||
import com.highcapable.flexiui.resources.icon.Dropdown
|
import com.highcapable.flexiui.resources.icon.Dropdown
|
||||||
import com.highcapable.flexiui.toColor
|
import com.highcapable.flexiui.toColor
|
||||||
import com.highcapable.flexiui.toDp
|
import com.highcapable.flexiui.toDp
|
||||||
import com.highcapable.flexiui.toShape
|
import com.highcapable.flexiui.toShape
|
||||||
|
import com.highcapable.flexiui.toTextStyle
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
@@ -138,6 +142,7 @@ data class DropdownListColors(
|
|||||||
data class DropdownMenuColors(
|
data class DropdownMenuColors(
|
||||||
val contentColor: Color,
|
val contentColor: Color,
|
||||||
val activeColor: Color,
|
val activeColor: Color,
|
||||||
|
val activeContentColor: Color,
|
||||||
val backgroundColor: Color,
|
val backgroundColor: Color,
|
||||||
val borderColor: Color
|
val borderColor: Color
|
||||||
)
|
)
|
||||||
@@ -161,6 +166,8 @@ data class DropdownListStyle(
|
|||||||
*/
|
*/
|
||||||
@Immutable
|
@Immutable
|
||||||
data class DropdownMenuStyle(
|
data class DropdownMenuStyle(
|
||||||
|
val textStyle: TextStyle,
|
||||||
|
val activeTextStyle: TextStyle,
|
||||||
val padding: ComponentPadding,
|
val padding: ComponentPadding,
|
||||||
val shape: Shape,
|
val shape: Shape,
|
||||||
val borderWidth: Dp,
|
val borderWidth: Dp,
|
||||||
@@ -373,7 +380,10 @@ fun DropdownMenuBox(
|
|||||||
* @param onClick the callback when the dropdown menu item is clicked.
|
* @param onClick the callback when the dropdown menu item is clicked.
|
||||||
* @param modifier the [Modifier] to be applied to this dropdown menu item.
|
* @param modifier the [Modifier] to be applied to this dropdown menu item.
|
||||||
* @param contentColor the color of the content.
|
* @param contentColor the color of the content.
|
||||||
|
* @param activeContentColor the color of the active item content.
|
||||||
* @param activeColor the color of the active item.
|
* @param activeColor the color of the active item.
|
||||||
|
* @param textStyle the text style of the content.
|
||||||
|
* @param activeTextStyle the text style of the active item content.
|
||||||
* @param contentPadding the padding of the content.
|
* @param contentPadding the padding of the content.
|
||||||
* @param contentShape the shape of the content.
|
* @param contentShape the shape of the content.
|
||||||
* @param enabled whether the dropdown menu item is enabled, default is true.
|
* @param enabled whether the dropdown menu item is enabled, default is true.
|
||||||
@@ -386,7 +396,10 @@ fun DropdownMenuItem(
|
|||||||
onClick: () -> Unit,
|
onClick: () -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
contentColor: Color = Color.Unspecified,
|
contentColor: Color = Color.Unspecified,
|
||||||
|
activeContentColor: Color = Color.Unspecified,
|
||||||
activeColor: Color = Color.Unspecified,
|
activeColor: Color = Color.Unspecified,
|
||||||
|
textStyle: TextStyle? = null,
|
||||||
|
activeTextStyle: TextStyle? = null,
|
||||||
contentPadding: ComponentPadding? = null,
|
contentPadding: ComponentPadding? = null,
|
||||||
contentShape: Shape? = null,
|
contentShape: Shape? = null,
|
||||||
enabled: Boolean = true,
|
enabled: Boolean = true,
|
||||||
@@ -394,12 +407,21 @@ fun DropdownMenuItem(
|
|||||||
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
||||||
content: @Composable RowScope.() -> Unit
|
content: @Composable RowScope.() -> Unit
|
||||||
) {
|
) {
|
||||||
val currentColor = contentColor.orNull()
|
val currentContentColor = contentColor.orNull()
|
||||||
?: LocalDropdownMenuContentColor.current.orNull()
|
?: LocalDropdownMenuContentColor.current.orNull()
|
||||||
?: DropdownMenuDefaults.colors().contentColor
|
?: DropdownMenuDefaults.colors().contentColor
|
||||||
|
val currentActiveContentColor = activeContentColor.orNull()
|
||||||
|
?: LocalDropdownMenuActiveContentColor.current.orNull()
|
||||||
|
?: DropdownMenuDefaults.colors().activeContentColor
|
||||||
val currentActiveColor = activeColor.orNull()
|
val currentActiveColor = activeColor.orNull()
|
||||||
?: LocalDropdownMenuActiveColor.current.orNull()
|
?: LocalDropdownMenuActiveColor.current.orNull()
|
||||||
?: DropdownMenuDefaults.colors().activeColor
|
?: DropdownMenuDefaults.colors().activeColor
|
||||||
|
val currentTextStyle = textStyle
|
||||||
|
?: LocalDropdownMenuTextStyle.current
|
||||||
|
?: DropdownMenuDefaults.style().textStyle
|
||||||
|
val currentActiveTextStyle = activeTextStyle
|
||||||
|
?: LocalDropdownMenuActiveTextStyle.current
|
||||||
|
?: DropdownMenuDefaults.style().activeTextStyle
|
||||||
val currentPadding = contentPadding
|
val currentPadding = contentPadding
|
||||||
?: LocalDropdownMenuContentPadding.current
|
?: LocalDropdownMenuContentPadding.current
|
||||||
?: DropdownMenuDefaults.style().contentPadding
|
?: DropdownMenuDefaults.style().contentPadding
|
||||||
@@ -427,8 +449,10 @@ fun DropdownMenuItem(
|
|||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
CompositionLocalProvider(
|
CompositionLocalProvider(
|
||||||
LocalIconStyle provides LocalIconStyle.current.copy(tint = currentColor),
|
LocalIconStyle provides LocalIconStyle.current.copy(tint = currentContentColor),
|
||||||
LocalTextStyle provides LocalTextStyle.current.copy(color = currentColor)
|
LocalTextStyle provides LocalTextStyle.current.merge(
|
||||||
|
if (actived) currentActiveTextStyle else currentTextStyle
|
||||||
|
).copy(color = if (actived) currentActiveContentColor else currentContentColor)
|
||||||
) { content() }
|
) { content() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -499,7 +523,10 @@ private fun DropdownMenuContent(
|
|||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
CompositionLocalProvider(
|
CompositionLocalProvider(
|
||||||
|
LocalDropdownMenuTextStyle provides style.textStyle,
|
||||||
|
LocalDropdownMenuActiveTextStyle provides style.activeTextStyle,
|
||||||
LocalDropdownMenuContentColor provides colors.contentColor,
|
LocalDropdownMenuContentColor provides colors.contentColor,
|
||||||
|
LocalDropdownMenuActiveContentColor provides colors.activeContentColor,
|
||||||
LocalDropdownMenuActiveColor provides colors.activeColor,
|
LocalDropdownMenuActiveColor provides colors.activeColor,
|
||||||
LocalDropdownMenuContentPadding provides style.contentPadding,
|
LocalDropdownMenuContentPadding provides style.contentPadding,
|
||||||
LocalDropdownMenuContentShape provides style.contentShape
|
LocalDropdownMenuContentShape provides style.contentShape
|
||||||
@@ -679,6 +706,7 @@ object DropdownMenuDefaults {
|
|||||||
* Creates a [DropdownMenuColors] with the default values.
|
* Creates a [DropdownMenuColors] with the default values.
|
||||||
* @param contentColor the color of the content.
|
* @param contentColor the color of the content.
|
||||||
* @param activeColor the color of the active item.
|
* @param activeColor the color of the active item.
|
||||||
|
* @param activeContentColor the color of the active item content.
|
||||||
* @param backgroundColor the background color.
|
* @param backgroundColor the background color.
|
||||||
* @param borderColor the color of the border.
|
* @param borderColor the color of the border.
|
||||||
* @return [DropdownMenuColors]
|
* @return [DropdownMenuColors]
|
||||||
@@ -687,17 +715,21 @@ object DropdownMenuDefaults {
|
|||||||
fun colors(
|
fun colors(
|
||||||
contentColor: Color = DropdownMenuProperties.ContentColor.toColor(),
|
contentColor: Color = DropdownMenuProperties.ContentColor.toColor(),
|
||||||
activeColor: Color = DropdownMenuProperties.ActiveColor.toColor().copy(alpha = 0.3f),
|
activeColor: Color = DropdownMenuProperties.ActiveColor.toColor().copy(alpha = 0.3f),
|
||||||
|
activeContentColor: Color = DropdownMenuProperties.ActiveContentColor.toColor(),
|
||||||
backgroundColor: Color = DropdownMenuProperties.BackgroundColor.toColor(),
|
backgroundColor: Color = DropdownMenuProperties.BackgroundColor.toColor(),
|
||||||
borderColor: Color = DropdownMenuProperties.BorderColor.toColor()
|
borderColor: Color = DropdownMenuProperties.BorderColor.toColor()
|
||||||
) = DropdownMenuColors(
|
) = DropdownMenuColors(
|
||||||
contentColor = contentColor,
|
contentColor = contentColor,
|
||||||
activeColor = activeColor,
|
activeColor = activeColor,
|
||||||
|
activeContentColor = activeContentColor,
|
||||||
backgroundColor = backgroundColor,
|
backgroundColor = backgroundColor,
|
||||||
borderColor = borderColor
|
borderColor = borderColor
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a [DropdownMenuStyle] with the default values.
|
* Creates a [DropdownMenuStyle] with the default values.
|
||||||
|
* @param textStyle the text style.
|
||||||
|
* @param activeTextStyle the text style of the active item.
|
||||||
* @param padding the menu padding.
|
* @param padding the menu padding.
|
||||||
* @param shape the menu shape.
|
* @param shape the menu shape.
|
||||||
* @param borderWidth the menu border width.
|
* @param borderWidth the menu border width.
|
||||||
@@ -710,6 +742,8 @@ object DropdownMenuDefaults {
|
|||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun style(
|
fun style(
|
||||||
|
textStyle: TextStyle = DropdownMenuProperties.Typography.toTextStyle(),
|
||||||
|
activeTextStyle: TextStyle = DropdownMenuProperties.ActiveTextStyle.toTextStyle().copy(fontWeight = FontWeight.Bold),
|
||||||
padding: ComponentPadding = DropdownMenuProperties.Padding.toPadding(),
|
padding: ComponentPadding = DropdownMenuProperties.Padding.toPadding(),
|
||||||
shape: Shape = DropdownMenuProperties.Shape.toShape(),
|
shape: Shape = DropdownMenuProperties.Shape.toShape(),
|
||||||
borderWidth: Dp = DropdownMenuProperties.BorderWidth.toDp(),
|
borderWidth: Dp = DropdownMenuProperties.BorderWidth.toDp(),
|
||||||
@@ -719,6 +753,8 @@ object DropdownMenuDefaults {
|
|||||||
inTransitionDuration: Int = DropdownMenuProperties.InTransitionDuration,
|
inTransitionDuration: Int = DropdownMenuProperties.InTransitionDuration,
|
||||||
outTransitionDuration: Int = DropdownMenuProperties.OutTransitionDuration
|
outTransitionDuration: Int = DropdownMenuProperties.OutTransitionDuration
|
||||||
) = DropdownMenuStyle(
|
) = DropdownMenuStyle(
|
||||||
|
textStyle = textStyle,
|
||||||
|
activeTextStyle = activeTextStyle,
|
||||||
padding = padding,
|
padding = padding,
|
||||||
shape = shape,
|
shape = shape,
|
||||||
borderWidth = borderWidth,
|
borderWidth = borderWidth,
|
||||||
@@ -747,8 +783,11 @@ internal object DropdownListProperties {
|
|||||||
internal object DropdownMenuProperties {
|
internal object DropdownMenuProperties {
|
||||||
val ContentColor = ColorsDescriptor.TextPrimary
|
val ContentColor = ColorsDescriptor.TextPrimary
|
||||||
val ActiveColor = ColorsDescriptor.ThemePrimary
|
val ActiveColor = ColorsDescriptor.ThemePrimary
|
||||||
|
val ActiveContentColor = ColorsDescriptor.ThemePrimary
|
||||||
val BackgroundColor = AreaBoxProperties.BackgroundColor
|
val BackgroundColor = AreaBoxProperties.BackgroundColor
|
||||||
val BorderColor = AreaBoxProperties.BorderColor
|
val BorderColor = AreaBoxProperties.BorderColor
|
||||||
|
val Typography = TypographyDescriptor.Primary
|
||||||
|
val ActiveTextStyle = TypographyDescriptor.Primary
|
||||||
val Padding = PaddingDescriptor(SizesDescriptor.SpacingTertiary)
|
val Padding = PaddingDescriptor(SizesDescriptor.SpacingTertiary)
|
||||||
val Shape = ShapesDescriptor.Primary
|
val Shape = ShapesDescriptor.Primary
|
||||||
val BorderWidth = AreaBoxProperties.BorderWidth
|
val BorderWidth = AreaBoxProperties.BorderWidth
|
||||||
@@ -762,6 +801,9 @@ internal object DropdownMenuProperties {
|
|||||||
private val LocalDropdownMenuActiveColor = compositionLocalOf { Color.Unspecified }
|
private val LocalDropdownMenuActiveColor = compositionLocalOf { Color.Unspecified }
|
||||||
|
|
||||||
private val LocalDropdownMenuContentColor = compositionLocalOf { Color.Unspecified }
|
private val LocalDropdownMenuContentColor = compositionLocalOf { Color.Unspecified }
|
||||||
|
private val LocalDropdownMenuActiveContentColor = compositionLocalOf { Color.Unspecified }
|
||||||
|
private val LocalDropdownMenuTextStyle = compositionLocalOf<TextStyle?> { null }
|
||||||
|
private val LocalDropdownMenuActiveTextStyle = compositionLocalOf<TextStyle?> { null }
|
||||||
private val LocalDropdownMenuContentPadding = compositionLocalOf<ComponentPadding?> { null }
|
private val LocalDropdownMenuContentPadding = compositionLocalOf<ComponentPadding?> { null }
|
||||||
private val LocalDropdownMenuContentShape = compositionLocalOf<Shape?> { null }
|
private val LocalDropdownMenuContentShape = compositionLocalOf<Shape?> { null }
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user