In <owl> compose sample, `lifecycleIsResumed` chec...
# compose
r
In owl compose sample,
lifecycleIsResumed
check is added to discard duplicated navigation events. Is this change required as I've followed similar pattern?
i
This would be a 100% reliable way to prevent race conditions (i.e., with multi-touch) and take the place of any kind of debouncing type of code that you might want to prevent users from navigating multiple times
Whether that is a problem for your app or not is up to you - Navigation Compose won't crash or anything if you leave this type of check out entirely
As a general pattern when it comes to analytics for click events, etc., you'd want to check to surround the entire code (not just the call to
navigate()
). Obviously for something like Owl which doesn't track analytics, etc., the approach shown there is enough
👀 1
r
I'm using SingleShotEventBus mechanism to propagate navigation events as
exactly once
from ViewModel and these actions are getting invoked through
LaunchedEffect
snapshotFlow
inside compose. With this approach
lifecycleIsResumed
check required ?
i
Your Compose UI will still receive click events until it is disposed (and, in the Navigation Compose world, the Lifecycle moved to
DESTROYED
), so if you want to only process events when resumed, you'd want to use
repeatOnLifecycle(Lifecycle.State.RESUMED)
inside your
LaunchedEffect
ala https://kotlinlang.slack.com/archives/CJLTWPH7S/p1615397085281600?thread_ts=1615395535.277500&amp;cid=CJLTWPH7S
👍 1
r
Yes i'm using
repeatOnLifecycle
ty
Copy code
val sideEffectFlow = remember(mainSideEffect, lifecycleOwner) {
        mainSideEffect.flowWithLifecycle(lifecycleOwner.lifecycle, Lifecycle.State.RESUMED)
    }
    LaunchedEffect(sideEffectFlow) {
        sideEffectFlow.collect {
            when (it) {
                is Navigate.ChatScreen -> action.navigateChatScreen(it.imageUrl)
            }
        }
    }
i
Then you're good to go, nothing else needed
🙌 1