https://kotlinlang.org logo
Title
m

mgrazianodecastro

03/02/2023, 4:25 PM
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

dazza5000

03/02/2023, 4:29 PM
do you hide or show the textfield based on content?
m

mgrazianodecastro

03/02/2023, 4:30 PM
yep, I check for empty to see if I need to replace it with a hint
d

dazza5000

03/02/2023, 4:31 PM
do you have a sample of the code?
m

mgrazianodecastro

03/02/2023, 4:32 PM
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

dazza5000

03/02/2023, 4:34 PM
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

mgrazianodecastro

03/02/2023, 4:34 PM
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

Stylianos Gakis

03/02/2023, 9:30 PM
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

Albert Chang

03/03/2023, 1:32 AM
You shouldn't hide it anyway, otherwise the cursor won't be shown when the text is empty.
z

Zach Klippenstein (he/him) [MOD]

03/06/2023, 5:27 PM
Can you file a bug with the entire stack trace and link it here? This should work without crashing
m

mgrazianodecastro

03/06/2023, 6:58 PM
If I find some free time this week, I can open it sure 😁
z

Zach Klippenstein (he/him) [MOD]

03/07/2023, 5:54 AM
Shouldn’t take more than a minute