https://kotlinlang.org logo
#compose
Title
# compose
t

tieskedh

01/11/2021, 3:53 PM
Question: Do I need to call compose from the same coroutine every time? My Textfield is generating random input based upon previous entered characters. When I enter for example type "email@123456.com" then remove everything and then type "thisis" it copletes with "thisis@124356.com". I do submit my input to a multithreaded application (using MVIKotlin) but I would expect it would then complete to previous entered values instead of the characters in random order. Am I missing something?
a

Adam Powell

01/11/2021, 3:55 PM
cc @Siyamed
with the current shape of the TextField API it is important that any user edits are reflected on the next recomposition. Using an async pipeline to do this does indeed open the door for these kinds of bugs.
👍🏻 1
we are evaluating different options to mitigate this
t

tieskedh

01/11/2021, 4:00 PM
just to give you a little bit more information, I'm using Compose for desktop and it seems to only happen on mobile. (probably because laptop is much faster, but maybe it helps)
a

Adam Powell

01/11/2021, 4:07 PM
It has to do with the way that the Android IME framework expects to be notified of unexpected states. After typing, the soft keyboard expects the new changes to have been applied. Compose doesn't see those changes yet since they're still in the app's async data pipeline, so it tells the IME, "no, the state is (old state) instead," which produces this effect.
(roughly speaking)
t

tieskedh

01/11/2021, 6:28 PM
Ok, but in my case the text does fully show then I remove it and type only a view characters and it autocompletes wrong. does that make sense?
s

Siyamed

01/11/2021, 6:29 PM
I didn't understand the last comment
Do you set the value of TextField when onValueChange is fired?
t

tieskedh

01/11/2021, 6:30 PM
I can see "email@123456.com" on the screen. Then I clear everything and type the beginning. Then it autocompletes incorrectly
s

Siyamed

01/11/2021, 6:31 PM
If not, in the current design TextField has to decide on a value and afaik it chooses not to apply the changes and inform IME about this. Then there is the period of ipc call, meanwhile if user is typing, app is coming back with another value, etc: wonder if you can see why it is hard to consolidate that information.
Can you accept the changes first, and then fork to see what needs to happen and maybe when the async operation is completed, see if the computed new value should br applied or not.
Even if we change the API, it will probably make this consolidation a part of developer responsibility since TextField cannot reason about the intent of the changes on both sides.
t

tieskedh

01/11/2021, 6:41 PM
Ah, I understand now. I will try!
I'm sorry for taking all this time... I should have experimented more and have reduced the problem a lot more... before continuing I do have to verify some things: • "compose for desktop" used by android == "compose"? • rememberBy can be used without viewmodel? If both are yes, I tried the following and it gives the same result:
class MainActivity{
fun onCreate(...){
setContent{
val t by remember { mutablestateOf("") }
TextField(
t, {t = it }
)
}
}
}
s

Siyamed

01/11/2021, 7:59 PM
Compose for desktop is not equal to jetpack compose
Especially in terms of ime/keyboard they are not consolidated as we would like them to be
t

tieskedh

01/11/2021, 8:00 PM
Ah, when I use it for Android, they still use the components for desktop under the hood? I expected them to use expect actual...
s

Siyamed

01/11/2021, 8:04 PM
When we use for android it does not use comoonents for desktop
They are different
Yes they use expect actual
Does your problem happen on desktop or android?
t

tieskedh

01/11/2021, 8:05 PM
Android
s

Siyamed

01/11/2021, 8:05 PM
The sample you provided is the minumum working setup and it looks correct.
Remember can be used by viewmodel, correct
t

tieskedh

01/11/2021, 8:09 PM
I am using Jetpack compose multiplatform - setup and the problem occurs on Android. Then this is the correct place to ask? The code above gives the bug I described. Ps. I am using Samsung which, if I remember correctly from previous devices, does give more strange keyboard-behavior
s

Siyamed

01/11/2021, 8:31 PM
Thanks for the information, i never saw it happening even with that minimum case. There were some issues on samsung devices and we fixed them. However at this point it will be good to create a ticket describing compose version, minumum repro, device/os/keyboard.
t

tieskedh

01/11/2021, 8:33 PM
Thank you both for all your info and attention. I will create the ticket now.
Filed it. If more is needed, please let me know: https://issuetracker.google.com/issues/177236401
s

Siyamed

01/11/2021, 10:32 PM
Thanks. What is the compose version that you are using? in terms of alphaX ?
t

tieskedh

01/11/2021, 11:27 PM
I don't know. Jetbrains takes the snapshot of the branch and applies it with a compiles plugin. Therefor, I never come in contact with the real version and it probably is between versions
4 Views