Closed StefaniOSApps closed 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 βοΈ
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 π¦Έπ»ββοΈ
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.
use example code
use completion method like
swipe the controller down
--> completion() is not called
How to handle
UIAdaptivePresentationControllerDelegate
events?not called...
func presentationControllerDidDismiss(_ presentationController: UIPresentationController)