@@ -405,7 +405,7 @@ open class SwiftMessages {
405
405
*/
406
406
open func hide( id: String ) {
407
407
messageQueue. sync {
408
- if id == current ? . id {
408
+ if id == _current ? . id {
409
409
hideCurrent ( )
410
410
}
411
411
queue = queue. filter { $0. id != id }
@@ -429,7 +429,7 @@ open class SwiftMessages {
429
429
return
430
430
}
431
431
}
432
- if id == current ? . id {
432
+ if id == _current ? . id {
433
433
hideCurrent ( )
434
434
}
435
435
queue = queue. filter { $0. id != id }
@@ -486,7 +486,7 @@ open class SwiftMessages {
486
486
fileprivate var queue : [ Presenter ] = [ ]
487
487
fileprivate var delays = Delays ( )
488
488
fileprivate var counts : [ String : Int ] = [ : ]
489
- fileprivate var current : Presenter ? = nil {
489
+ fileprivate var _current : Presenter ? = nil {
490
490
didSet {
491
491
if oldValue != nil {
492
492
let delayTime = DispatchTime . now ( ) + pauseBetweenMessages
@@ -500,7 +500,7 @@ open class SwiftMessages {
500
500
fileprivate func enqueue( presenter: Presenter ) {
501
501
if presenter. config. ignoreDuplicates {
502
502
counts [ presenter. id] = ( counts [ presenter. id] ?? 0 ) + 1
503
- if current ? . id == presenter. id && current ? . isHiding == false { return }
503
+ if _current ? . id == presenter. id && _current ? . isHiding == false { return }
504
504
if queue. filter ( { $0. id == presenter. id } ) . count > 0 { return }
505
505
}
506
506
func doEnqueue( ) {
@@ -520,9 +520,9 @@ open class SwiftMessages {
520
520
}
521
521
522
522
fileprivate func dequeueNext( ) {
523
- guard self . current == nil , queue. count > 0 else { return }
523
+ guard self . _current == nil , queue. count > 0 else { return }
524
524
let current = queue. removeFirst ( )
525
- self . current = current
525
+ self . _current = current
526
526
// Set `autohideToken` before the animation starts in case
527
527
// the dismiss gesture begins before we've queued the autohide
528
528
// block on animation completion.
@@ -545,31 +545,31 @@ open class SwiftMessages {
545
545
}
546
546
} catch {
547
547
strongSelf. messageQueue. sync {
548
- strongSelf. current = nil
548
+ strongSelf. _current = nil
549
549
}
550
550
}
551
551
}
552
552
}
553
553
554
554
fileprivate func internalHide( id: String ) {
555
- if id == current ? . id {
555
+ if id == _current ? . id {
556
556
hideCurrent ( )
557
557
}
558
558
queue = queue. filter { $0. id != id }
559
559
delays. ids. remove ( id)
560
560
}
561
561
562
562
fileprivate func hideCurrent( ) {
563
- guard let current = current , !current. isHiding else { return }
563
+ guard let current = _current , !current. isHiding else { return }
564
564
let delay = current. delayHide ?? 0
565
565
DispatchQueue . main. asyncAfter ( deadline: . now( ) + delay) { [ weak self, weak current] in
566
566
guard let strongCurrent = current else { return }
567
567
strongCurrent. hide { ( completed) in
568
568
guard completed, let strongSelf = self , let strongCurrent = current else { return }
569
569
strongSelf. messageQueue. sync {
570
- guard strongSelf. current === strongCurrent else { return }
570
+ guard strongSelf. _current === strongCurrent else { return }
571
571
strongSelf. counts [ strongCurrent. id] = nil
572
- strongSelf. current = nil
572
+ strongSelf. _current = nil
573
573
}
574
574
}
575
575
}
@@ -578,7 +578,7 @@ open class SwiftMessages {
578
578
fileprivate weak var autohideToken : AnyObject ?
579
579
580
580
fileprivate func queueAutoHide( ) {
581
- guard let current = current else { return }
581
+ guard let current = _current else { return }
582
582
autohideToken = current
583
583
if let pauseDuration = current. pauseDuration {
584
584
let delayTime = DispatchTime . now ( ) + pauseDuration
@@ -598,6 +598,19 @@ open class SwiftMessages {
598
598
599
599
extension SwiftMessages {
600
600
601
+ /**
602
+ Returns the message view of type `T` if it is currently being shown or hidden.
603
+
604
+ - Returns: The view of type `T` if it is currently being shown or hidden.
605
+ */
606
+ public func current< T: UIView > ( ) -> T ? {
607
+ var view : T ?
608
+ messageQueue. sync {
609
+ view = _current? . view as? T
610
+ }
611
+ return view
612
+ }
613
+
601
614
/**
602
615
Returns a message view with the given `id` if it is currently being shown or hidden.
603
616
@@ -607,7 +620,7 @@ extension SwiftMessages {
607
620
public func current< T: UIView > ( id: String ) -> T ? {
608
621
var view : T ?
609
622
messageQueue. sync {
610
- if let current = current , current. id == id {
623
+ if let current = _current , current. id == id {
611
624
view = current. view as? T
612
625
}
613
626
}
@@ -670,7 +683,7 @@ extension SwiftMessages: PresenterDelegate {
670
683
}
671
684
672
685
private func presenter( forAnimator animator: Animator ) -> Presenter ? {
673
- if let current = current , animator === current. animator {
686
+ if let current = _current , animator === current. animator {
674
687
return current
675
688
}
676
689
let queued = queue. filter { $0. animator === animator }
0 commit comments