Chris Fillmore
06/15/2022, 4:32 PMval scope1 = rememberCoroutineScope()
val scope2 = LocalLifecycleOwner.current.lifecycleScopeChris Fillmore
06/15/2022, 4:32 PMbottomSheet(...) {
val scope = /* one of the scopes I'm asking about */
MyScreenContent(
onClickSomething = {
scope.launch {
val someResult = doSomethingSuspending()
if (someResult is success) {
navController.navigate(...)
}
}
}
)
}Chris Fillmore
06/15/2022, 4:36 PMLocalLifecycleOwner.current is the lifecycle of the bottom sheet in the example aboveAdam Powell
06/15/2022, 4:46 PMLocalLifecycleOwner is generally going to be very broadly scoped, usually to whatever activity, fragment, or navigation destination is above you. rememberCoroutineScope returns a scope that is a child of the composition effect scope and is cancelled when the call to rememberCoroutineScope leaves the composition. Dispatchers and other context elements may differ between the two; for example the lifecycle scope is generally not going to have the MonotonicFrameClock available that is required for most of the compose animation apis to workChris Fillmore
06/15/2022, 4:47 PMAdam Powell
06/15/2022, 4:49 PMLocalLifecycleOwner.current.lifecycleScope for things but there are occasional reasons to use it depending on what other abstractions you're invoking/appealing to. I would probably avoid the kind of usage in the snippet above.Chris Fillmore
06/15/2022, 4:53 PMCustomTabsSession.validateRelationship() at this point, because this could fail in a variety of ways. Most of these ways are just programmer error, I think, but some could perhaps warrant handling in the application (maybe there was a timeout, e.g.)Chris Fillmore
06/15/2022, 4:55 PMLocalLifecycleOwner.current, which is what triggered this questionChris Fillmore
06/15/2022, 4:55 PMLocalLifecycleOwner.current at the point where I create the NavController)Adam Powell
06/15/2022, 4:56 PMvalidateRelationship is called inAdam Powell
06/15/2022, 4:58 PMChris Fillmore
06/15/2022, 5:11 PMclass CustomTabsNavigator : Navigator<CustomTabsNavigator.Destination>Chris Fillmore
06/15/2022, 5:14 PMChris Fillmore
06/15/2022, 5:14 PM