Skip to content

Commit 5500236

Browse files
SwiftMessages.Config expands the popupPriority property to support the popup queue to accurately control the display order according to the weight (SwiftKickMobile#555)
1 parent b3bccca commit 5500236

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

SwiftMessages/Presenter.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ protocol PresenterDelegate: AnimationDelegate {
1515

1616
@MainActor
1717
class Presenter: NSObject {
18-
18+
1919
// MARK: - API
2020

2121
init(config: SwiftMessages.Config, view: UIView, delegate: PresenterDelegate) {

SwiftMessages/SwiftMessages.swift

+16
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,11 @@ open class SwiftMessages {
393393
Supply an instance of `KeyboardTrackingView` to have the message view avoid the keyboard.
394394
*/
395395
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
396401
}
397402

398403
/**
@@ -612,6 +617,17 @@ open class SwiftMessages {
612617
fileprivate func dequeueNext() {
613618
guard queue.count > 0 else { return }
614619
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 }
615631
let current = queue.removeFirst()
616632
self._current = current
617633
// Set `autohideToken` before the animation starts in case

0 commit comments

Comments
 (0)