SwiftKickMobile / SwiftMessages

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

SwiftMessages showed only once when Config.duration = .forever #411

Closed giofid closed 3 years ago

giofid commented 3 years ago

Hi @wtmoose, I try to briefly describe a potential problem found in the library. I have a view controller V1 that presents (modally) a view controller V2, and V2 shows a swifty-message with duration set to .forever. If V2 is dismissed and presented again, when it tries to show again the same swifty-message, nothing appears.

I attach a sample project: SMExample.zip

As a workaround (honestly, it looks like an ugly workaround), I have to call hide(animated:) before to show the swifty-message and I have to call show(config:, view:) into DispatchQueue.main.async.

SwiftMessages.hide(animated: false)
DispatchQueue.main.async {
    SwiftMessages.show(config: config, view: view)
}

I don't know if this problem is related to this one: #328.

wtmoose commented 3 years ago

If you are using the global SwiftMessages instance, your first message will block the queue until you dismiss it. SwiftMessages does not attempt to detect when a message should be dismissed sooner than the timing you specified.

You have a couple of options:

  1. Explicitly dismiss the message when the view controller is being dismissed
  2. Have your view controller create and use a unique instance of SwiftMessages so that the queue is local to the view controller.

Hope that helps.

giofid commented 3 years ago

Ok. I will use option 2. It seems the most clean one.

Thank you Timothy.