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 backgroundColor = Color.Transparent
) )
Box( Box(
modifier = modifier.status(enabled) modifier = Modifier.status(enabled)
.clip(style.shape) .clip(style.shape)
.background(colors.backgroundColor, style.shape) .background(colors.backgroundColor, style.shape)
.borderOrNot(style.border, style.shape) .borderOrNot(style.border, style.shape)
.then(modifier)
.rippleClickable( .rippleClickable(
enabled = enabled, enabled = enabled,
role = Role.Button, role = Role.Button,
@@ -104,7 +105,7 @@ fun Button(
LocalProgressIndicatorColors provides localProgressIndicatorColors LocalProgressIndicatorColors provides localProgressIndicatorColors
) { ) {
Row( Row(
Modifier.padding( modifier = Modifier.padding(
top = style.topPadding.orElse() ?: style.padding, top = style.topPadding.orElse() ?: style.padding,
start = style.startPadding.orElse() ?: style.padding, start = style.startPadding.orElse() ?: style.padding,
bottom = style.bottomPadding.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 animatedContentScale by animateFloatAsState(if (hovered) style.hoveredGain else 1f)
val animatedContentAlpha by animateFloatAsState(if (checked) 1f else 0f) val animatedContentAlpha by animateFloatAsState(if (checked) 1f else 0f)
val animatedContentLayer 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( Box(
modifier = Modifier.clickable( modifier = Modifier.clickable(
interactionSource = interactionSource, interactionSource = interactionSource,

View File

@@ -95,7 +95,7 @@ fun RadioButton(
val animatedContentScale by animateFloatAsState(if (hovered) style.hoveredGain else 1f) val animatedContentScale by animateFloatAsState(if (hovered) style.hoveredGain else 1f)
val animatedContentShadow by animateDpAsState(if (selected) style.contentShadowSize else 0.dp) val animatedContentShadow by animateDpAsState(if (selected) style.contentShadowSize else 0.dp)
val animatedContentAlpha by animateFloatAsState(if (selected) 1f else 0f) 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( Box(
modifier = Modifier.clickable( modifier = Modifier.clickable(
interactionSource = interactionSource, interactionSource = interactionSource,

View File

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

View File

@@ -67,11 +67,14 @@ fun Surface(
backgroundPrimary = colors.backgroundColor, backgroundPrimary = colors.backgroundColor,
textPrimary = colors.contentColor 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) = private fun Modifier.surface(
background(colors.backgroundColor).padding( colors: SurfaceColors,
style: SurfaceStyle
) = background(colors.backgroundColor)
.padding(
top = style.topPadding.orElse() ?: style.padding, top = style.topPadding.orElse() ?: style.padding,
start = style.startPadding.orElse() ?: style.padding, start = style.startPadding.orElse() ?: style.padding,
bottom = style.bottomPadding.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( Box(
modifier = Modifier.padding(end = contentSpacing) modifier = Modifier.padding(end = contentSpacing)
.clickable(enabled = enabled) { onCheckedChange(!checked) } .clickable(enabled = enabled) { onCheckedChange(!checked) }

View File

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