I have a `BasicTextField` field which, when cleani...
# compose
m
I have a
BasicTextField
field which, when cleaning up the text with
backspace
and writing something again, it is raising
java.lang.IllegalStateException: LayoutCoordinate operations are only valid when isAttached is true
. Does anyone know why?
d
do you hide or show the textfield based on content?
m
yep, I check for empty to see if I need to replace it with a hint
d
do you have a sample of the code?
m
Copy code
BasicTextField(
                value = value,
                onValueChange = { onValueChange(it) },
                ...,
                decorationBox = { innerTextField ->
                    Row(
                        modifier = Modifier.fillMaxSize(),
                        horizontalArrangement = Arrangement.Center,
                        verticalAlignment = Alignment.CenterVertically
                    ){
                        if (value.isEmpty()) {
                            Text(
                                text = hint,
                                ...
                            )
                        }else{
                            innerTextField()
                        }
                    }
                }
            )
d
this
innerTextField()
is probably being detached when you are removing it from composition (im not an expert), but that might be causing the issue
m
you are probably right
I'm gonna remove from the else clause, let's see
yep, that fixed the problem. To keep the visual the same, we must have some layout composables like column and row, but it works. Thanks!
s
If you want something to take the space it wants to, so that you don’t get this jumpiness, but you still want to hide it, you can do the trick of measuring it, but not placing it Checkout this https://kotlinlang.slack.com/archives/CJLTWPH7S/p1673314562259549?thread_ts=1673311120.934409&cid=CJLTWPH7S thread for how to do that
a
You shouldn't hide it anyway, otherwise the cursor won't be shown when the text is empty.
z
Can you file a bug with the entire stack trace and link it here? This should work without crashing
m
If I find some free time this week, I can open it sure 😁
z
Shouldn’t take more than a minute
305 Views