Ravi

    Ravi

    1 year ago
    In owl compose sample,
    lifecycleIsResumed
    check is added to discard duplicated navigation events. Is this change required as I've followed similar pattern?
    i

    Ian Lake

    1 year ago
    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
    Ravi

    Ravi

    1 year ago
    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

    Ian Lake

    1 year ago
    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&cid=CJLTWPH7S
    Ravi

    Ravi

    1 year ago
    Yes i'm using
    repeatOnLifecycle
    ty
    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

    Ian Lake

    1 year ago
    Then you're good to go, nothing else needed