Skip to content

Commit

Permalink
Use decorationBox instead of manually handling text field
Browse files Browse the repository at this point in the history
  • Loading branch information
PatilShreyas committed Oct 31, 2021
1 parent 8ed29b3 commit bae72db
Showing 1 changed file with 18 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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)
)
}
)
}

0 comments on commit bae72db

Please sign in to comment.