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

Adds the completion handler #10

Merged
merged 2 commits into from
Dec 11, 2015
Merged
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
Binary file not shown.
4 changes: 3 additions & 1 deletion Demo/WhisperDemo/WhisperDemo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ class ViewController: UIViewController {
func presentNotificationDidPress(button: UIButton) {
let announcement = Announcement(title: "Ramon Gilabert", subtitle: "Vadym Markov just commented your post", image: UIImage(named: "avatar"))

Shout(announcement, to: self)
Shout(announcement, to: self, completion: {
print("The shout was silent.")
})
}

func statusBarButtonDidPress(button: UIButton) {
Expand Down
12 changes: 8 additions & 4 deletions Source/ShoutFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import UIKit

let shout = ShoutView()

public func Shout(announcement: Announcement, to: UIViewController) {
shout.craft(announcement, to: to)
public func Shout(announcement: Announcement, to: UIViewController, completion: (() -> ())? = {}) {
shout.craft(announcement, to: to, completion: completion)
}

public class ShoutView: UIView {
Expand Down Expand Up @@ -93,6 +93,7 @@ public class ShoutView: UIView {
public var displayTimer = NSTimer()
public var panGestureActive = false
public var shouldSilent = false
public var completion: (() -> ())?

// MARK: - Initializers

Expand Down Expand Up @@ -121,11 +122,13 @@ public class ShoutView: UIView {

// MARK: - Configuration

public func craft(announcement: Announcement, to: UIViewController) {
public func craft(announcement: Announcement, to: UIViewController, completion: (() -> ())?) {
panGestureActive = false
shouldSilent = false
configureView(announcement)
shout(to: to)

self.completion = completion
}

public func configureView(announcement: Announcement) {
Expand Down Expand Up @@ -187,6 +190,7 @@ public class ShoutView: UIView {
self.frame.size.height = 0
self.backgroundView.frame.size.height = self.frame.height
}, completion: { finished in
self.completion?()
self.displayTimer.invalidate()
self.removeFromSuperview()
})
Expand Down Expand Up @@ -227,7 +231,7 @@ public class ShoutView: UIView {
duration = 0.2
UIView.animateWithDuration(duration, animations: {
self.frame.size.height = height
}, completion: { _ in if translation.y < -5 { self.removeFromSuperview() }})
}, completion: { _ in if translation.y < -5 { self.completion?(); self.removeFromSuperview() }})
}

UIView.animateWithDuration(duration, animations: {
Expand Down