Kofktu / KUIPopOver

Easy to use PopOver in iOS
MIT License
583 stars 37 forks source link

Completion handler being called immediately... #18

Open wdcurry opened 5 years ago

wdcurry commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

wdcurry commented 5 years ago

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 commented 5 years ago

@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 commented 5 years ago

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!