Alexander Sitnikov
09/15/2021, 9:35 AMFlow.collectAsState()
where collection of the flow starts one frame after initial composition. Usually my Flow
emits its first value immediately upon subscription, and in that case I don’t want to see initialValue
. But because collect starts only after first frame, there’s visible fast “blink” when you first open a screen. As I understand it’s because LaunchedEffect
executes it’s lambda in AndroidUiDispatcher
, and it dispatches `LaunchedEffect`’s job only after first frame has been drawn. I found a solution, where if I launch a coroutine that collects the Flow
with start = CoroutineStart.UNDISPATCHED
, value is produced immediately after first composition (so I can read it inside SubcomposeLayout
of some sort, and screen does not “blink”). Is there any pitfalls of doing so?Adam Powell
09/15/2021, 2:18 PMAdam Powell
09/15/2021, 2:19 PMAlexander Sitnikov
09/15/2021, 2:19 PMAdam Powell
09/15/2021, 2:21 PMAlexander Sitnikov
09/15/2021, 2:22 PMAdam Powell
09/15/2021, 2:23 PMAlexander Sitnikov
09/15/2021, 2:24 PMAdam Powell
09/15/2021, 2:25 PMAdam Powell
09/15/2021, 2:26 PMAlexander Sitnikov
09/15/2021, 2:26 PMAdam Powell
09/15/2021, 2:27 PMAdam Powell
09/15/2021, 2:27 PMAdam Powell
09/15/2021, 2:28 PMAdam Powell
09/15/2021, 2:28 PMAdam Powell
09/15/2021, 2:29 PMremember {}
block directly and then cancel it in both onForgotten
and onAbandoned
Adam Powell
09/15/2021, 2:30 PMAdam Powell
09/15/2021, 2:31 PMAdam Powell
09/15/2021, 2:33 PMAdam Powell
09/15/2021, 2:33 PMAlexander Sitnikov
09/15/2021, 2:35 PMAdam Powell
09/15/2021, 2:36 PMAlexander Sitnikov
09/15/2021, 2:36 PMAdam Powell
09/15/2021, 2:37 PMAdam Powell
09/15/2021, 2:37 PMAdam Powell
09/15/2021, 2:38 PMAdam Powell
09/15/2021, 2:39 PMAdam Powell
09/15/2021, 2:39 PMrunUpdates()
function in a LaunchedEffect
can be highly effective for these cases