Skip to content

Commit

Permalink
Added touch handler based notification
Browse files Browse the repository at this point in the history
  • Loading branch information
Ömer Aslan committed Mar 28, 2016
1 parent 98372ea commit 430a3e1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
34 changes: 28 additions & 6 deletions Classes/NotificationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation
import UIKit

class NotificationView : UIView {
class NotificationView : UIView{
let bundle = NSBundle(identifier: "com.omer.OEANotification")
var notificationTimer: NSTimer!
var title: String?
Expand All @@ -23,20 +23,27 @@ class NotificationView : UIView {

init(frame: CGRect, title: String, subTitle: String?, type: NotificationType?, isDismissable: Bool) {
super.init(frame: frame)
self.initVariables(title, subTitle: subTitle, image: nil, type: type, completionHandler: {}, touchHandler: {}, isDismissable: isDismissable)
self.initVariables(title, subTitle: subTitle, image: nil, type: type, completionHandler: nil, touchHandler: nil, isDismissable: isDismissable)
self.setupNotification()

}

init(frame: CGRect, title: String, subTitle: String?, image: UIImage?, type: NotificationType?, isDismissable: Bool) {
super.init(frame: frame)
self.initVariables(title, subTitle: subTitle, image: image, type: type, completionHandler: {}, touchHandler: {}, isDismissable: isDismissable)
self.initVariables(title, subTitle: subTitle, image: image, type: type, completionHandler: nil, touchHandler: nil, isDismissable: isDismissable)
self.setupNotification()
}

init(frame: CGRect, title: String, subTitle: String?, image: UIImage?, type: NotificationType?, completionHandler: (() -> Void)?, isDismissable: Bool) {
super.init(frame: frame)
self.initVariables(title, subTitle: subTitle, image: image, type: type, completionHandler: completionHandler, touchHandler: {}, isDismissable: isDismissable)
self.initVariables(title, subTitle: subTitle, image: image, type: type, completionHandler: completionHandler, touchHandler: nil, isDismissable: isDismissable)
self.setupNotification()
}

init(frame: CGRect, title: String, subTitle: String?, image: UIImage?, type: NotificationType?, completionHandler: (() -> Void)?, touchHandler: (() -> Void)?, isDismissable: Bool) {
super.init(frame: frame)

self.initVariables(title, subTitle: subTitle, image: image, type: type, completionHandler: completionHandler, touchHandler: touchHandler, isDismissable: isDismissable)
self.setupNotification()
}

Expand All @@ -52,6 +59,7 @@ class NotificationView : UIView {
}

private func setupNotification() {

self.createBackground()
if self.isDismissable {
constants.nvPaddingRight += constants.nvdWidth
Expand All @@ -70,9 +78,22 @@ class NotificationView : UIView {
if self.isDismissable {
constants.nvPaddingRight -= constants.nvdPaddingLeft
}

if self.touchHandler != nil {
self.createTouchEvent()
}
self.addNotificationView()
}

private func createTouchEvent() {
let tap = UITapGestureRecognizer(target: self, action: "handleTap:")
self.addGestureRecognizer(tap)
}

func handleTap(recognizer: UITapGestureRecognizer) {
self.touchHandler!()
}

private func addNotificationView() {
NotificationView.animateWithDuration(constants.nvaTimer, animations: { () -> Void in
self.frame.origin.y = self.constants.nvMarginTop
Expand All @@ -83,6 +104,7 @@ class NotificationView : UIView {
self.completionHandler!()
}
}

}

self.addTimer(constants.nvaShownTimer)
Expand Down Expand Up @@ -161,15 +183,15 @@ class NotificationView : UIView {

func close() {
self.notificationTimer.invalidate()

NotificationView.animateWithDuration(constants.nvaTimer, animations: { () -> Void in
self.frame.origin.y = self.constants.nvStartYPoint
self.frame.origin.y = self.constants.nvStartYPoint
}) { (Bool) -> Void in
if OEANotification.notificationCount == 1 {
UIApplication.sharedApplication().delegate?.window??.windowLevel = UIWindowLevelNormal
OEANotification.removeOldNotifications()
}
}

}

required init?(coder aDecoder: NSCoder) {
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ class ViewController: UIViewController {
//OEANotification.notify("Test Title", subTitle: "Test SubTitle", image: nil, type: NotificationType.Info, isDismissable: true)
// to create warning notification
//OEANotification.notify("Test Title", subTitle: "Test SubTitle", image: nil, type: NotificationType.Warning, isDismissable: true)
// to create completion handler based notification
OEANotification.notify("Test Title", subTitle: "Test Subtitle", image: nil, type: .Success, isDismissable: true, completion: { () -> Void in
print("completed")
}, touchHandler: nil)
// to create touchHandler based notificaiton
OEANotification.notify("Test Title", subTitle: "Test Subtitle", image: nil, type: .Success, isDismissable: true, completion: { () -> Void in
print("completed")
}) { () -> Void in
print("touched event")
}
}
```
Expand All @@ -45,7 +54,7 @@ pod "OEANotification"
- [ ] Custom Notification Type
- [X] Device rotation handling
- [X] Completion Handler based notification
- [ ] View Tapped Handler based notification
- [X] View Tapped Handler based notification
- [ ] Creating big example of OEANotification
- [ ] UI Tests
- [ ] Setup Travis
Expand Down

0 comments on commit 430a3e1

Please sign in to comment.