Skip to content

Commit f058d56

Browse files
committed
use both presenting & sender parameters
1 parent 5f9ed1a commit f058d56

File tree

1 file changed

+38
-14
lines changed

1 file changed

+38
-14
lines changed

Source/SwiftEntryKit.swift

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import UIKit
1010
public protocol SwiftEntryPresenting: NSObject {
1111
func isCurrentlyDisplaying() -> Bool
1212
func isCurrentlyDisplaying(entryNamed name: String?) -> Bool
13-
func display(entry view: UIView, using attributes: EKAttributes)
14-
func display(entry viewController: UIViewController, using attributes: EKAttributes)
13+
func display(sender: UIViewController?, entry view: UIView, using attributes: EKAttributes)
14+
func display(sender: UIViewController?, entry viewController: UIViewController, using attributes: EKAttributes)
1515
func dismiss(_ descriptor: SwiftEntryKit.EntryDismissalDescriptor, with completion: SwiftEntryKit.DismissCompletionHandler?)
1616
func queueContains(entryNamed name: String?) -> Bool
1717
}
@@ -34,6 +34,7 @@ extension UIViewController {
3434

3535
static var ViewControllerProviderKey = UnsafeRawPointer(bitPattern: "viewControllerProvider".hashValue)!
3636
static var EntryPresentingKey = UnsafeRawPointer(bitPattern: "EntryPresentingKey".hashValue)!
37+
static var EntrySenderKey = UnsafeRawPointer(bitPattern: "EntrySenderKey".hashValue)!
3738

3839
var entryProvider: EKViewControllerProvider? {
3940
get {
@@ -53,6 +54,15 @@ extension UIViewController {
5354
}
5455
}
5556

57+
public var entrySender: UIViewController? {
58+
get {
59+
return objc_getAssociatedWeakObject(self, UIViewController.EntrySenderKey) as? UIViewController
60+
}
61+
set {
62+
objc_setAssociatedWeakObject(self, UIViewController.EntrySenderKey, newValue)
63+
}
64+
}
65+
5666
public var entryViewController: UIViewController? {
5767
return entryProvider?.entryViewController
5868
}
@@ -62,6 +72,7 @@ extension UIViewController {
6272
extension UIView {
6373

6474
static var EntryPresentingKey = UnsafeRawPointer(bitPattern: "EntryPresentingKey".hashValue)!
75+
static var EntrySenderKey = UnsafeRawPointer(bitPattern: "EntrySenderKey".hashValue)!
6576

6677
public var entryPresenting: SwiftEntryPresenting? {
6778
get {
@@ -72,6 +83,15 @@ extension UIView {
7283
}
7384
}
7485

86+
public var entrySender: UIViewController? {
87+
get {
88+
return objc_getAssociatedWeakObject(self, UIViewController.EntrySenderKey) as? UIViewController
89+
}
90+
set {
91+
objc_setAssociatedWeakObject(self, UIViewController.EntrySenderKey, newValue)
92+
}
93+
}
94+
7595
}
7696

7797
extension UIApplication: SwiftEntryPresenting {
@@ -84,12 +104,12 @@ extension UIApplication: SwiftEntryPresenting {
84104
return SwiftEntryKit.isCurrentlyDisplaying(entryNamed: name)
85105
}
86106

87-
public func display(entry view: UIView, using attributes: EKAttributes) {
88-
SwiftEntryKit.display(entry: view, using: attributes)
107+
public func display(sender: UIViewController? = nil, entry view: UIView, using attributes: EKAttributes) {
108+
SwiftEntryKit.display(sender: sender, entry: view, using: attributes)
89109
}
90110

91-
public func display(entry viewController: UIViewController, using attributes: EKAttributes) {
92-
SwiftEntryKit.display(entry: viewController, using: attributes)
111+
public func display(sender: UIViewController? = nil, entry viewController: UIViewController, using attributes: EKAttributes) {
112+
SwiftEntryKit.display(sender: sender, entry: viewController, using: attributes)
93113
}
94114

95115
public func dismiss(_ descriptor: SwiftEntryKit.EntryDismissalDescriptor = .displayed, with completion: SwiftEntryKit.DismissCompletionHandler? = nil) {
@@ -112,12 +132,12 @@ extension UIViewController: SwiftEntryPresenting {
112132
return SwiftEntryKit.isCurrentlyDisplaying(self, entryNamed: name)
113133
}
114134

115-
public func display(entry view: UIView, using attributes: EKAttributes) {
116-
SwiftEntryKit.display(self, entry: view, using: attributes)
135+
public func display(sender: UIViewController? = nil, entry view: UIView, using attributes: EKAttributes) {
136+
SwiftEntryKit.display(self, sender: sender, entry: view, using: attributes)
117137
}
118138

119-
public func display(entry viewController: UIViewController, using attributes: EKAttributes) {
120-
SwiftEntryKit.display(self, entry: viewController, using: attributes)
139+
public func display(sender: UIViewController? = nil, entry viewController: UIViewController, using attributes: EKAttributes) {
140+
SwiftEntryKit.display(self, sender: sender, entry: viewController, using: attributes)
121141
}
122142

123143
public func dismiss(_ descriptor: SwiftEntryKit.EntryDismissalDescriptor = .displayed, with completion: SwiftEntryKit.DismissCompletionHandler? = nil) {
@@ -216,12 +236,13 @@ extension SwiftEntryKit {
216236
- parameter view: Custom view that is to be displayed
217237
- parameter attributes: Display properties
218238
*/
219-
public class func display(_ presenting: UIViewController, entry view: UIView, using attributes: EKAttributes) {
239+
public class func display(_ presenting: UIViewController, sender: UIViewController? = nil, entry view: UIView, using attributes: EKAttributes) {
220240
DispatchQueue.main.async {
221241
if presenting.entryProvider == nil {
222242
presenting.entryProvider = EKViewControllerProvider(with: presenting)
223243
}
224244
view.entryPresenting = presenting
245+
view.entrySender = sender
225246
presenting.entryProvider?.display(view: view, using: attributes)
226247
}
227248
}
@@ -234,12 +255,13 @@ extension SwiftEntryKit {
234255
- parameter view: Custom view that is to be displayed
235256
- parameter attributes: Display properties
236257
*/
237-
public class func display(_ presenting: UIViewController, entry viewController: UIViewController, using attributes: EKAttributes) {
258+
public class func display(_ presenting: UIViewController, sender: UIViewController? = nil, entry viewController: UIViewController, using attributes: EKAttributes) {
238259
DispatchQueue.main.async {
239260
if presenting.entryProvider == nil {
240261
presenting.entryProvider = EKViewControllerProvider(with: presenting)
241262
}
242263
viewController.entryPresenting = presenting
264+
viewController.entrySender = sender
243265
presenting.entryProvider?.display(viewController: viewController, using: attributes)
244266
}
245267
}
@@ -337,9 +359,10 @@ extension SwiftEntryKit {
337359
- parameter presentInsideKeyWindow: Indicates whether the entry window should become the key window.
338360
- parameter rollbackWindow: After the entry has been dismissed, SwiftEntryKit rolls back to the given window. By default it is *.main* which is the app main window
339361
*/
340-
public class func display(entry view: UIView, using attributes: EKAttributes, presentInsideKeyWindow: Bool = false, rollbackWindow: RollbackWindow = .main) {
362+
public class func display(sender: UIViewController? = nil, entry view: UIView, using attributes: EKAttributes, presentInsideKeyWindow: Bool = false, rollbackWindow: RollbackWindow = .main) {
341363
DispatchQueue.main.async {
342364
view.entryPresenting = UIApplication.shared
365+
view.entrySender = sender
343366
EKWindowProvider.shared.display(view: view, using: attributes, presentInsideKeyWindow: presentInsideKeyWindow, rollbackWindow: rollbackWindow)
344367
}
345368
}
@@ -353,9 +376,10 @@ extension SwiftEntryKit {
353376
- parameter presentInsideKeyWindow: Indicates whether the entry window should become the key window.
354377
- parameter rollbackWindow: After the entry has been dismissed, SwiftEntryKit rolls back to the given window. By default it is *.main* - which is the app main window
355378
*/
356-
public class func display(entry viewController: UIViewController, using attributes: EKAttributes, presentInsideKeyWindow: Bool = false, rollbackWindow: RollbackWindow = .main) {
379+
public class func display(sender: UIViewController? = nil, entry viewController: UIViewController, using attributes: EKAttributes, presentInsideKeyWindow: Bool = false, rollbackWindow: RollbackWindow = .main) {
357380
DispatchQueue.main.async {
358381
viewController.entryPresenting = UIApplication.shared
382+
viewController.entrySender = sender
359383
EKWindowProvider.shared.display(viewController: viewController, using: attributes, presentInsideKeyWindow: presentInsideKeyWindow, rollbackWindow: rollbackWindow)
360384
}
361385
}

0 commit comments

Comments
 (0)