myanmarking
01/18/2022, 7:59 PMCasey Brooks
01/18/2022, 8:03 PMrememberCoroutineScope()
to access the scope of a particular Composable, or else bubble events up to a ViewModel to handle in the viewModelScope
myanmarking
01/18/2022, 8:05 PMAbhinav Suthar
01/18/2022, 8:17 PMmyanmarking
01/18/2022, 8:23 PMCasey Brooks
01/18/2022, 8:23 PMrememberCoroutineScope()
.
If you want the coroutine to be bound to a particular UI composable, use the most local rememberCoroutineScope()
you can (i.e. access it from the body of the function and don't pass it to children functions).
If you want a coroutineScope that persists beyond any single Composable, then it shouldn't really be touched directly by child composables. Instead, the child composables should "bubble up" an "event" (callbacks) to the point that holds the scope, to avoid coupling a Composable to a coroutineScope that it is not directly tied to. This could be a rememberCoroutineScope
somewhere higher up the UI tree, or bubbled all the way to the screen root and passed to a ViewModelmyanmarking
01/18/2022, 8:27 PMCasey Brooks
01/18/2022, 8:31 PMCasey Brooks
01/18/2022, 8:32 PMrememberCoroutineScope
for all of them, each launch { }
will run in parallel to the othersCasey Brooks
01/18/2022, 8:41 PMmyanmarking
01/18/2022, 8:42 PM