From bae72dba4ff4b250fde8aaf7d9d8cce405b00eba Mon Sep 17 00:00:00 2001 From: Shreyas Date: Sun, 31 Oct 2021 18:23:29 +0530 Subject: [PATCH] Use decorationBox instead of manually handling text field --- .../component/text/CommonTextField.kt | 41 ++++++++----------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/noty-android/app/composeapp/src/main/java/dev/shreyaspatil/noty/composeapp/component/text/CommonTextField.kt b/noty-android/app/composeapp/src/main/java/dev/shreyaspatil/noty/composeapp/component/text/CommonTextField.kt index d0f6c3ea..293e6c4c 100644 --- a/noty-android/app/composeapp/src/main/java/dev/shreyaspatil/noty/composeapp/component/text/CommonTextField.kt +++ b/noty-android/app/composeapp/src/main/java/dev/shreyaspatil/noty/composeapp/component/text/CommonTextField.kt @@ -18,9 +18,6 @@ package dev.shreyaspatil.noty.composeapp.component.text import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.ExperimentalAnimationApi -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding import androidx.compose.foundation.text.BasicTextField import androidx.compose.material.MaterialTheme import androidx.compose.material.OutlinedTextField @@ -33,7 +30,6 @@ import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.input.VisualTransformation import androidx.compose.ui.unit.TextUnit -import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import dev.shreyaspatil.noty.composeapp.ui.theme.getTextFieldHintColor @@ -70,25 +66,24 @@ fun BasicNotyTextField( textStyle: TextStyle = TextStyle(fontSize = 16.sp, fontWeight = FontWeight.Normal), onTextChange: (String) -> Unit, maxLines: Int = Int.MAX_VALUE, - textFieldModifier: Modifier = Modifier ) { - - Box(modifier = modifier.padding(4.dp)) { - AnimatedVisibility(visible = value.isBlank()) { - Text( - text = label, - color = getTextFieldHintColor(), - fontSize = textStyle.fontSize, - fontWeight = textStyle.fontWeight - ) + BasicTextField( + modifier = modifier, + value = value, + onValueChange = onTextChange, + textStyle = textStyle.copy(color = MaterialTheme.colors.onPrimary), + maxLines = maxLines, + cursorBrush = SolidColor(MaterialTheme.colors.primary), + decorationBox = { inlineTextField -> + AnimatedVisibility(visible = value.isBlank()) { + Text( + text = label, + color = getTextFieldHintColor(), + fontSize = textStyle.fontSize, + fontWeight = textStyle.fontWeight + ) + } + inlineTextField() } - BasicTextField( - modifier = textFieldModifier.fillMaxWidth(), - value = value, - onValueChange = onTextChange, - textStyle = textStyle.copy(color = MaterialTheme.colors.onPrimary), - maxLines = maxLines, - cursorBrush = SolidColor(MaterialTheme.colors.primary) - ) - } + ) }