Grigory Panko
03/13/2024, 4:27 PMString, (String) -> Unit
overload of BTF2, leaving only the one with TextFieldState
. Does this mean that Compose enforces us to hoist the TextFieldState
directly inside the ViewModel state, because including the suggested workaround with StateSyncingModifier
and etc. into each project is too cumbersome? I'm used to think that including any compose-related class (MutableState
, TextFieldState
or anything else) into my ViewModel is a bad practice (and sometimes even impossible). Or is there some better option?Stylianos Gakis
03/13/2024, 4:46 PMStateSyncingModifierWhat’s
StateSyncingModifier
from here? Is that from some blogpost, or something in the library that is new?
I’m used to think that including any compose-related class (Hoisting your compose related classes into ViewModel is by no means a bad practice. The non UI parts of compose can just be used there without any problem. The one problem which I can imagine is if you are sharing your ViewModel with iOS and having a TextFieldState in it might not be possible, that I can understand.,MutableState
or anything else) into my ViewModel is a bad practiceTextFieldState
Grigory Panko
03/13/2024, 4:59 PMStylianos Gakis
03/13/2024, 5:07 PMIt's also possible to internally wrap around an existing TextFieldState and expose a more
lightweight state hoisting mechanism through a value that dictates the content of the TextField
and an onValueChange callback that communicates the changes to this value.
@sample androidx.compose.foundation.samples.BasicTextFieldWithValueOnValueChangeSample
Seems to want you to look at this https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]mple.kt;l=41?q=BasicTextFieldWithValueOnValueChangeSample&sq= and just copy-paste that if you want to have a BTF2 with the old API.
You say that it sounds cumbersome, but you only import it once and it should be fine from that point on, no?Stylianos Gakis
03/13/2024, 5:10 PMGrigory Panko
03/13/2024, 5:26 PMStylianos Gakis
03/13/2024, 5:35 PMGrigory Panko
03/13/2024, 5:45 PM