https://kotlinlang.org logo
#compose-ios
Title
# compose-ios
m

Michal Guspiel

03/26/2024, 2:01 PM
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

Arkadii Ivanov

03/26/2024, 6:42 PM
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

Michal Guspiel

03/26/2024, 6:58 PM
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

Arkadii Ivanov

03/26/2024, 6:59 PM
It would be nice to see some code, or maybe a reproducer code.
m

Michal Guspiel

03/26/2024, 7:02 PM
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

Arkadii Ivanov

03/26/2024, 7:30 PM
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

Djuro

03/27/2024, 8:47 AM
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

Michal Guspiel

03/27/2024, 12:52 PM
Turns out iOS TextField is faulty. disabling animations by
UIView.setAnimationsEnabled(*false*)
fixes the issue.
👍 2
c

Colton Idle

03/31/2024, 12:41 PM
I'd file a bug so that they fix it for everyone. 😄
2
3 Views