Hi, my TextField behaves super oddly. It works per...
# compose-ios
m
Hi, my TextField behaves super oddly. It works perfectly in Android but in iOS whenever I enter a character,
onValueChange
is called multiple times. This only happens if my TextField value exists in ViewModel. If value exists in composable use
remember
it behaves as expected. Has anyone faced a similar issue?
a
I'm not sure, but if you are using StateFlow, make sure you are collecting the flow on the immediate dispatcher. E.g. flow.collectAsState(Dispatchers.Main.immediate).
m
Hi, that doesn’t help. This is odd since my app works quite alright. Nothing unusual happens until I edit the TextField. After I edit the TextField
LaunchEffect(Unit){...}
get’s called dozens of time. This also happens if I back up my TextField with
var key by _remember_ *{* _mutableStateOf_("") *}*
(tried this to verify that recompositions aren’t ducked). In such case input to TextField works alright but afterwards the app doesn’t work right.
a
It would be nice to see some code, or maybe a reproducer code.
m
It’s right here: https://github.com/solita/HRnD/blob/main/HRnD/composeApp/src/commonMain/kotlin/fi/solita/hrnd/feature/list/ListScreen.kt I’ve added
Copy code
text: String,
        onSearchUpdate: (String) -> Unit,
to BuildContent function in order to verify if the issue doesn’t come from MVI-Orbit
a
I couldn't find any issues with the code straightaway. If the issue happens only if the the state is in the ViewModel, then it might also worth asking in #orbit-mvi.
d
just a guess, maybe try compose-compiler to
1.5.8
and maybe try with
TextFieldState
, though I am unsure why it wouldn't work now
m
Turns out iOS TextField is faulty. disabling animations by
UIView.setAnimationsEnabled(*false*)
fixes the issue.
👍 2
c
I'd file a bug so that they fix it for everyone. 😄
2