I would like to show a vector image within my comp...
# compose
l
I would like to show a vector image within my composable for a specific period of time, e.g. 3 seconds and it should block so nothing else is done while it is displayed. Is this possible?
a
"nothing else" in what kind of scope? The scope of that particular composable or something wider? The former, yes, very possible. The latter, I'm curious about the use case, but it tends to be quite difficult without some wider intentional collaboration.
(and the idea that a called composable can't interfere with its caller is generally considered a feature)
l
@Adam Powell Sorry, I mean in the scope of the composable. My use case is to show a vector image dependent on the current state. The possible states are INITIAL, LOADING, SUCCESS but it might happen that this cycle is < 5 seconds so the images are not even noted. So I want to wait a fake second between every state
a
maybe with something like
Copy code
@Composable fun <T> produceDelayed(value: T, delayMillis: Long): State<T> {
    val ch = remember { Channel<T>(Channel.CONFLATED) }
    SideEffect {
        ch.offer(value)
    }
    return produceState(value) {
        for (item in ch) {
            this.value = item
            delay(delayMillis)
        }
    }
}
so it'll wait at least
delayMillis
after producing every new value. You can use a
receiveAsFlow()
and a series of operators with a channel with a buffer if you want more complex behavior
👍 1
l
Thanks @Adam Powell