diff --git a/CHANGELOG.md b/CHANGELOG.md index de1f84a..8c25038 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ # Change Log All notable changes to this project will be documented in this file. +## 9.0.6 + +### Features + +* Add `UIView` associated type to `Event`, e.g. `willShow(UIView)` so that event listeners can inspect the view. +* Add `Event.id: String?` property so that event listeners can reason about the view's ID. + ## 9.0.5 ### Fixes diff --git a/README.md b/README.md index c46c84c..97e8374 100644 --- a/README.md +++ b/README.md @@ -156,7 +156,9 @@ config.preferredStatusBarStyle = .lightContent // Specify one or more event listeners to respond to show and hide events. config.eventListeners.append() { event in - if case .didHide = event { print("yep") } + if case .didHide = event { + print("yep id=\(String(describing: event.id)") + } } SwiftMessages.show(config: config, view: view) diff --git a/SwiftMessages.podspec b/SwiftMessages.podspec index c43a529..4c7b945 100644 --- a/SwiftMessages.podspec +++ b/SwiftMessages.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = 'SwiftMessages' - spec.version = '9.0.5' + spec.version = '9.0.6' spec.license = { :type => 'MIT' } spec.homepage = 'https://github.com/SwiftKickMobile/SwiftMessages' spec.authors = { 'Timothy Moose' => 'tim@swiftkick.it' } diff --git a/SwiftMessages/Presenter.swift b/SwiftMessages/Presenter.swift index 11243f5..be093be 100644 --- a/SwiftMessages/Presenter.swift +++ b/SwiftMessages/Presenter.swift @@ -119,7 +119,7 @@ class Presenter: NSObject { func show(completion: @escaping AnimationCompletion) throws { try presentationContext = getPresentationContext() install() - self.config.eventListeners.forEach { $0(.willShow) } + self.config.eventListeners.forEach { $0(.willShow(self.view)) } showAnimation() { completed in completion(completed) if completed { @@ -128,7 +128,7 @@ class Presenter: NSObject { } else { self.showAccessibilityAnnouncement() } - self.config.eventListeners.forEach { $0(.didShow) } + self.config.eventListeners.forEach { $0(.didShow(self.view)) } } } } @@ -181,7 +181,7 @@ class Presenter: NSObject { func hide(animated: Bool, completion: @escaping AnimationCompletion) { isHiding = true - self.config.eventListeners.forEach { $0(.willHide) } + self.config.eventListeners.forEach { $0(.willHide(self.view)) } let context = animationContext() let action = { if let viewController = self.presentationContext.viewControllerValue() as? WindowViewController { @@ -189,7 +189,7 @@ class Presenter: NSObject { } self.maskingView.removeFromSuperview() completion(true) - self.config.eventListeners.forEach { $0(.didHide) } + self.config.eventListeners.forEach { $0(.didHide(self.view)) } } guard animated else { action() diff --git a/SwiftMessages/SwiftMessages.swift b/SwiftMessages/SwiftMessages.swift index 7c0042f..5e9f0c3 100644 --- a/SwiftMessages/SwiftMessages.swift +++ b/SwiftMessages/SwiftMessages.swift @@ -219,10 +219,23 @@ open class SwiftMessages { Specifies events in the message lifecycle. */ public enum Event { - case willShow - case didShow - case willHide - case didHide + case willShow(UIView) + case didShow(UIView) + case willHide(UIView) + case didHide(UIView) + + public var view: UIView { + switch self { + case .willShow(let view): return view + case .didShow(let view): return view + case .willHide(let view): return view + case .didHide(let view): return view + } + } + + public var id: String? { + return (view as? Identifiable)?.id + } } /**