Orderella / PopupDialog

A simple, customizable popup dialog for iOS written in Swift. Replaces UIAlertController alert style.
http://www.mwfire.de
Other
3.96k stars 522 forks source link

How to catch gesture dismissal without deiniting the popup? #292

Closed ghost closed 6 years ago

ghost commented 6 years ago

Report

Environment

Please provide information on your development environment, so we can build with the same scenario.

Dependency management

If you are not using any dependency managers, you can remove this section.

What did you do?

I am showing a popup dialog box using the following code

popupDialog = PopupDialog(viewController: newController) {
    print("dialog was dismissed")
}

currentViewController.present(popupDialog!, animated: true, completion: nil)

The dialog box is shown as expected.

If I click on the background, the dialog box disappears as expected.

What did you expect to happen?

After I click on the background, the dialog box disappears as expected. Since I have provided the completion parameter, I expected that the completion handler will be executed and dialog was dimissed will be printed to console

What happened instead?

The completion handler is not executed.

Additional Information

According to this PR, completion handler is executed when popup is deinited.

The readme says This completion handler is called when the dialog was dismissed. This is especially useful for catching a gesture dismissal

Is there any way to catch a gesture dismissal without deiniting the popup

mwfire commented 6 years ago

Hey there! The completion is indeed called whenever the dialog is dismissed. As the handler is called on deinit, my guess is that deinit is not called. This can be caused by a retain cycle. Do you have a small example project I can check out?

Thanks!

ghost commented 6 years ago

Reference to the popup dialog was stored in a variable due to which the popup dialog did not get deinited and handler did not get called.

After making the reference weak, the handler gets called.