Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add overlapping the status bar support #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class ViewController: UIViewController {
super.viewDidLoad()

notificationManager1.notificationsPosition = .top
notificationManager1.notificationsBackgroundColor = UIColor.white
notificationManager1.shouldOverlapStatusBar = true
notificationManager1.notificationsBackgroundColor = UIColor.yellow
notificationManager1.notificationsTitleTextColor = UIColor.black
notificationManager1.notificationsBodyTextColor = UIColor.darkGray
notificationManager1.notificationsSeperatorColor = UIColor.gray
Expand Down
30 changes: 23 additions & 7 deletions Source/LNRNotificationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ public class LNRNotificationManager: NSObject {
}
})

mainWindow?.windowLevel = UIWindowLevelNormal

return true
}

Expand All @@ -124,8 +126,8 @@ public class LNRNotificationManager: NSObject {
// MARK: Notification Styling

/**
* Use to set the background color of notifications.
*/
* Use to set the background color of notifications.
*/
public var notificationsBackgroundColor: UIColor = UIColor.white

/**
Expand Down Expand Up @@ -158,6 +160,11 @@ public class LNRNotificationManager: NSObject {
*/
public var notificationsIcon: UIImage?

/**
* Use to set the status bar hidden or not.
*/
public var shouldOverlapStatusBar: Bool = false

/**
* Use to set the position of notifications on screen.
*/
Expand All @@ -168,33 +175,42 @@ public class LNRNotificationManager: NSObject {
*/
public var notificationSound: SystemSoundID?

fileprivate var mainWindow: UIWindow?

// MARK: Internal

private func displayNotificationView(notificationView: LNRNotificationView) {

mainWindow = UIApplication.shared.keyWindow
self.activeNotification = notificationView

notificationView.isDisplayed = true

let mainWindow = UIApplication.shared.keyWindow
mainWindow?.addSubview(notificationView)

var toPoint: CGPoint

if notificationsPosition != LNRNotificationPosition.bottom {
toPoint = CGPoint(x: notificationView.center.x, y: notificationView.frame.height / 2.0)
var y = notificationView.frame.height / 2.0
y = shouldOverlapStatusBar ? (y - kStatusBarHeight) : y
toPoint = CGPoint(x: notificationView.center.x, y: y)
} else {
let y: CGFloat = UIScreen.main.bounds.size.height - (notificationView.frame.height / 2.0)
var y: CGFloat = UIScreen.main.bounds.size.height - (notificationView.frame.height / 2.0)
toPoint = CGPoint(x: notificationView.center.x, y: y)
}

if shouldOverlapStatusBar {
mainWindow?.windowLevel = UIWindowLevelStatusBar
} else {
mainWindow?.windowLevel = UIWindowLevelNormal
}

if let notificationSound = notificationSound {
AudioServicesPlayAlertSound(notificationSound)
}

UIView.animate(withDuration: kLNRNotificationAnimationDuration + 0.1, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: [UIViewAnimationOptions.beginFromCurrentState, UIViewAnimationOptions.allowUserInteraction], animations: { () -> Void in
notificationView.center = toPoint
}, completion: nil)
}, completion: nil)

if notificationView.notification.duration != LNRNotificationDuration.endless.rawValue {
let notificationDisplayTime = notificationView.notification.duration > 0 ? notificationView.notification.duration : LNRNotificationDuration.default.rawValue
Expand Down