Skip to content

Commit

Permalink
Merge pull request #83 from hyperoslo/feature/permanent-whistle
Browse files Browse the repository at this point in the history
Feature: permanent whistle
  • Loading branch information
zenangst committed May 3, 2016
2 parents f980709 + 7422372 commit 781f615
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 57 deletions.
5 changes: 2 additions & 3 deletions Demo/WhisperDemo/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ platform :ios, '8.0'
use_frameworks!
inhibit_all_warnings!

target "WhisperDemo" do
pod 'Whisper', path: '../../'
end
pod 'Whisper', path: '../../'
target 'WhisperDemo'
4 changes: 3 additions & 1 deletion Demo/WhisperDemo/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
Whisper: 18b574de21a089c0d664b115f26e0d9ccbbadbab

COCOAPODS: 0.39.0
PODFILE CHECKSUM: e20a3f258a5cd7e57b37f62aadb18fd14d135133

COCOAPODS: 1.0.0.beta.8
18 changes: 9 additions & 9 deletions Demo/WhisperDemo/WhisperDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@
isa = PBXNativeTarget;
buildConfigurationList = 29AD42AC1BBC2BD2004292F1 /* Build configuration list for PBXNativeTarget "WhisperDemo" */;
buildPhases = (
7C2AD771C3E0C8D8C952C8C1 /* Check Pods Manifest.lock */,
7C2AD771C3E0C8D8C952C8C1 /* 📦 Check Pods Manifest.lock */,
29AD42961BBC2BD2004292F1 /* Sources */,
29AD42971BBC2BD2004292F1 /* Frameworks */,
29AD42981BBC2BD2004292F1 /* Resources */,
386529A60BE25BE05191D829 /* Embed Pods Frameworks */,
BCC353EC93296D0E781E45A8 /* Copy Pods Resources */,
386529A60BE25BE05191D829 /* 📦 Embed Pods Frameworks */,
BCC353EC93296D0E781E45A8 /* 📦 Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -221,44 +221,44 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
386529A60BE25BE05191D829 /* Embed Pods Frameworks */ = {
386529A60BE25BE05191D829 /* 📦 Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Embed Pods Frameworks";
name = "📦 Embed Pods Frameworks";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-WhisperDemo/Pods-WhisperDemo-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
7C2AD771C3E0C8D8C952C8C1 /* Check Pods Manifest.lock */ = {
7C2AD771C3E0C8D8C952C8C1 /* 📦 Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Check Pods Manifest.lock";
name = "📦 Check Pods Manifest.lock";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
BCC353EC93296D0E781E45A8 /* Copy Pods Resources */ = {
BCC353EC93296D0E781E45A8 /* 📦 Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Copy Pods Resources";
name = "📦 Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
45 changes: 32 additions & 13 deletions Demo/WhisperDemo/WhisperDemo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,18 @@ class ViewController: UIViewController {
return button
}()

lazy var statusBarButton: UIButton = { [unowned self] in
lazy var showWhistleButton: UIButton = { [unowned self] in
let button = UIButton()
button.addTarget(self, action: #selector(statusBarButtonDidPress(_:)), forControlEvents: .TouchUpInside)
button.setTitle("Status bar", forState: .Normal)
button.addTarget(self, action: #selector(showWhistleButtonDidPress(_:)), forControlEvents: .TouchUpInside)
button.setTitle("Show Whistle", forState: .Normal)

return button
}()

lazy var presentWhistleButton: UIButton = { [unowned self] in
let button = UIButton()
button.addTarget(self, action: #selector(presentWhistleButtonDidPress(_:)), forControlEvents: .TouchUpInside)
button.setTitle("Present permanent Whistle", forState: .Normal)

return button
}()
Expand Down Expand Up @@ -84,13 +92,15 @@ class ViewController: UIViewController {

view.addSubview(scrollView)
[titleLabel, presentButton, showButton,
presentPermanentButton, notificationButton, statusBarButton].forEach { scrollView.addSubview($0) }

[presentButton, showButton, presentPermanentButton, notificationButton, statusBarButton].forEach {
$0.setTitleColor(UIColor.grayColor(), forState: .Normal)
$0.layer.borderColor = UIColor.grayColor().CGColor
$0.layer.borderWidth = 1.5
$0.layer.cornerRadius = 7.5
presentPermanentButton, notificationButton,
showWhistleButton, presentWhistleButton].forEach { scrollView.addSubview($0) }

[presentButton, showButton, presentPermanentButton,
notificationButton, showWhistleButton, presentWhistleButton].forEach {
$0.setTitleColor(UIColor.grayColor(), forState: .Normal)
$0.layer.borderColor = UIColor.grayColor().CGColor
$0.layer.borderWidth = 1.5
$0.layer.cornerRadius = 7.5
}

guard let navigationController = navigationController else { return }
Expand Down Expand Up @@ -150,13 +160,21 @@ class ViewController: UIViewController {
navigationController?.pushViewController(controller, animated: true)
}

func statusBarButtonDidPress(button: UIButton) {
func showWhistleButtonDidPress(button: UIButton) {
let murmur = Murmur(title: "This is a small whistle...",
backgroundColor: UIColor(red: 0.975, green: 0.975, blue: 0.975, alpha: 1))

Whistle(murmur)
}

func presentWhistleButtonDidPress(button: UIButton) {
let murmur = Murmur(title: "This is a permanent whistle...",
backgroundColor: UIColor.redColor(),
titleColor: UIColor.whiteColor())

Whistle(murmur, action: .Present)
}

// MARK - Configuration

func setupFrames() {
Expand All @@ -168,9 +186,10 @@ class ViewController: UIViewController {
showButton.frame = CGRect(x: 50, y: presentButton.frame.maxY + 15, width: totalSize.width - 100, height: 50)
presentPermanentButton.frame = CGRect(x: 50, y: showButton.frame.maxY + 15, width: totalSize.width - 100, height: 50)
notificationButton.frame = CGRect(x: 50, y: presentPermanentButton.frame.maxY + 15, width: totalSize.width - 100, height: 50)
statusBarButton.frame = CGRect(x: 50, y: notificationButton.frame.maxY + 15, width: totalSize.width - 100, height: 50)
showWhistleButton.frame = CGRect(x: 50, y: notificationButton.frame.maxY + 15, width: totalSize.width - 100, height: 50)
presentWhistleButton.frame = CGRect(x: 50, y: showWhistleButton.frame.maxY + 15, width: totalSize.width - 100, height: 50)

let height = statusBarButton.frame.maxY >= totalSize.height ? statusBarButton.frame.maxY + 35 : totalSize.height
let height = presentWhistleButton.frame.maxY >= totalSize.height ? presentWhistleButton.frame.maxY + 35 : totalSize.height
scrollView.contentSize = CGSize(width: totalSize.width, height: height)
}
}
Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ The usage of the component is so simple, you just create a message in the case o

```swift
let message = Message(title: "Enter your message here.", backgroundColor: UIColor.redColor())

// Show and hide a message after delay
Whisper(message, to: navigationController, action: .Show)

// Present a permanent message
Whisper(message, to: navigationController, action: .Present)

// Hide a message
Silent(navigationController)
```

##### For a Shout:
Expand All @@ -58,7 +66,15 @@ Shout(announcement, to: self)

```swift
let murmur = Murmur(title: "This is a small whistle...")
Whistle(murmur)

// Show and hide a message after delay
Whistle(murmur) // Whistle(murmur, action: .Show(1.5))

// Present a permanent status bar message
Whistle(murmur, action: .Present)

// Hide a message
Calm()
```

If you want to use **Whisper** with Objective-C, you can find information about it [here](https://github.com/hyperoslo/Whisper/wiki/Using-Whisper-in-Objective-C).
Expand Down
4 changes: 1 addition & 3 deletions Source/Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ public struct Announcement {
public struct Murmur {

public var title: String
public var duration: NSTimeInterval
public var backgroundColor: UIColor
public var titleColor: UIColor
public var font: UIFont

public init(title: String, duration: NSTimeInterval = 1.5, backgroundColor: UIColor = ColorList.Whistle.background, titleColor: UIColor = ColorList.Whistle.title, font: UIFont = FontList.Whistle.title) {
public init(title: String, backgroundColor: UIColor = ColorList.Whistle.background, titleColor: UIColor = ColorList.Whistle.title, font: UIFont = FontList.Whistle.title) {
self.title = title
self.duration = duration
self.backgroundColor = backgroundColor
self.titleColor = titleColor
self.font = font
Expand Down
8 changes: 4 additions & 4 deletions Source/ShoutFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ public class ShoutView: UIView {

public private(set) lazy var tapGestureRecognizer: UITapGestureRecognizer = { [unowned self] in
let gesture = UITapGestureRecognizer()
gesture.addTarget(self, action: "handleTapGestureRecognizer")
gesture.addTarget(self, action: #selector(ShoutView.handleTapGestureRecognizer))

return gesture
}()

public private(set) lazy var panGestureRecognizer: UIPanGestureRecognizer = { [unowned self] in
let gesture = UIPanGestureRecognizer()
gesture.addTarget(self, action: "handlePanGestureRecognizer")
gesture.addTarget(self, action: #selector(ShoutView.handlePanGestureRecognizer))

return gesture
}()
Expand Down Expand Up @@ -108,7 +108,7 @@ public class ShoutView: UIView {
addGestureRecognizer(tapGestureRecognizer)
gestureContainer.addGestureRecognizer(panGestureRecognizer)

NSNotificationCenter.defaultCenter().addObserver(self, selector: "orientationDidChange", name: UIDeviceOrientationDidChangeNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(ShoutView.orientationDidChange), name: UIDeviceOrientationDidChangeNotification, object: nil)
}

public required init?(coder aDecoder: NSCoder) {
Expand Down Expand Up @@ -146,7 +146,7 @@ public class ShoutView: UIView {

displayTimer.invalidate()
displayTimer = NSTimer.scheduledTimerWithTimeInterval(announcement.duration,
target: self, selector: "displayTimerDidFire", userInfo: nil, repeats: false)
target: self, selector: #selector(ShoutView.displayTimerDidFire), userInfo: nil, repeats: false)
setupFrames()
}

Expand Down
18 changes: 9 additions & 9 deletions Source/WhisperFactory.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import UIKit

public enum Action: String {
public enum WhisperAction: String {
case Present = "Whisper.PresentNotification"
case Show = "Whisper.ShowNotification"
}

let whisperFactory: WhisperFactory = WhisperFactory()

public func Whisper(message: Message, to: UINavigationController, action: Action = .Show) {
public func Whisper(message: Message, to: UINavigationController, action: WhisperAction = .Show) {
whisperFactory.craft(message, navigationController: to, action: action)
}

Expand Down Expand Up @@ -36,14 +36,14 @@ class WhisperFactory: NSObject {

override init() {
super.init()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "orientationDidChange", name: UIDeviceOrientationDidChangeNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(WhisperFactory.orientationDidChange), name: UIDeviceOrientationDidChangeNotification, object: nil)
}

deinit {
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIDeviceOrientationDidChangeNotification, object: nil)
}

func craft(message: Message, navigationController: UINavigationController, action: Action) {
func craft(message: Message, navigationController: UINavigationController, action: WhisperAction) {
self.navigationController = navigationController
self.navigationController.delegate = self
presentTimer.invalidate()
Expand Down Expand Up @@ -105,7 +105,7 @@ class WhisperFactory: NSObject {
whisperView = whisperSubview
delayTimer.invalidate()
delayTimer = NSTimer.scheduledTimerWithTimeInterval(after, target: self,
selector: "delayFired:", userInfo: nil, repeats: false)
selector: #selector(WhisperFactory.delayFired(_:)), userInfo: nil, repeats: false)
}

// MARK: - Presentation
Expand Down Expand Up @@ -143,11 +143,11 @@ class WhisperFactory: NSObject {
}
}, completion: { _ in
self.delayTimer = NSTimer.scheduledTimerWithTimeInterval(1.5, target: self,
selector: "delayFired:", userInfo: nil, repeats: false)
selector: #selector(WhisperFactory.delayFired(_:)), userInfo: nil, repeats: false)
})
}

func changeView(message: Message, action: Action) {
func changeView(message: Message, action: WhisperAction) {
presentTimer.invalidate()
delayTimer.invalidate()
hideView()
Expand All @@ -161,7 +161,7 @@ class WhisperFactory: NSObject {
if let images = message.images { array["images"] = images }

presentTimer = NSTimer.scheduledTimerWithTimeInterval(AnimationTiming.movement * 1.1, target: self,
selector: "presentFired:", userInfo: array, repeats: false)
selector: #selector(WhisperFactory.presentFired(_:)), userInfo: array, repeats: false)
}

func hideView() {
Expand Down Expand Up @@ -195,7 +195,7 @@ class WhisperFactory: NSObject {

if let imageArray = userInfo["images"] as? [UIImage]? { images = imageArray }

let action = Action(rawValue: actionString)
let action = WhisperAction(rawValue: actionString)
let message = Message(title: title, textColor: textColor, backgroundColor: backgroundColor, images: images)

whisperView = WhisperView(height: navigationController.navigationBar.frame.height, message: message)
Expand Down
Loading

0 comments on commit 781f615

Please sign in to comment.