Skip to content

Conversation

@rjrjr
Copy link
Collaborator

@rjrjr rjrjr commented Jul 27, 2022

OverlayDialogHolder now can provide an onBackPressed: () -> Unit function to be called in place of Dialog.onBackPressed, and we provide a default implementation that hooks in OnBackPressedDispatcher. This works for all kinds of dialogs, not just modal ones, and replaces ModalScreenOverlayBackButtonHelper. The other method that was on ModalScreenOverlayBackButtonHelper, which put the no-op backPressedHandler on the content view to ensure those on layer layers would not fire, is now built into the default implementation of ScreenOverlayDialogFactory.buildDialogWithContent, which is designed to be customized anyway.

Also locks down AlertOverlayDialogFactory, but moves all the interesting parts into a public function. Should be easier and safer for re-use.

So how is this simpler? Or at least less complex?

The old scheme had:

  • a strategy object in the ViewEnvironment, ModalScreenOverlayBackButtonHelper, that was providing a one-size-fits-all-dialogs scheme for back button handling
  • that scheme was only used by the ScreenViewOverlay subtype, not for Overlay in general
  • and it was applied only for modals, which was very wrong

With this change:

  • The individual OverlayDialogHolder that wraps a Dialog is directly responsible for defining its back button behavior, and can be changed from the default behavior directly by the feature developer
  • The bizarre subtle onBackPressed = {} hack is moved to the factory class responsible for building the dialog, again in a spot that is naturally open for customization
  • and we eliminate the boolean return value, meaning one less decision point for developers

@rjrjr rjrjr force-pushed the ray/back-button-always-the-back-button-what-a-terrible-idea-the-back-button-was branch 2 times, most recently from 9b676fb to 7ad3116 Compare July 27, 2022 23:52
@rjrjr rjrjr changed the title wip: simpler / completer back button handling Simpler, better back button handling. Jul 27, 2022
@rjrjr rjrjr force-pushed the ray/back-button-always-the-back-button-what-a-terrible-idea-the-back-button-was branch from 7ad3116 to b5b1f00 Compare July 27, 2022 23:59
@rjrjr rjrjr force-pushed the ray/better-bounds branch from f96fb8e to 6d88a6a Compare July 28, 2022 04:19
@rjrjr rjrjr force-pushed the ray/back-button-always-the-back-button-what-a-terrible-idea-the-back-button-was branch from b5b1f00 to 76422f5 Compare July 28, 2022 04:19
@rjrjr rjrjr marked this pull request as ready for review July 28, 2022 04:23
@rjrjr rjrjr requested review from a team and zach-klippenstein as code owners July 28, 2022 04:23
Base automatically changed from ray/better-bounds to main July 28, 2022 15:43
@rjrjr rjrjr force-pushed the ray/back-button-always-the-back-button-what-a-terrible-idea-the-back-button-was branch from 76422f5 to 3c394cf Compare July 28, 2022 15:43
Copy link
Contributor

@steve-the-edwards steve-the-edwards left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I've gotten to coming around to how this is simpler, but I trust you and I think I need to do a more systematic learning of the modal/dialog/overlay handling anyway.

I do have a few questions about this particular PR though - noted in comments.

* [OverlayDialogFactory]. The default implementation makes [AndroidOverlay]
* work, and provides default bindings for [AlertOverlay] and [FullScreenOverlay].
*
* Here is how this hook could be used to provide a custom dialog to handle [FullScreenOverlay]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example is no longer applicable because of back press handling?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was already inaccurate, and I'm kind of exhausted, TBH.

@rjrjr
Copy link
Collaborator Author

rjrjr commented Jul 28, 2022

I'm not sure I've gotten to coming around to how this is simpler

Less complex, anyway.

The old scheme had a strategy object in the ViewEnvironment that was providing a one-size-fits-all-dialogs scheme for back button handling, and that scheme was only used by the ScreenViewOverlay subtype, not for Overlay in general. It also was applied only for modals, which was just wrong.

With this change, the OverlayDialogHolder that wraps the Dialog is directly responsible for defining its back button behavior; the bizarre subtle onBackPressed = {} hack is moved to the factory class responsible for building the dialog, again in a spot that is naturally open for customization; and we eliminate the boolean return value, meaning one less decision point for developers.

I'll add this to the commit message.

@rjrjr rjrjr force-pushed the ray/back-button-always-the-back-button-what-a-terrible-idea-the-back-button-was branch from 3c394cf to 2120968 Compare July 28, 2022 21:48
`OverlayDialogHolder` now can provide an `onBackPressed: () -> Unit` function to be called in place of `Dialog.onBackPressed`, and we provide a default implementation that hooks in `OnBackPressedDispatcher`. This works for all kinds of dialogs, not just modal ones, and replaces `ModalScreenOverlayBackButtonHelper`. The other method that was on `ModalScreenOverlayBackButtonHelper`, which put the no-op `backPressedHandler` on the content view to ensure those on layer layers would not fire, is now built into the default implementation of `ScreenOverlayDialogFactory.buildDialogWithContent`, which is designed to be customized anyway.

Also locks down `AlertOverlayDialogFactory`, but moves all the interesting parts into a public function. Should be easier and safer for re-use.

So how is this simpler? Or at least less complex?

The old scheme had:

- a strategy object in the `ViewEnvironment`, `ModalScreenOverlayBackButtonHelper`, that was providing a one-size-fits-all-dialogs scheme for back button handling
- that scheme was only used by the `ScreenViewOverlay` subtype, not for `Overlay` in general
- and it was applied only for modals, which was very wrong

With this change:

- The individual `OverlayDialogHolder` that wraps a `Dialog` is directly responsible for defining its back button behavior, and can be changed from the default behavior directly by the feature developer
- The bizarre subtle `onBackPressed = {}` hack is moved to the factory class responsible for building the dialog, again in a spot that is naturally open for customization
- and we eliminate the boolean return value, meaning one less decision point for developers
@rjrjr rjrjr force-pushed the ray/back-button-always-the-back-button-what-a-terrible-idea-the-back-button-was branch from 2120968 to ba43dab Compare July 28, 2022 21:48
@rjrjr rjrjr merged commit 8d94f6f into main Jul 28, 2022
@rjrjr rjrjr deleted the ray/back-button-always-the-back-button-what-a-terrible-idea-the-back-button-was branch July 28, 2022 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants