File tree 2 files changed +17
-1
lines changed
2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ protocol PresenterDelegate: AnimationDelegate {
15
15
16
16
@MainActor
17
17
class Presenter : NSObject {
18
-
18
+
19
19
// MARK: - API
20
20
21
21
init ( config: SwiftMessages . Config , view: UIView , delegate: PresenterDelegate ) {
Original file line number Diff line number Diff line change @@ -393,6 +393,11 @@ open class SwiftMessages {
393
393
Supply an instance of `KeyboardTrackingView` to have the message view avoid the keyboard.
394
394
*/
395
395
public var keyboardTrackingView : KeyboardTrackingView ?
396
+
397
+ /**
398
+ Specify a positive or negative priority to influence the position of a message in the queue based on it's relative priority.
399
+ */
400
+ public var priority : Int = 0
396
401
}
397
402
398
403
/**
@@ -612,6 +617,17 @@ open class SwiftMessages {
612
617
fileprivate func dequeueNext( ) {
613
618
guard queue. count > 0 else { return }
614
619
if let _current, !_current. isOrphaned { return }
620
+ // Sort by priority
621
+ queue = queue. enumerated ( ) . sorted { left, right in
622
+ // The priority is sorted first
623
+ let leftPriority = left. element. config. priority
624
+ let rightPriority = right. element. config. priority
625
+ if leftPriority != rightPriority {
626
+ return leftPriority > rightPriority
627
+ }
628
+ // The same priority is sorted in queue order
629
+ return left. offset < right. offset
630
+ } . map { $0. element }
615
631
let current = queue. removeFirst ( )
616
632
self . _current = current
617
633
// Set `autohideToken` before the animation starts in case
You can’t perform that action at this time.
0 commit comments