Skip to content

Commit 00198b3

Browse files
committed
library: TextField: Opt labelOffset
1 parent a52e4f9 commit 00198b3

File tree

1 file changed

+7
-4
lines changed
  • miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/basic

1 file changed

+7
-4
lines changed

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/basic/TextField.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import androidx.compose.ui.text.style.TextAlign
3636
import androidx.compose.ui.unit.Dp
3737
import androidx.compose.ui.unit.DpSize
3838
import androidx.compose.ui.unit.dp
39+
import androidx.compose.ui.unit.max
3940
import androidx.compose.ui.unit.sp
4041
import top.yukonga.miuix.kmp.theme.MiuixTheme
4142
import top.yukonga.miuix.kmp.utils.SmoothRoundedCornerShape
@@ -108,12 +109,14 @@ fun TextField(
108109
val isFocused by interactionSource.collectIsFocusedAsState()
109110
val borderWidth by animateDpAsState(if (isFocused) 2.dp else 0.dp)
110111
val borderColor by animateColorAsState(if (isFocused) borderColor else backgroundColor)
111-
val labelOffsetY by animateDpAsState(if (value.text.isNotEmpty() && !useLabelAsPlaceholder) -(insideMargin.height / 2) else 0.dp)
112-
val innerTextOffsetY by animateDpAsState(if (value.text.isNotEmpty() && !useLabelAsPlaceholder) (insideMargin.height / 2) else 0.dp)
113-
val labelFontSize by animateDpAsState(if (value.text.isNotEmpty() && !useLabelAsPlaceholder) 10.dp else 17.dp)
112+
val labelOffsetY by animateDpAsState(if (value.text.isNotEmpty() && !useLabelAsPlaceholder) -(insideMargin.height / 2.2f) else 0.dp)
113+
val innerTextOffsetY by animateDpAsState(if (value.text.isNotEmpty() && !useLabelAsPlaceholder) (insideMargin.height / 1.8f) else 0.dp)
114114
val border = Modifier.border(borderWidth, borderColor, RoundedCornerShape(cornerRadius))
115115
val labelOffset = if (label != "" && !useLabelAsPlaceholder) Modifier.offset(y = labelOffsetY) else Modifier
116116
val innerTextOffset = if (label != "" && !useLabelAsPlaceholder) Modifier.offset(y = innerTextOffsetY) else Modifier
117+
val labelFontSize by animateDpAsState(
118+
if (value.text.isNotEmpty() && !useLabelAsPlaceholder) max(textStyle.fontSize.value.dp - 7.dp, 0.dp) else textStyle.fontSize.value.dp
119+
)
117120

118121
BasicTextField(
119122
value = value,
@@ -154,7 +157,7 @@ fun TextField(
154157
modifier = Modifier
155158
.weight(1f)
156159
.then(paddingModifier),
157-
contentAlignment = Alignment.CenterStart
160+
contentAlignment = Alignment.TopStart
158161
) {
159162
androidx.compose.animation.AnimatedVisibility(
160163
visible = if (useLabelAsPlaceholder) value.text.isEmpty() else true,

0 commit comments

Comments
 (0)