Orhan Tozan
03/02/2021, 7:28 PMSean McQuillan [G]
03/02/2021, 7:29 PMFlow<NavigationDestination>
Orhan Tozan
03/02/2021, 7:30 PMSean McQuillan [G]
03/02/2021, 7:31 PMOrhan Tozan
03/02/2021, 7:32 PMSean McQuillan [G]
03/02/2021, 7:33 PMOrhan Tozan
03/02/2021, 7:34 PMSean McQuillan [G]
03/02/2021, 7:36 PMFlow<NavigateToFoo>
, you can collect that (unrelated to compose) and produce a State<CurrentNavScreen>
. Ignore the first in compose and only use the second. (If you prefer, that can be a flow or any other state-like observable type)Orhan Tozan
03/02/2021, 7:36 PMSean McQuillan [G]
03/02/2021, 7:36 PMOrhan Tozan
03/02/2021, 7:37 PMSean McQuillan [G]
03/02/2021, 7:39 PMLaunchedEffect(sourceFlow) {
sourceFlow.//operations
}
This will launch a coroutine once per composable instance (and restart it if sourceFlow changes).Orhan Tozan
03/02/2021, 7:45 PMLaunchedEffect(Unit) {
viewModel.nonFatalErrors
.onEach { exception -> Firebase.crashlytics.recordException(exception) }
.launchIn(this)
}
Sean McQuillan [G]
03/02/2021, 7:47 PMviewModel.nonFatalErrors
as the key there, otherwise you can run into under-restart problems as the code changes if the surrounding code ever swaps the Flow instance (this is a very common mistake, and it takes a bit to get the hang of it)
LaunchedEffect(viewModel.nonFatalErrors) {
viewModel.nonFatalErrors
.onEach { exception -> Firebase.crashlytics.recordException(exception) }
.launchIn(this)
}
Orhan Tozan
03/02/2021, 7:49 PMSean McQuillan [G]
03/02/2021, 7:50 PMFlow
changes on recomposition. In that case, you'd want to cancel the previous and restart a new collection.
Some quick rules for keys:
• All locals that are captured longer that the current recomposition lifetime should be keys
• All locals that are referenced (time delayed) after the current recomposition scope should either be keys, or wrapped in rememberUpdatedState
Orhan Tozan
03/02/2021, 7:55 PMSean McQuillan [G]
03/02/2021, 7:58 PMFlow.collectAsState()
in compose. This is more of a special case exit valve.Orhan Tozan
03/02/2021, 7:58 PMSean McQuillan [G]
03/02/2021, 7:59 PMOrhan Tozan
03/02/2021, 7:59 PMSean McQuillan [G]
03/02/2021, 8:02 PM.startPhoneCall
2. Pass enough information to the VM event handler to allow the event handler to handle the event entirely (this code belongs "in" an event handler)
3. Create an event and collect it in recompositionOrhan Tozan
03/02/2021, 8:04 PMSean McQuillan [G]
03/02/2021, 8:05 PMOrhan Tozan
03/02/2021, 8:05 PMSean McQuillan [G]
03/02/2021, 8:05 PMOrhan Tozan
03/02/2021, 8:05 PMSean McQuillan [G]
03/02/2021, 8:06 PMOrhan Tozan
03/02/2021, 8:06 PMSean McQuillan [G]
03/02/2021, 8:07 PMOrhan Tozan
03/02/2021, 8:08 PMSean McQuillan [G]
03/02/2021, 8:08 PMOrhan Tozan
03/02/2021, 8:10 PMSean McQuillan [G]
03/02/2021, 8:11 PMOrhan Tozan
03/02/2021, 8:11 PMSean McQuillan [G]
03/02/2021, 8:12 PMonClick
listenerOrhan Tozan
03/02/2021, 8:12 PMSean McQuillan [G]
03/02/2021, 8:12 PMOrhan Tozan
03/02/2021, 8:13 PMSean McQuillan [G]
03/02/2021, 8:14 PMOrhan Tozan
03/02/2021, 8:14 PMSean McQuillan [G]
03/02/2021, 8:15 PM