Skip to content

Commit

Permalink
iPhone X now supported
Browse files Browse the repository at this point in the history
  • Loading branch information
Daltron committed Sep 19, 2017
1 parent a52556d commit ea6ea1f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
48 changes: 35 additions & 13 deletions NotificationBanner/Classes/BaseNotificationBanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

import UIKit
import SnapKit

#if CARTHAGE_CONFIG
import MarqueeLabelSwift
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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!

Expand Down Expand Up @@ -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
Expand All @@ -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
*/
Expand Down Expand Up @@ -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())
}

/**
Expand Down
2 changes: 2 additions & 0 deletions NotificationBanner/Classes/NotificationBanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion NotificationBanner/Classes/StatusBarNotificationBanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion NotificationBannerSwift.podspec
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit ea6ea1f

Please sign in to comment.