File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,13 @@ class Presenter: NSObject {
68
68
return duration
69
69
}
70
70
71
+ /// Detects the scenario where the view was shown, but the containing view heirarchy was removed before the view
72
+ /// was hidden. This unusual scenario could result in the message queue being blocked because the presented
73
+ /// view was not properly hidden by SwiftMessages. `isOrphaned` allows the queuing logic to unblock the queue.
74
+ var isOrphaned : Bool {
75
+ return installed && view. window == nil
76
+ }
77
+
71
78
// MARK: - Constants
72
79
73
80
enum PresentationContext {
@@ -97,7 +104,7 @@ class Presenter: NSObject {
97
104
98
105
private weak var delegate : PresenterDelegate ?
99
106
private var presentationContext = PresentationContext . viewController ( Weak < UIViewController > ( value: nil ) )
100
-
107
+ private var installed = false
101
108
private var interactivelyHidden = false ;
102
109
103
110
// MARK: - Showing and hiding
@@ -412,6 +419,7 @@ class Presenter: NSObject {
412
419
maskingView. accessibleElements = elements
413
420
}
414
421
422
+ installed = true
415
423
guard let containerView = presentationContext. viewValue ( ) else { return }
416
424
( presentationContext. viewControllerValue ( ) as? WindowViewController ) ? . install ( )
417
425
installMaskingView ( containerView: containerView)
Original file line number Diff line number Diff line change @@ -586,7 +586,10 @@ open class SwiftMessages {
586
586
fileprivate func enqueue( presenter: Presenter ) {
587
587
if presenter. config. ignoreDuplicates {
588
588
counts [ presenter. id] = ( counts [ presenter. id] ?? 0 ) + 1
589
- if _current? . id == presenter. id && _current? . isHiding == false { return }
589
+ if let _current,
590
+ _current. id == presenter. id,
591
+ !_current. isHiding,
592
+ !_current. isOrphaned { return }
590
593
if queue. filter ( { $0. id == presenter. id } ) . count > 0 { return }
591
594
}
592
595
func doEnqueue( ) {
@@ -606,7 +609,8 @@ open class SwiftMessages {
606
609
}
607
610
608
611
fileprivate func dequeueNext( ) {
609
- guard self . _current == nil , queue. count > 0 else { return }
612
+ guard queue. count > 0 else { return }
613
+ if let _current, !_current. isOrphaned { return }
610
614
let current = queue. removeFirst ( )
611
615
self . _current = current
612
616
// Set `autohideToken` before the animation starts in case
You can’t perform that action at this time.
0 commit comments