Skip to content

Commit b29dd21

Browse files
committed
Add view associated type to Event
1 parent 1e49de7 commit b29dd21

File tree

5 files changed

+32
-10
lines changed

5 files changed

+32
-10
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
## 9.0.6
5+
6+
### Features
7+
8+
* Add `UIView` associated type to `Event`, e.g. `willShow(UIView)` so that event listeners can inspect the view.
9+
* Add `Event.id: String?` property so that event listeners can reason about the view's ID.
10+
411
## 9.0.5
512

613
### Fixes

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ config.preferredStatusBarStyle = .lightContent
156156

157157
// Specify one or more event listeners to respond to show and hide events.
158158
config.eventListeners.append() { event in
159-
if case .didHide = event { print("yep") }
159+
if case .didHide = event {
160+
print("yep id=\(String(describing: event.id)")
161+
}
160162
}
161163
162164
SwiftMessages.show(config: config, view: view)

SwiftMessages.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |spec|
22
spec.name = 'SwiftMessages'
3-
spec.version = '9.0.5'
3+
spec.version = '9.0.6'
44
spec.license = { :type => 'MIT' }
55
spec.homepage = 'https://github.com/SwiftKickMobile/SwiftMessages'
66
spec.authors = { 'Timothy Moose' => 'tim@swiftkick.it' }

SwiftMessages/Presenter.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class Presenter: NSObject {
119119
func show(completion: @escaping AnimationCompletion) throws {
120120
try presentationContext = getPresentationContext()
121121
install()
122-
self.config.eventListeners.forEach { $0(.willShow) }
122+
self.config.eventListeners.forEach { $0(.willShow(self.view)) }
123123
showAnimation() { completed in
124124
completion(completed)
125125
if completed {
@@ -128,7 +128,7 @@ class Presenter: NSObject {
128128
} else {
129129
self.showAccessibilityAnnouncement()
130130
}
131-
self.config.eventListeners.forEach { $0(.didShow) }
131+
self.config.eventListeners.forEach { $0(.didShow(self.view)) }
132132
}
133133
}
134134
}
@@ -181,15 +181,15 @@ class Presenter: NSObject {
181181

182182
func hide(animated: Bool, completion: @escaping AnimationCompletion) {
183183
isHiding = true
184-
self.config.eventListeners.forEach { $0(.willHide) }
184+
self.config.eventListeners.forEach { $0(.willHide(self.view)) }
185185
let context = animationContext()
186186
let action = {
187187
if let viewController = self.presentationContext.viewControllerValue() as? WindowViewController {
188188
viewController.uninstall()
189189
}
190190
self.maskingView.removeFromSuperview()
191191
completion(true)
192-
self.config.eventListeners.forEach { $0(.didHide) }
192+
self.config.eventListeners.forEach { $0(.didHide(self.view)) }
193193
}
194194
guard animated else {
195195
action()

SwiftMessages/SwiftMessages.swift

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,23 @@ open class SwiftMessages {
219219
Specifies events in the message lifecycle.
220220
*/
221221
public enum Event {
222-
case willShow
223-
case didShow
224-
case willHide
225-
case didHide
222+
case willShow(UIView)
223+
case didShow(UIView)
224+
case willHide(UIView)
225+
case didHide(UIView)
226+
227+
public var view: UIView {
228+
switch self {
229+
case .willShow(let view): return view
230+
case .didShow(let view): return view
231+
case .willHide(let view): return view
232+
case .didHide(let view): return view
233+
}
234+
}
235+
236+
public var id: String? {
237+
return (view as? Identifiable)?.id
238+
}
226239
}
227240

228241
/**

0 commit comments

Comments
 (0)