Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WorkflowLayout.start needs a Lifecycle, BackStackScreen is supported. #632

Merged
merged 1 commit into from
Jan 31, 2022

Commits on Jan 31, 2022

  1. WorkflowLayout.start needs a Lifecycle, BackStackScreen is supported.

    On a lot of Samsung devices running Anroid 12 / API 30, the sketchy `WorkflowLayout.takeWhileAttached` method at the heart of `WorkflowLayout.start` was having surprising effects -- we'd see redundant calls to `OnAttachStateChangeListener.onViewAttachedToWindow`. The problem goes away if we get more conventional and use the new `repeatOnLifecycle` function as described in [this blog post](https://medium.com/androiddevelopers/a-safer-way-to-collect-flows-from-android-uis-23080b1f8bda).
    
    The old methods are deprecated and will be deleted soon.
    
    Making this change required making our `BackPressHandler` mechanism more robust, as it too was pretending that `OnAttachStateChangeListener` was an adequate lifecycle. Specifically, we were relying on `onViewAttachedToWindow` to be called in a predicable order, which stopped being the case with the move away from `WorkflowLayout.takeWhileAttached`. This PR changes things so that…
    
    - We register handlers immediately, so that we can count on them being stacked in the expected order
    - We lean on `OnAttachStateChangeListener` solely to enable and disable the `BackPressHandler` associated with a view
    - And take advantage of our recently added support for `ViewTreeLifecycleOwner` for clean up
    
    `ModalContainer`'s contribution to coping with the back button also had to be beefed up, for similar reasons. It needs to ensure that back button events are blocked by modal windows, just like any other event, which is tricky with the singleton `OnBackPressedDispatcher` that androidx provides. It does this by putting a no-op handler in place as a backstop for any set by modal renderings. Its bespoke code for doing this was also inadvertently relying on the order of `onViewAttachedToWindow` calls. We now achieve this by wrapping modal renderings with a reliable `BackStackScreen`, which is promoted from the sample container set.
    rjrjr committed Jan 31, 2022
    Configuration menu
    Copy the full SHA
    01eb576 View commit details
    Browse the repository at this point in the history