refactor: adjust the priority of Modifier

This commit is contained in:
2023-11-15 23:23:22 +08:00
parent 575e4b5adb
commit c7d94653ec
7 changed files with 16 additions and 11 deletions

View File

@@ -87,10 +87,11 @@ fun Button(
backgroundColor = Color.Transparent
)
Box(
modifier = modifier.status(enabled)
modifier = Modifier.status(enabled)
.clip(style.shape)
.background(colors.backgroundColor, style.shape)
.borderOrNot(style.border, style.shape)
.then(modifier)
.rippleClickable(
enabled = enabled,
role = Role.Button,
@@ -104,7 +105,7 @@ fun Button(
LocalProgressIndicatorColors provides localProgressIndicatorColors
) {
Row(
Modifier.padding(
modifier = Modifier.padding(
top = style.topPadding.orElse() ?: style.padding,
start = style.startPadding.orElse() ?: style.padding,
bottom = style.bottomPadding.orElse() ?: style.padding,

View File

@@ -94,7 +94,7 @@ fun CheckBox(
val animatedContentScale by animateFloatAsState(if (hovered) style.hoveredGain else 1f)
val animatedContentAlpha by animateFloatAsState(if (checked) 1f else 0f)
val animatedContentLayer by animateFloatAsState(if (checked) 1f else 0f)
Row(modifier = modifier.status(enabled), verticalAlignment = Alignment.CenterVertically) {
Row(modifier = Modifier.status(enabled).then(modifier), verticalAlignment = Alignment.CenterVertically) {
Box(
modifier = Modifier.clickable(
interactionSource = interactionSource,

View File

@@ -95,7 +95,7 @@ fun RadioButton(
val animatedContentScale by animateFloatAsState(if (hovered) style.hoveredGain else 1f)
val animatedContentShadow by animateDpAsState(if (selected) style.contentShadowSize else 0.dp)
val animatedContentAlpha by animateFloatAsState(if (selected) 1f else 0f)
Row(modifier = modifier.status(enabled), verticalAlignment = Alignment.CenterVertically) {
Row(modifier = Modifier.status(enabled).then(modifier), verticalAlignment = Alignment.CenterVertically) {
Box(
modifier = Modifier.clickable(
interactionSource = interactionSource,

View File

@@ -211,7 +211,8 @@ fun Slider(
)
}
Box(
modifier = modifier.status(enabled)
modifier = Modifier.status(enabled)
.then(modifier)
.hoverable(interactionSource, enabled)
.pointerInput(Unit) {
if (enabled) detectTapGestures(

View File

@@ -67,11 +67,14 @@ fun Surface(
backgroundPrimary = colors.backgroundColor,
textPrimary = colors.contentColor
)
) { Box(modifier.surface(colors, style), content = content) }
) { Box(Modifier.surface(colors, style).then(modifier), content = content) }
}
private fun Modifier.surface(colors: SurfaceColors, style: SurfaceStyle) =
background(colors.backgroundColor).padding(
private fun Modifier.surface(
colors: SurfaceColors,
style: SurfaceStyle
) = background(colors.backgroundColor)
.padding(
top = style.topPadding.orElse() ?: style.padding,
start = style.startPadding.orElse() ?: style.padding,
bottom = style.bottomPadding.orElse() ?: style.padding,

View File

@@ -181,7 +181,7 @@ fun Switch(
)
)
}
Row(modifier = modifier.status(enabled)) {
Row(modifier = Modifier.status(enabled).then(modifier)) {
Box(
modifier = Modifier.padding(end = contentSpacing)
.clickable(enabled = enabled) { onCheckedChange(!checked) }

View File

@@ -237,13 +237,13 @@ private fun TextFieldDecorationBox(
else -> style.borderInactive
}.copy(animatedBorderWidth, SolidColor(animatedBorderColor))
Box(
modifier.textField(
Modifier.textField(
colors = colors,
style = style,
border = border,
enabled = enabled,
interactionSource = interactionSource
)
).then(modifier)
) {
Row {
header()