From ea6ea1fbad679f2eb817c30d73cab22ac54c92d2 Mon Sep 17 00:00:00 2001 From: Dalton Date: Tue, 19 Sep 2017 12:45:14 -0500 Subject: [PATCH] iPhone X now supported --- .../Classes/BaseNotificationBanner.swift | 48 ++++++++++++++----- .../Classes/NotificationBanner.swift | 2 + .../Classes/StatusBarNotificationBanner.swift | 4 +- NotificationBannerSwift.podspec | 2 +- 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/NotificationBanner/Classes/BaseNotificationBanner.swift b/NotificationBanner/Classes/BaseNotificationBanner.swift index 69910114..ff90e8ac 100755 --- a/NotificationBanner/Classes/BaseNotificationBanner.swift +++ b/NotificationBanner/Classes/BaseNotificationBanner.swift @@ -17,6 +17,7 @@ */ import UIKit +import SnapKit #if CARTHAGE_CONFIG import MarqueeLabelSwift @@ -38,7 +39,9 @@ public class BaseNotificationBanner: UIView { /// The height of the banner when it is presented public var bannerHeight: CGFloat { - return NotificationBannerUtilities.isiPhoneX() && UIApplication.shared.statusBarOrientation.isPortrait ? 88.0 : 64.0 + return NotificationBannerUtilities.isiPhoneX() + && UIApplication.shared.statusBarOrientation.isPortrait + && parentViewController == nil ? 88.0 : 64.0 } /// The topmost label of the notification if a custom view is not desired @@ -82,9 +85,15 @@ public class BaseNotificationBanner: UIView { /// The view that the notification layout is presented on. The constraints/frame of this should not be changed internal var contentView: UIView! + /// A view that helps the spring animation look nice when the banner appears + internal var spacerView: UIView! + /// The default padding between edges and views internal var padding: CGFloat = 15.0 + /// The view controller to display the banner on. This is useful if you are wanting to display a banner underneath a navigation bar + internal weak var parentViewController: UIViewController? + /// Used by the banner queue to determine wether a notification banner was placed in front of it in the queue var isSuspended: Bool = false @@ -94,12 +103,6 @@ public class BaseNotificationBanner: UIView { /// The main window of the application which banner views are placed on private let appWindow: UIWindow = UIApplication.shared.delegate!.window!! - /// A view that helps the spring animation look nice when the banner appears - private var spacerView: UIView! - - /// The view controller to display the banner on. This is useful if you are wanting to display a banner underneath a navigation bar - private weak var parentViewController: UIViewController? - /// The position the notification banner should slide in from private(set) var bannerPosition: BannerPosition! @@ -169,11 +172,7 @@ public class BaseNotificationBanner: UIView { } make.left.equalToSuperview() make.right.equalToSuperview() - if NotificationBannerUtilities.isiPhoneX() && UIApplication.shared.statusBarOrientation.isPortrait { - make.height.equalTo(40.0) - } else { - make.height.equalTo(10) - } + updateSpacerViewHeight(make: make) } contentView.snp.remakeConstraints { (make) in @@ -184,12 +183,30 @@ public class BaseNotificationBanner: UIView { make.top.equalToSuperview() make.bottom.equalTo(spacerView.snp.top) } + make.left.equalToSuperview() make.right.equalToSuperview() } } + /** + Updates the spacer view height. Specifically used for orientation changes. + */ + + private func updateSpacerViewHeight(make: ConstraintMaker? = nil) { + let finalHeight = NotificationBannerUtilities.isiPhoneX() + && UIApplication.shared.statusBarOrientation.isPortrait + && parentViewController == nil ? 40.0 : 10.0 + if let make = make { + make.height.equalTo(finalHeight) + } else { + spacerView.snp.updateConstraints({ (make) in + make.height.equalTo(finalHeight) + }) + } + } + /** Dismisses the NotificationBanner and shows the next one if there is one to show on the queue */ @@ -326,7 +343,12 @@ public class BaseNotificationBanner: UIView { Changes the frame of the notificaiton banner when the orientation of the device changes */ private dynamic func onOrientationChanged() { - self.frame = CGRect(x: self.frame.origin.x, y: self.frame.origin.y, width: appWindow.frame.width, height: self.frame.height) + updateSpacerViewHeight() + self.frame = CGRect(x: self.frame.origin.x, y: self.frame.origin.y, width: appWindow.frame.width, height: bannerHeight) + bannerPositionFrame = BannerPositionFrame(bannerPosition: bannerPosition, + bannerWidth: appWindow.frame.width, + bannerHeight: bannerHeight, + maxY: maximumYPosition()) } /** diff --git a/NotificationBanner/Classes/NotificationBanner.swift b/NotificationBanner/Classes/NotificationBanner.swift index 65229692..c8cd38a3 100755 --- a/NotificationBanner/Classes/NotificationBanner.swift +++ b/NotificationBanner/Classes/NotificationBanner.swift @@ -164,6 +164,8 @@ public class NotificationBanner: BaseNotificationBanner { customView.snp.makeConstraints { (make) in make.edges.equalTo(contentView) } + + spacerView.backgroundColor = customView.backgroundColor } required public init?(coder aDecoder: NSCoder) { diff --git a/NotificationBanner/Classes/StatusBarNotificationBanner.swift b/NotificationBanner/Classes/StatusBarNotificationBanner.swift index f4a3e647..9dbc55d4 100755 --- a/NotificationBanner/Classes/StatusBarNotificationBanner.swift +++ b/NotificationBanner/Classes/StatusBarNotificationBanner.swift @@ -27,7 +27,9 @@ import UIKit public class StatusBarNotificationBanner: BaseNotificationBanner { public override var bannerHeight: CGFloat { - if NotificationBannerUtilities.isiPhoneX() && UIApplication.shared.statusBarOrientation.isPortrait { + if NotificationBannerUtilities.isiPhoneX() + && UIApplication.shared.statusBarOrientation.isPortrait + && parentViewController == nil { return super.bannerHeight } else { return 20.0 diff --git a/NotificationBannerSwift.podspec b/NotificationBannerSwift.podspec index 0098527a..bd6fda82 100755 --- a/NotificationBannerSwift.podspec +++ b/NotificationBannerSwift.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = 'NotificationBannerSwift' - s.version = '1.4.3' + s.version = '1.4.4' s.summary = 'The easiest way to display in app notification banners in iOS.' s.description = <<-DESC