Zoltan Demant
10/12/2023, 7:16 AMdata class Holder(val text: String?)
(simplified) somewhere outside of compose.
Ideally Id like every text change in compose to be propagated to it, instantaneously; while still allowing for fluid editing (the typing experience suffers if holder.text
is the source of truth for the input field).
Unfortunately Im "stuck" with holder.text (String)
, otherwise a MutableStateFlow<String>
would probably work, I think.
Ive also considered making a mutableState
in compose the source of truth, basically using holder.text
as its initial value, then updating to reflect user input while propagating all changes upstream to holder.text
as well. Problem here being that if the upstream holder.text
value changes from external sources, they would be lost. Other than that, I think this solution could work; its just not very scalable; Ill eventually run into the external edits situation, hence the question. Any other ideas?Stylianos Gakis
10/12/2023, 7:50 AMZoltan Demant
10/12/2023, 8:00 AMremember(holder.text) { mutableState(holder.text) }
then updating the mutableState right away, and propagating changes to holder.text
like 0.5s later. Problem here is that input happens quickly, and I often find myself pressing continue before those 0.5s have passed. Reducing it to 0.25s or something smaller makes the input flow awkward instead, so no win win.Stylianos Gakis
10/12/2023, 8:04 AMZoltan Demant
10/12/2023, 8:07 AMif (state != newState) { x }
Stylianos Gakis
10/12/2023, 8:07 AMLaunchedEffect(Unit) {
snapshotFlow { holder.text }
.debounce()
.collect {
// stuff
}
}
Zoltan Demant
10/12/2023, 8:13 AMStylianos Gakis
10/12/2023, 8:16 AMZoltan Demant
10/12/2023, 8:28 AMStylianos Gakis
10/12/2023, 8:44 AMZoltan Demant
10/12/2023, 9:04 AMStylianos Gakis
10/12/2023, 9:14 AMWhen holder changes externally, compose SOT is “reset” back to the holders value, and so it goes.Yeap, as long as you make sure that the state changing from the input itself doesn’t create this loop, then yes it should just work I think 😄 Good luck with it! Always happy to help when I can 😊
ascii
10/12/2023, 11:06 AM@Stable
as well, with the same performance benefits, and it's what you should be doing anyway if you have mutableStates within it.
Dumbed down refresher: immutable is almost the same as stable, except that it says nothing about notifying compose of changes.Stylianos Gakis
10/12/2023, 12:27 PMZach Klippenstein (he/him) [MOD]
10/12/2023, 1:55 PMStylianos Gakis
10/12/2023, 2:08 PMZoltan Demant
10/12/2023, 3:38 PMZach Klippenstein (he/him) [MOD]
10/12/2023, 3:40 PMStylianos Gakis
10/12/2023, 3:42 PMZach Klippenstein (he/him) [MOD]
10/12/2023, 3:44 PMvide
10/12/2023, 3:50 PMZoltan Demant
10/12/2023, 4:05 PMascii
10/12/2023, 5:07 PMI really wish I liked coffeeSame! We probably have that gene that makes this and coriander etc taste far more bitter than normal.
Zach Klippenstein (he/him) [MOD]
10/13/2023, 12:47 PMZoltan Demant
10/13/2023, 12:49 PM