mirror of
https://github.com/BetterAndroid/FlexiUI.git
synced 2025-09-08 11:34:18 +08:00
refactor: merge contentSpacing into style in CheckBox and Switch
This commit is contained in:
@@ -67,6 +67,7 @@ data class CheckBoxColors(
|
|||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
data class CheckBoxStyle(
|
data class CheckBoxStyle(
|
||||||
|
val contentSpacing: Dp,
|
||||||
val contentSize: Dp,
|
val contentSize: Dp,
|
||||||
val strokeSize: Dp,
|
val strokeSize: Dp,
|
||||||
val pressedGain: Float,
|
val pressedGain: Float,
|
||||||
@@ -84,7 +85,6 @@ fun CheckBox(
|
|||||||
style: CheckBoxStyle = CheckBox.style,
|
style: CheckBoxStyle = CheckBox.style,
|
||||||
enabled: Boolean = true,
|
enabled: Boolean = true,
|
||||||
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
||||||
contentSpacing: Dp = CheckBox.contentSpacing,
|
|
||||||
content: @Composable () -> Unit = {}
|
content: @Composable () -> Unit = {}
|
||||||
) {
|
) {
|
||||||
val hovered by interactionSource.collectIsHoveredAsState()
|
val hovered by interactionSource.collectIsHoveredAsState()
|
||||||
@@ -121,7 +121,7 @@ fun CheckBox(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier.padding(start = contentSpacing)
|
modifier = Modifier.padding(start = style.contentSpacing)
|
||||||
.clickable(enabled = enabled) { onCheckedChange(!checked) }
|
.clickable(enabled = enabled) { onCheckedChange(!checked) }
|
||||||
) { content() }
|
) { content() }
|
||||||
}
|
}
|
||||||
@@ -136,10 +136,6 @@ object CheckBox {
|
|||||||
@Composable
|
@Composable
|
||||||
@ReadOnlyComposable
|
@ReadOnlyComposable
|
||||||
get() = defaultCheckBoxStyle()
|
get() = defaultCheckBoxStyle()
|
||||||
val contentSpacing: Dp
|
|
||||||
@Composable
|
|
||||||
@ReadOnlyComposable
|
|
||||||
get() = defaultCheckBoxContentSpacing()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -153,6 +149,7 @@ private fun defaultCheckBoxColors() = CheckBoxColors(
|
|||||||
@Composable
|
@Composable
|
||||||
@ReadOnlyComposable
|
@ReadOnlyComposable
|
||||||
private fun defaultCheckBoxStyle() = CheckBoxStyle(
|
private fun defaultCheckBoxStyle() = CheckBoxStyle(
|
||||||
|
contentSpacing = LocalSizes.current.spacingSecondary,
|
||||||
contentSize = DefaultContentSize,
|
contentSize = DefaultContentSize,
|
||||||
strokeSize = DefaultStrokeSize,
|
strokeSize = DefaultStrokeSize,
|
||||||
pressedGain = DefaultPressedGain,
|
pressedGain = DefaultPressedGain,
|
||||||
@@ -165,10 +162,6 @@ private fun defaultCheckBoxStyle() = CheckBoxStyle(
|
|||||||
@ReadOnlyComposable
|
@ReadOnlyComposable
|
||||||
private fun defaultCheckBoxBorder() = BorderStroke(LocalSizes.current.borderSizeTertiary, LocalColors.current.textPrimary)
|
private fun defaultCheckBoxBorder() = BorderStroke(LocalSizes.current.borderSizeTertiary, LocalColors.current.textPrimary)
|
||||||
|
|
||||||
@Composable
|
|
||||||
@ReadOnlyComposable
|
|
||||||
private fun defaultCheckBoxContentSpacing() = LocalSizes.current.spacingSecondary
|
|
||||||
|
|
||||||
private val DefaultContentSize = 13.dp
|
private val DefaultContentSize = 13.dp
|
||||||
private val DefaultStrokeSize = 20.dp
|
private val DefaultStrokeSize = 20.dp
|
||||||
|
|
||||||
|
@@ -75,6 +75,7 @@ data class SwitchColors(
|
|||||||
@Immutable
|
@Immutable
|
||||||
data class SwitchStyle(
|
data class SwitchStyle(
|
||||||
val padding: Dp,
|
val padding: Dp,
|
||||||
|
val contentSpacing: Dp,
|
||||||
val thumbRadius: Dp,
|
val thumbRadius: Dp,
|
||||||
val thumbGain: Float,
|
val thumbGain: Float,
|
||||||
val thumbShadowSize: Dp,
|
val thumbShadowSize: Dp,
|
||||||
@@ -95,7 +96,6 @@ fun Switch(
|
|||||||
style: SwitchStyle = Switch.style,
|
style: SwitchStyle = Switch.style,
|
||||||
enabled: Boolean = true,
|
enabled: Boolean = true,
|
||||||
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
||||||
contentSpacing: Dp = Switch.contentSpacing,
|
|
||||||
content: @Composable () -> Unit = {}
|
content: @Composable () -> Unit = {}
|
||||||
) {
|
) {
|
||||||
val thumbDiameter = style.thumbRadius * 2
|
val thumbDiameter = style.thumbRadius * 2
|
||||||
@@ -182,7 +182,7 @@ fun Switch(
|
|||||||
}
|
}
|
||||||
Row(modifier = Modifier.status(enabled).then(modifier)) {
|
Row(modifier = Modifier.status(enabled).then(modifier)) {
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier.padding(end = contentSpacing)
|
modifier = Modifier.padding(end = style.contentSpacing)
|
||||||
.clickable(enabled = enabled) { onCheckedChange(!checked) }
|
.clickable(enabled = enabled) { onCheckedChange(!checked) }
|
||||||
) { content() }
|
) { content() }
|
||||||
Track { Thumb() }
|
Track { Thumb() }
|
||||||
@@ -198,10 +198,6 @@ object Switch {
|
|||||||
@Composable
|
@Composable
|
||||||
@ReadOnlyComposable
|
@ReadOnlyComposable
|
||||||
get() = defaultSwitchStyle()
|
get() = defaultSwitchStyle()
|
||||||
val contentSpacing: Dp
|
|
||||||
@Composable
|
|
||||||
@ReadOnlyComposable
|
|
||||||
get() = defaultSwitchContentSpacing()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -215,6 +211,7 @@ private fun defaultSwitchColors() = SwitchColors(
|
|||||||
@Composable
|
@Composable
|
||||||
@ReadOnlyComposable
|
@ReadOnlyComposable
|
||||||
private fun defaultSwitchStyle() = SwitchStyle(
|
private fun defaultSwitchStyle() = SwitchStyle(
|
||||||
|
contentSpacing = LocalSizes.current.spacingSecondary,
|
||||||
padding = DefaultSwitchPadding,
|
padding = DefaultSwitchPadding,
|
||||||
thumbRadius = DefaultThumbRadius,
|
thumbRadius = DefaultThumbRadius,
|
||||||
thumbGain = DefaultThumbGain,
|
thumbGain = DefaultThumbGain,
|
||||||
@@ -231,10 +228,6 @@ private fun defaultSwitchStyle() = SwitchStyle(
|
|||||||
@ReadOnlyComposable
|
@ReadOnlyComposable
|
||||||
private fun defaultSwitchBorder() = BorderStroke(LocalSizes.current.borderSizeTertiary, LocalColors.current.textPrimary)
|
private fun defaultSwitchBorder() = BorderStroke(LocalSizes.current.borderSizeTertiary, LocalColors.current.textPrimary)
|
||||||
|
|
||||||
@Composable
|
|
||||||
@ReadOnlyComposable
|
|
||||||
private fun defaultSwitchContentSpacing() = LocalSizes.current.spacingSecondary
|
|
||||||
|
|
||||||
private val DefaultSwitchPadding = 3.dp
|
private val DefaultSwitchPadding = 3.dp
|
||||||
|
|
||||||
private val DefaultThumbRadius = 7.5.dp
|
private val DefaultThumbRadius = 7.5.dp
|
||||||
|
Reference in New Issue
Block a user