I have a `mutableStateOf` for a text field and a `...
# compose
v
I have a
mutableStateOf
for a text field and a
snapshotFlow
version of it in my viewmodel, How can i create a
flow
for typing indicator type of feature Like when there are emissions in the snapshot flow, it should be true and when there are no emission for like 3seconds, it will be false Again snapshot flow got new emissions, and its again true Any idea?
a
Something like
Copy code
snapshotFlow { textFieldValue }
    .transformLatest {
        emit(true)
        delay(3000)
        emit(false)
    }
    .distinctUntilChanged()
v
What if user is typing for more than 3 seconds
It will drop the previous values?
a
https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/transform-latest.html
When the original flow emits a new value, the previous
transform
block is cancelled, thus the name
transformLatest
.
v
Thankyou
h
One thing to note is that if you are observing a
TextFieldValue
, the flow will also emit when the cursor or selection position changes. If you are only interested in typing, only observe the text contents of the value.
j
Try denounce
Denounce