I have a `TextField` with a `TextFieldValue` . Whe...
# compose
j
I have a
TextField
with a
TextFieldValue
. When I select a Text the
onValueChange
callback is invoked correctly. However when I perform a configuration change the `onValueChange`callback is invoked again (before the recomposition is invoked). This time with wrong values. The selection is cleared. When I use a
remembersaveable
it works more or less. It seems the selection is restored with the correct values (even though the context menu on the text is missing). It seems it simply doesn't update it before the recomposition. Since my state is more complex I store the value in my
ViewModel
. Of course the value get's updated with the wrong state before the recomposition. Any ideas how to solve this? Or is it a bug?
My wild guess would be that the focus is cleared and the selection is removed on the orientation change.
I'm now using a simple workaround: I check the current Lifecycle state and only update the value if the app is resumed.
j
Wow. That is actually a good idea - thanks!
👍 1
s
Hi @jannis , picking up on your line:
When I use a 
remembersaveable
 it works more or less.
Might you have any hint how you got
rememberSaveable
working with a
TextfieldValue
? I struggle a bit with a custom Saver object creation, since
TextfieldValue
is not parcelable by itself…
omg, found it in the docs, that easy:
Copy code
var textValue by rememberSaveable(stateSaver = TextFieldValue.Saver) {
    mutableStateOf(TextFieldValue())
}
Nevermind 🙂
j
Yes like this 🙂
👍 1