SvenTiigi / WhatsNewKit

Showcase your awesome new app features πŸ“±
https://sventiigi.github.io/WhatsNewKit/
MIT License
3.92k stars 193 forks source link

Swipe down does not called completion #34

Closed StefaniOSApps closed 4 years ago

StefaniOSApps commented 4 years ago
  1. use example code

  2. use completion method like

    configuration.completionButton = WhatsNewViewController.CompletionButton(
         title: "Continue",
            action: .custom(action: { (controller) in
               controller.dismiss(animated: true) {
                  completion()
               }
            }
         )
      )
  3. swipe the controller down

--> completion() is not called

How to handle UIAdaptivePresentationControllerDelegate events?

whatsNewViewController.navigationController?.presentationController?.delegate = self
whatsNewViewController.presentationController?.delegate = self

not called... func presentationControllerDidDismiss(_ presentationController: UIPresentationController)

SvenTiigi commented 4 years ago

Hey @StefaniOSApps

This is behavior is intended as the action of the completionButton should only be invoked when the user has pressed the button.

When you want to perform any related task, after the WhatsNewViewController has been dismissed for example the User has swiped down the presented WhatsNewViewController with iOS 13 automatic UIModalPresentationStyle, you can pass in a custom implementation of the WhatsNewVersionStore as the WhatsNewViewController will call the func set(version: WhatsNew.Version) API after it has been deallocated.

A reference implementation could look something like this.

struct EventWrappedWhatsNewVersionStore: WhatsNewVersionStore {

    let whatsNewVersionStore: WhatsNewVersionStore

    let onVersionSet: () -> Void

    func set(version: WhatsNew.Version) {
        self.whatsNewVersionStore.set(version: version)
        self.onVersionSet()
    }

    func has(version: WhatsNew.Version) -> Bool {
        self.whatsNewVersionStore.has(version: version)
    }

}

As the WhatsNewViewController is a simple UIViewController subclass (but not wrapped in an UINavigationController) you can make use of the UIAdaptivePresentationControllerDelegate by setting the delegate of the presentationController similar to your example code.

class ViewController: UIViewController {

    func presentWhatsNew() {
        let whatsNewViewController: WhatsNewViewController = ...
        whatsNewViewController.presentationController?.delegate = self
        self.present(whatsNewViewController, animated: true)
    }

}

extension ViewController: UIAdaptivePresentationControllerDelegate {

    func presentationControllerDidDismiss(_ presentationController: UIPresentationController) {
        print(#function)
    }

}

Hope this should resolve your issues ✌️

StefaniOSApps commented 4 years ago

Yes, I use this variant myself now. My wish would be to have a single "completion" method that WhatsNewKit will run when it closes. Also with an enum parameter, which can differentiate between .button and .swipe. Optionally also with close if you have pressed the text above the button. Then another case would be added to the enum. This method would be a bit cleaner than multiple helper classes. What do you think? @SvenTiigi πŸ¦ΈπŸ»β€β™‚οΈ

SvenTiigi commented 4 years ago

Hey @StefaniOSApps,

Thanks for your feedback πŸ‘

I will consider adding such functionality in the next release of WhatsNewKit. Of course feel free to open up a PR to get things started.