SwiftKickMobile / SwiftMessages

A very flexible message bar for UIKit and SwiftUI.
MIT License
7.24k stars 742 forks source link

Message queueing not working #428

Closed graycampbell closed 3 years ago

graycampbell commented 3 years ago

I've created a NotificationManager in my project to present banners at the bottom of the screen as notifications to users. Sometimes notifications occur while a banner is already being shown, so my expectation was that calling SwiftMessages.show would add that banner to the queue to be shown when the currently visible banner is hidden. For some reason, that isn't happening. The currently visible banner disappears as expected, but no new banner is shown. Below is my NotificationManager. Am I missing something, or is this a bug?

import UIKit
import SwiftMessages

class NotificationManager {

    // MARK: Properties

    private lazy var bottomBanners: SwiftMessages = {
        let bottomBanners = SwiftMessages()

        bottomBanners.defaultConfig.ignoreDuplicates = false
        bottomBanners.defaultConfig.presentationStyle = .bottom
        bottomBanners.defaultConfig.presentationContext = .window(windowLevel: .normal)
        bottomBanners.defaultConfig.keyboardTrackingView = KeyboardTrackingView()

        return bottomBanners
    }()
}

// MARK: - Notifications

extension NotificationManager {

    // MARK: Bottom Banners

    func showBottomBanner(_ view: UIView) {
        self.bottomBanners.show(view: view)
    }
}
wtmoose commented 3 years ago

SwiftMessages ignores duplicates by default. So if your messages have the same ID and you haven't set SwiftMessages.Config. ignoreDuplicates = false, then the behavior you see is expected.

The MessageView class determined it's ID as follows:

open var id: String {
    get {
        return customId ?? "MessageView:title=\(String(describing: titleLabel?.text)), body=\(String(describing: bodyLabel?.text))"
    }
    set {
        customId = newValue
    }
}

private var customId: String?

So if you don't specify a customId, then it is derived from the message's title and body.

graycampbell commented 3 years ago

I'm setting ignoresDuplicates to false, and I'm not using MessageView - I'm using a custom UIView that does not conform to Identifiable.

wtmoose commented 3 years ago

Should be fixed in 8.0.3