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

Completion handler being called immediately... #18

Open
wdcurry opened this issue Jan 17, 2019 · 5 comments
Open

Completion handler being called immediately... #18

wdcurry opened this issue Jan 17, 2019 · 5 comments

Comments

@wdcurry
Copy link

wdcurry commented Jan 17, 2019

You can see this in the demo, by breaking any of the completion handlers and running the example. You can seem them called immediately, which great negates the ease-of-use factor if collecting info.

@wdcurry
Copy link
Author

wdcurry commented Jan 17, 2019

it would seem i misunderstood the "completion" portion of the signature, and was thinking async. It really should be renamed "didAppear" as it surely isn't a completed showing of a popup. I know this is not the repo's issue, but a swift thing.

@Kofktu
Copy link
Owner

Kofktu commented Jan 18, 2019

@wdcurry
When calling the UIViewController's presenter, pass completion to the parameter.
It's the same as the iOS system.

@wdcurry
Copy link
Author

wdcurry commented Jan 18, 2019

I don’t think you understood my point and follow up. I was expecting the completion to act as the completion of the presention, ie when the pop up was finished, not to when it was completed in instantion and now showing. In the context of passing control to a pseudo-modal view, the current logic from Apple is incorrect. The completion should run when the pop up disappears.

@cozzin
Copy link
Contributor

cozzin commented Jan 29, 2019

@wdcurry Hello, I think we have different point of view.
In UIKit, The completion closure of the present function is called when the present animation ends. In the same way, the dismiss function also calls the completion closure when the dismiss animation finishes.

https://developer.apple.com/documentation/uikit/uiviewcontroller/1621380-present

func present(_ viewControllerToPresent: UIViewController, 
    animated flag: Bool, 
  completion: (() -> Void)? = nil)

completion
The block to execute after the presentation finishes. This block has no return value and takes no parameters. You may specify nil for this parameter.

https://developer.apple.com/documentation/uikit/uiviewcontroller/1621505-dismiss

func dismiss(animated flag: Bool, 
  completion: (() -> Void)? = nil)

completion
The block to execute after the view controller is dismissed. This block has no return value and takes no parameters. You may specify nil for this parameter.

Therefore, If you want to run the closure after the pop up disappears on screen, you can use

public func dismissPopover(animated: Bool, completion: DismissPopoverCompletion?)

@wdcurry
Copy link
Author

wdcurry commented Jan 29, 2019

Thank you for taking the time to explain that so well. This is/was my first foray into the popOver, and indeed my wires were crossed. I had already gone old-school with an unwind as i usually do, but will convert to the block passing as time permits, thanks!

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

No branches or pull requests

3 participants