I'm noticing a common thing that happens is ending...
# compose
I'm noticing a common thing that happens is ending up with split-second "loading" states in the app when some data retrieval is async, but the operation ends up being fast (e.g. network request normally, but cached data arrives). So for example, I press the refresh button, the thing being refreshed shows a spinner, but only for 200ms, then it actually loads, making the spinner flash which isn't nice. Is there a recommended how to avoid this, i.e. skip displaying the loading state unless it's been loading for at least 0.5s? First thought that comes to mind is debouncing a flow; but I wonder if there's other options which are more on the composable side? Maybe an animation with a delay if the state is loading (as the real state would cancel the animation)?
I dont have the code for this anymore, but I used produceState with a delay of some period of time before the loading indicator would actually show up, and it worked really nicely!
If the spinner pops up instantly, wouldn't delaying just postpone the problem instead of solving it? I mean, if you'd delay by 200ms and the load completes at 300ms, you'd still see the flash, just 200ms later than initially. What about fading in a spinner instead?
True, I thought about that - this is exploratory, I suspect that a large number of requests will finish in under Xms, so the spinner would only appear for the long tail.