fix: Text field enlarge a little when focused

This commit is contained in:
Artem Chepurnoy 2024-03-30 09:28:17 +02:00
parent 50a0d6f591
commit b933993001
No known key found for this signature in database
GPG Key ID: FAC37D0CF674043E
1 changed files with 7 additions and 5 deletions

View File

@ -393,7 +393,7 @@ fun FlatTextField(
) )
val padding by animateDpAsState( val padding by animateDpAsState(
targetValue = if (focused) 28.dp else 0.dp, targetValue = if (focused) 16.dp else 0.dp,
) )
Box( Box(
@ -401,13 +401,13 @@ fun FlatTextField(
.heightIn(min = 48.dp) .heightIn(min = 48.dp)
.graphicsLayer { .graphicsLayer {
alpha = disabledAlphaState.value alpha = disabledAlphaState.value
translationY = -padding.value
}, },
contentAlignment = Alignment.CenterStart, contentAlignment = Alignment.CenterStart,
) { ) {
Text( Text(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth(),
.padding(bottom = padding),
text = label, text = label,
fontSize = textSize.sp, fontSize = textSize.sp,
maxLines = 1, maxLines = 1,
@ -417,7 +417,7 @@ fun FlatTextField(
} }
val focused = (hasFocus || value.text.isNotEmpty()) && label != null val focused = (hasFocus || value.text.isNotEmpty()) && label != null
val padding by animateDpAsState( val padding by animateDpAsState(
targetValue = if (focused) 20.dp else 0.dp, targetValue = if (focused) 8.dp else 0.dp,
) )
val finalPlaceholder = placeholder ?: value.hint val finalPlaceholder = placeholder ?: value.hint
@ -427,7 +427,9 @@ fun FlatTextField(
.focusRequester2(fieldFocusRequester) .focusRequester2(fieldFocusRequester)
.heightIn(min = 48.dp), .heightIn(min = 48.dp),
boxModifier = boxModifier boxModifier = boxModifier
.padding(top = padding), .graphicsLayer {
translationY = padding.value
},
placeholder = if (finalPlaceholder != null) { placeholder = if (finalPlaceholder != null) {
// composable // composable
{ {