Skip to content

Commit

Permalink
Feature Requests from JoniVR
Browse files Browse the repository at this point in the history
  • Loading branch information
Daltron committed May 6, 2017
1 parent f002751 commit 36d4577
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
9 changes: 8 additions & 1 deletion NotificationBanner/Classes/BaseNotificationBanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public class BaseNotificationBanner: UIView {

/// Closure that will be executed if the notification banner is swiped up
public var onSwipeUp: (() -> Void)?

/// Wether or not the notification banner is currently being displayed
public private(set) var isDisplaying: Bool = false

/// The view that the notification layout is presented on. The constraints/frame of this should not be changed
internal var contentView: UIView!
Expand All @@ -56,7 +59,7 @@ public class BaseNotificationBanner: UIView {
var isSuspended: Bool = false

/// Responsible for positioning and auto managing notification banners
private let bannerQueue: NotificationBannerQueue = NotificationBannerQueue.sharedInstance
private let bannerQueue: NotificationBannerQueue = NotificationBannerQueue.default

/// The main window of the application which banner views are placed on
private let APP_WINDOW: UIWindow = UIApplication.shared.delegate!.window!!
Expand Down Expand Up @@ -126,6 +129,7 @@ public class BaseNotificationBanner: UIView {
self.frame = CGRect(x: 0, y: -self.frame.height, width: self.frame.width, height: self.frame.height)
}) { (completed) in
self.removeFromSuperview()
self.isDisplaying = false
self.bannerQueue.showNext(onEmpty: {
self.APP_WINDOW.windowLevel = UIWindowLevelNormal
})
Expand Down Expand Up @@ -157,6 +161,7 @@ public class BaseNotificationBanner: UIView {
UIView.animate(withDuration: 0.5, delay: 0.0, usingSpringWithDamping: 0.7, initialSpringVelocity: 1, options: .curveLinear, animations: {
self.frame = CGRect(x: 0, y: 0, width: self.frame.width, height: self.frame.height)
}) { (completed) in
self.isDisplaying = true
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.onTapGestureRecognizer))
self.addGestureRecognizer(tapGestureRecognizer)

Expand All @@ -174,6 +179,7 @@ public class BaseNotificationBanner: UIView {
func suspend() {
NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(dismiss), object: nil)
isSuspended = true
isDisplaying = false
}

/**
Expand All @@ -182,6 +188,7 @@ public class BaseNotificationBanner: UIView {
func resume() {
self.perform(#selector(dismiss), with: nil, afterDelay: self.duration)
isSuspended = false
isDisplaying = true
}

/**
Expand Down
21 changes: 10 additions & 11 deletions NotificationBanner/Classes/NotificationBannerQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,19 @@ public enum QueuePosition {
case front
}

class NotificationBannerQueue: NSObject {
public class NotificationBannerQueue: NSObject {

private static var sInstance: NotificationBannerQueue?
static var sharedInstance: NotificationBannerQueue {
guard let sInstance = sInstance else {
self.sInstance = NotificationBannerQueue()
return self.sInstance!
}

return sInstance
}

/// The default instance of the NotificationBannerQueue
public static let `default` = NotificationBannerQueue()

/// The notification banners currently placed on the queue
private var banners: [BaseNotificationBanner] = []

/// The current number of notification banners on the queue
public var numberOfBanners: Int {
return banners.count
}

/**
Adds a banner to the queue
-parameter banner: The notification banner to add to the queue
Expand Down

0 comments on commit 36d4577

Please sign in to comment.