Nacho Ruiz Martin
12/24/2023, 1:10 PMBasicTextField2
API conjugate with non-compose state holders?
I mean, let's say you have a ViewModel shared with other platforms and some of those platforms are not using Compose. The "good" way of using BTF2 is to store a TextFieldState
with which you can use all the fancy edit
API. But what if I can't store Compose things in my state holder because it's not exclusively used by Compose UIs?Nacho Ruiz Martin
12/24/2023, 1:11 PMFranSoto
12/24/2023, 2:48 PMNacho Ruiz Martin
12/24/2023, 2:55 PMFranSoto
12/24/2023, 4:42 PMNacho Ruiz Martin
12/24/2023, 5:01 PMFranSoto
12/24/2023, 5:01 PMHalil Ozercan
12/25/2023, 1:05 AMbecause you wouldn't be able to edit the text programmatically in the VM layerCan you give some examples to this? What is blocking you from implementing the filtering functionality in the UI layer, or call ViewModel functions from
inputTransformation
?Halil Ozercan
12/25/2023, 1:06 AMBasicTextField2
API difficult to work with compared to existing APIs.efemoney
12/25/2023, 10:48 AMKarthick
12/25/2023, 3:48 PMStateFlow
as data holder and in compose you can do stateFlow.collectAsState()
Nacho Ruiz Martin
12/25/2023, 5:05 PMTextFieldState
, otherwise, the changes won't propagate to the UI until the field loses focus.
But TextFieldState
is a Compose class. Propagating that to the ViewModel is not possible in this context.
> What is blocking you from implementing the filtering functionality in the UI layer, or call ViewModel functions from inputTransformation ?
>
It's not filtering or calling the ViewModel what I want to achieve. I'm trying to modify the text in the ViewModel. I hope it's more clear now!
> go expect+actual or interface+platformImplementation
>
This feels way more complex than before just for a TextField.
> You can have a StateFlow as data holder and in compose you can do stateFlow.collectAsState()
>
I don't see how this helps.Nacho Ruiz Martin
12/25/2023, 5:14 PMAlbert Chang
12/26/2023, 2:28 PMString
and (String) -> Unit
will still be available, so you should be able to do whatever you can do now with that overload.Nacho Ruiz Martin
12/26/2023, 2:29 PMAlbert Chang
12/26/2023, 2:32 PMNacho Ruiz Martin
12/26/2023, 2:35 PMHowever, the text field won’t update the state with your programmatic changes while the field is in focus, it respects only the input coming from typing events
Albert Chang
12/26/2023, 3:07 PMAlbert Chang
12/26/2023, 3:12 PMKarthick
12/26/2023, 3:36 PMTextFieldState
Nacho Ruiz Martin
12/26/2023, 3:43 PMDon't you need to place the cursor at the end when you prepend the text?
Ah, you're right. Since this wasn't a real case but a theoretical one I missed the fact that you have to store TextFieldState on BTF1 for the same behaviour. So expect/actual feels like the way to go in the current case too.
You can see the overloads just receiving just text and inside handle with TextFieldState
Yes, I know the existence of this overload. But as it was already stated, this isn't usable because the UI won't update until the text field loses focus. Anyway, @Halil Ozercan, in case you want a usecase that is not covered by the BTF2 API (it wasn't exactly covered by the BTF1 either).