Hi, I'm having issues using TextField. I can't use...
# compose
f
Hi, I'm having issues using TextField. I can't use the cursor in order to move around the text and try to delete or edit it. I'm trying to do a simple calculator and this is what happens to me
There are 3 inputs: Initial Capital, Years and Rate, The component is defined as follows:
@Composable
fun Input(value: Double, label: String, changeListener: ((Double) -> Unit)) {
Column {
Text(text = label)
TextField(value = EditorModel(text = value.toString()), keyboardType = KeyboardType.Number,
onValueChange = {
changeListener(it.text.toDouble())
})
}
}
Any thoughts?
b
you're not changing the value
f
The onValueChanged callback is in the calling function:
Input(model.initial, "Initial capital") {
model.initial = it
}
So when the valueChange, the Model changes and the TextField is updated. This works, but I can't put the cursor anywhere in the TextField, just at the beginning
Also I can't delete the entered text, the "backspace" key seems not to work
b
well it works for me when I do
Copy code
@Composable
fun TextEdit(property: KMutableProperty0<String>) {
    Container(padding = EdgeInsets(5.dp)) {
        Surface(border = Border(Color.Black, 1.dp)) {
            Padding(10.dp) {
                TextField(value = property.get(), onValueChange = property.setter)
            }
        }
    }
}
maybe it's a bug?
f
Maybe, I don't understand the difference either
l
This seems like a bug
Can you file a bug with repro steps? I would greatly appreciate that
TextField had some strange interactions with layout, and we’ve fixed some big layout bugs recently. it’s possible this is fixed in master
f
Sure!, I will send a report with the video and full code. Also, I tried to use the
TextField
in a
Row
, but it crashes (someone reported it previously), so a moved it inside a
Column
. I think that bug is already sent and fixed in master, but I'm not sure about this one.
l
yep, that bug is fixed in master
send me the bug once you create it and i’ll make sure the proper people see it
k
@Facundo Rodriguez Arceri -> @Luca Nicoletti reported the
row
and
TextField
, I believe he found issues after the fix too but he might be able to express it better 🙂
l
The crash is fixed, but right now a
TextField
in a row will occupy the entire parent, leading you to have elements outside the screen(or parent) if the
Row
contains other elements https://issuetracker.google.com/issues/144301458
f
Ok, @Leland Richardson [G] . This is my first bug report. Let me know if it looks ok and with the enough information: https://issuetracker.google.com/issues/144888050
l
@Facundo Rodriguez Arceri bug looks great. Looks like matvei already assigned it to nona. Thanks!
❤️ 1
f
No problem, thank you!