Never show more than one toast view

pull/1/head
Michael Kirk 7 years ago
parent 75ead2ac09
commit 06a8bffa66

@ -67,6 +67,8 @@ class ToastView: UIView {
@objc @objc
class ToastController: NSObject, ToastViewDelegate { class ToastController: NSObject, ToastViewDelegate {
static var currentToastController: ToastController?
private let toastView: ToastView private let toastView: ToastView
private var isDismissing: Bool private var isDismissing: Bool
@ -98,6 +100,12 @@ class ToastController: NSObject, ToastViewDelegate {
toastView.autoPinEdge(.bottom, to: .bottom, of: view, withOffset: -inset) toastView.autoPinEdge(.bottom, to: .bottom, of: view, withOffset: -inset)
toastView.autoPinWidthToSuperview(withMargin: 24) toastView.autoPinWidthToSuperview(withMargin: 24)
if let currentToastController = type(of: self).currentToastController {
currentToastController.dismissToastView()
type(of: self).currentToastController = nil
}
type(of: self).currentToastController = self
UIView.animate(withDuration: 0.1) { UIView.animate(withDuration: 0.1) {
self.toastView.alpha = 1 self.toastView.alpha = 1
} }
@ -131,6 +139,11 @@ class ToastController: NSObject, ToastViewDelegate {
return return
} }
isDismissing = true isDismissing = true
if type(of: self).currentToastController == self {
type(of: self).currentToastController = nil
}
UIView.animate(withDuration: 0.1, UIView.animate(withDuration: 0.1,
animations: { animations: {
self.toastView.alpha = 0 self.toastView.alpha = 0

Loading…
Cancel
Save