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

Fix LockViewController dismissal when presented as a popup #647

Merged
merged 6 commits into from
Apr 13, 2021

Conversation

agirault
Copy link
Contributor

@agirault agirault commented Dec 1, 2020

Issues

On iPad, the LockViewController is presented as a .formSheet. As such, it can be dismissed by simply tapping outside the bounds of the modal. In this scenario, there are two issues:

Changes

  • Setting isModalInPresentation based on closable allows controlling whether or not UIKit should prevent the interactive dismissal of the modal
  • Listening to presentationControllerDidDismiss allows us to trigger the cancel callback when the user manually dismissed the modal

Testing

On iPad:

  • with the closable option set to false (or not set, since that's the default), check that the lock modal does not get dismissed when tapping outside its bounds (used to fail before this change)
  • with the closable option set to true, check that the lock modal gets dismissed when tapping outside its bounds and that the onCancel callback is triggered.

Checklist

@agirault agirault requested a review from a team as a code owner December 1, 2020 21:11
@agirault agirault changed the title Fix closable option behavior when Lock is presented as a popup [WIP] Fix closable option behavior when Lock is presented as a popup Dec 1, 2020
agirault and others added 2 commits December 1, 2020 16:36
On iPad, with a presentation style of .formSheet, the LockViewController
could be dismissed by simply tapping outside the bounds of the modal,
without regard for the `closable` [1] option.

Setting `isModalInPresentation` [2] based on `closable` allows controlling
whether or not UIKit should prevent the interactive dismissal of the popup.

[1] https://auth0.com/docs/libraries/lock-swift/lock-swift-configuration-options#closable
[2] https://developer.apple.com/documentation/uikit/uiviewcontroller/3229894-ismodalinpresentation
Call onCancel when the Lock view controller modal is dismissed by the user
(by tapping outside its bounds on iPad).

This is not called when it's dismissed programmatically:
https://developer.apple.com/documentation/uikit/uiadaptivepresentationcontrollerdelegate/3229889-presentationcontrollerdiddismiss
@agirault agirault changed the title [WIP] Fix closable option behavior when Lock is presented as a popup Fix LockViewController behavior when presented as a popup Dec 1, 2020
@agirault agirault changed the title Fix LockViewController behavior when presented as a popup Fix LockViewController dismissal when presented as a popup Dec 1, 2020
@Widcket Widcket added the needs investigation An issue that has more questions to answer or otherwise needs work to fully understand the issue label Dec 4, 2020
@agirault
Copy link
Contributor Author

FYI @Widcket I'm still interested in pursuing this but had some issues running the tests locally. I should be able to spend a bit more time investigating early next year, though I'd appreciate any insight if you found the time to review. Ty!

@Widcket
Copy link
Contributor

Widcket commented Apr 9, 2021

I found out the issue, the delegate needs to be set on viewDidLoad instead of the initializer.

Screen.Recording.2021-04-08.at.21.57.19.mov

@cocojoe please review, as I made and pushed that change.

@@ -138,6 +137,7 @@ public class LockViewController: UIViewController {
center.addObserver(self, selector: #selector(keyboardWasShown), name: UIResponder.responderKeyboardWillShowNotification, object: nil)
center.addObserver(self, selector: #selector(keyboardWasHidden), name: UIResponder.responderKeyboardWillHideNotification, object: nil)

self.presentationController?.delegate = self
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't get why it had to be in viewDidLoad instead of init: could you explain?

@Widcket Widcket merged commit 5a7499e into auth0:master Apr 13, 2021
@Widcket Widcket added CH: Fixed bug This points to a verified bug in the code and removed needs investigation An issue that has more questions to answer or otherwise needs work to fully understand the issue labels Apr 14, 2021
@Widcket Widcket added this to the vNext milestone Apr 14, 2021
@Widcket Widcket mentioned this pull request Apr 14, 2021
@agirault agirault deleted the patch-1 branch April 14, 2021 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This points to a verified bug in the code CH: Fixed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants