refactor: move decoration style to InnerDecorationBox in TextField

This commit is contained in:
2023-11-19 01:30:31 +08:00
parent 98344617bb
commit 15e3161d3f

View File

@@ -146,9 +146,12 @@ fun TextField(
verticalAlignment = Alignment.CenterVertically
) {
header?.also {
Box(modifier = Modifier.textFieldPadding(style, fitStart = true)) {
DecorationBoxStyle(animatedDecorTint) { it() }
}
InnerDecorationBox(
decorTint = animatedDecorTint,
style = style,
header = true,
content = it
)
}
Box(modifier = Modifier.weight(1f, fill = false).textFieldPadding(style)) {
TextFieldStyle(colors) {
@@ -179,9 +182,27 @@ fun TextField(
}
}
footer?.also {
Box(modifier = Modifier.textFieldPadding(style, fitEnd = true)) {
DecorationBoxStyle(animatedDecorTint) { it() }
}
InnerDecorationBox(
decorTint = animatedDecorTint,
style = style,
footer = true,
content = it
)
}
}
}
@Composable
private fun InnerDecorationBox(
decorTint: Color,
style: TextFieldStyle,
header: Boolean = false,
footer: Boolean = false,
content: @Composable () -> Unit
) {
Box(modifier = Modifier.textFieldPadding(style, fitStart = header, fitEnd = footer)) {
CompositionLocalProvider(LocalIconTint provides decorTint) {
content()
}
}
}
@@ -208,13 +229,6 @@ private fun TextFieldStyle(colors: TextFieldColors, content: @Composable () -> U
}
}
@Composable
private fun DecorationBoxStyle(decorTint: Color, content: @Composable () -> Unit) {
CompositionLocalProvider(LocalIconTint provides decorTint) {
content()
}
}
private fun Modifier.textField(
colors: TextFieldColors,
style: TextFieldStyle,