https://kotlinlang.org logo
#compose
Title
# compose
g

gpaligot

01/15/2020, 2:04 PM
Hello! I’m trying to add a
TextField
in my screen but the component have a weird behavior. When I type any text in the text field, there isn’t any visual in the component on the screen. Someone has already encountered this issue? You can find my code here:
Copy code
@Composable
fun Password(data: LoginForm) {
    MyTextField(
        hint = "Password",
        keyboardType = KeyboardType.Password,
        imeAction = ImeAction.Done,
        onValueChange = { data.email = it }
    )
}

@Composable
fun MyTextField(
    hint: String,
    onValueChange: (text: String) -> Unit,
    keyboardType: KeyboardType = KeyboardType.Text,
    imeAction: ImeAction = ImeAction.Unspecified
) {
    val typography = +MaterialTheme.typography()
    val model = +state { "" }
    Padding(left = 8.dp, right = 8.dp, top = 8.dp) {
        Column {
            Text(
                text = hint,
                style = typography.subtitle1
            )
            HeightSpacer(height = 8.dp)
            TextField(
                value = model.value,
                onValueChange = onValueChange,
                keyboardType = keyboardType,
                imeAction = imeAction,
                textStyle = typography.body1,
                modifier = ExpandedWidth
            )
        }
    }
}
s

Siyamed

01/15/2020, 2:23 PM
You should add the callback in TextField and update the 'model' with the passed value
👍 2
g

gpaligot

01/15/2020, 2:35 PM
Thanks, I shouldn’t mix
state
and
@Model
data class. Everything is ok now!
2 Views