mirror of
https://github.com/BetterAndroid/FlexiUI.git
synced 2025-09-08 11:34:18 +08:00
feat: add active color in DropdownMenu
This commit is contained in:
@@ -88,6 +88,7 @@ import kotlin.math.min
|
|||||||
@Immutable
|
@Immutable
|
||||||
data class DropdownMenuColors(
|
data class DropdownMenuColors(
|
||||||
val contentColor: Color,
|
val contentColor: Color,
|
||||||
|
val activeColor: Color,
|
||||||
val borderColor: Color
|
val borderColor: Color
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -147,12 +148,15 @@ fun DropdownMenuItem(
|
|||||||
onClick: () -> Unit,
|
onClick: () -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
contentColor: Color = Color.Unspecified,
|
contentColor: Color = Color.Unspecified,
|
||||||
|
activeColor: Color = Color.Unspecified,
|
||||||
contentStyle: AreaBoxStyle? = null,
|
contentStyle: AreaBoxStyle? = null,
|
||||||
enabled: Boolean = true,
|
enabled: Boolean = true,
|
||||||
|
actived: Boolean = false,
|
||||||
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
||||||
content: @Composable RowScope.() -> Unit
|
content: @Composable RowScope.() -> Unit
|
||||||
) {
|
) {
|
||||||
val currentColor = contentColor.orElse() ?: LocalDropdownMenuContentColor.current.orElse() ?: DropdownMenu.colors.contentColor
|
val currentColor = contentColor.orElse() ?: LocalDropdownMenuContentColor.current.orElse() ?: DropdownMenu.colors.contentColor
|
||||||
|
val currentActiveColor = activeColor.orElse() ?: LocalDropdownMenuActiveColor.current.orElse() ?: DropdownMenu.colors.activeColor
|
||||||
val currentStyle = contentStyle ?: LocalDropdownMenuContentStyle.current ?: DropdownMenu.style.contentStyle
|
val currentStyle = contentStyle ?: LocalDropdownMenuContentStyle.current ?: DropdownMenu.style.contentStyle
|
||||||
AreaRow(
|
AreaRow(
|
||||||
modifier = Modifier.status(enabled)
|
modifier = Modifier.status(enabled)
|
||||||
@@ -169,7 +173,7 @@ fun DropdownMenuItem(
|
|||||||
interactionSource = interactionSource,
|
interactionSource = interactionSource,
|
||||||
onClick = onClick
|
onClick = onClick
|
||||||
),
|
),
|
||||||
color = Color.Transparent,
|
color = if (actived) currentActiveColor else Color.Transparent,
|
||||||
style = currentStyle,
|
style = currentStyle,
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
@@ -222,6 +226,7 @@ private fun DropdownMenuContent(
|
|||||||
) {
|
) {
|
||||||
CompositionLocalProvider(
|
CompositionLocalProvider(
|
||||||
LocalDropdownMenuContentColor provides colors.contentColor,
|
LocalDropdownMenuContentColor provides colors.contentColor,
|
||||||
|
LocalDropdownMenuActiveColor provides colors.activeColor,
|
||||||
LocalDropdownMenuContentStyle provides style.contentStyle
|
LocalDropdownMenuContentStyle provides style.contentStyle
|
||||||
) { content() }
|
) { content() }
|
||||||
}
|
}
|
||||||
@@ -320,12 +325,15 @@ object DropdownMenu {
|
|||||||
|
|
||||||
private val LocalDropdownMenuContentColor = compositionLocalOf { Color.Unspecified }
|
private val LocalDropdownMenuContentColor = compositionLocalOf { Color.Unspecified }
|
||||||
|
|
||||||
|
private val LocalDropdownMenuActiveColor = compositionLocalOf { Color.Unspecified }
|
||||||
|
|
||||||
private val LocalDropdownMenuContentStyle = compositionLocalOf<AreaBoxStyle?> { null }
|
private val LocalDropdownMenuContentStyle = compositionLocalOf<AreaBoxStyle?> { null }
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@ReadOnlyComposable
|
@ReadOnlyComposable
|
||||||
private fun defaultDropdownMenuColors() = DropdownMenuColors(
|
private fun defaultDropdownMenuColors() = DropdownMenuColors(
|
||||||
contentColor = LocalColors.current.textPrimary,
|
contentColor = LocalColors.current.textPrimary,
|
||||||
|
activeColor = LocalColors.current.themePrimary.copy(alpha = 0.3f),
|
||||||
borderColor = AreaBox.color
|
borderColor = AreaBox.color
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user