Skip to content
This repository was archived by the owner on Mar 10, 2022. It is now read-only.

Commit 8c9b005

Browse files
authored
Merge pull request #20 from nodes-ios/mariusc/tweaks
Minor tweaks
2 parents acf26ee + 120996b commit 8c9b005

File tree

5 files changed

+52
-67
lines changed

5 files changed

+52
-67
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ osx_image: xcode8.1
33
branches:
44
only:
55
- master
6+
- develop
67

78
env:
89
global:

KeyboardHelper/Classes/KeyboardAppearanceInfo.swift

+26-42
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
import Foundation
1010
import UIKit
1111

12-
/**
13-
A struct holding all keyboard view information when it's being shown or hidden.
14-
*/
12+
/// A struct holding all keyboard view information when it's being shown or hidden.
1513
public struct KeyboardAppearanceInfo {
1614

1715
public let notification: Notification
@@ -22,68 +20,54 @@ public struct KeyboardAppearanceInfo {
2220
self.userInfo = notification.userInfo ?? [:]
2321
}
2422

25-
/**
26-
Getter for the UIKeyboard frame begin infokey.
27-
Return a `CGRect` or `CGRectZero`.
28-
*/
23+
/// Getter for the UIKeyboard frame begin infokey. Returns a `CGRect` or `CGRectZero`.
2924
public var beginFrame: CGRect {
3025
return (userInfo[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue ?? .zero
3126
}
3227

33-
/**
34-
Getter for the UIKeyboard frame end infokey.
35-
Return a `CGRect` or `CGRectZero`.
36-
*/
28+
29+
/// Getter for the UIKeyboard frame end infokey. Return a `CGRect` or `CGRectZero`.
3730
public var endFrame: CGRect {
3831
return (userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue ?? .zero
3932
}
4033

41-
/**
42-
Getter for the UIKeyboard info if the keyboard is in the current app.
43-
That variable will help to keep track of which app uses the keyboard at the moment.
44-
If it is the current app it is true, if not it is false.
45-
*/
34+
35+
@available(iOS 9.0, *)
36+
/// Getter for the UIKeyboard info if the keyboard is in the current app.
37+
/// That variable will help to keep track of which app uses the keyboard at the moment.
38+
/// If it is the current app it is true, if not it is false.
4639
public var belongsToCurrentApp: Bool {
47-
if #available(iOS 9.0, *) {
48-
return (userInfo[UIKeyboardIsLocalUserInfoKey] as? Bool) ?? true
49-
} else {
50-
return true
51-
}
40+
return (userInfo[UIKeyboardIsLocalUserInfoKey] as? Bool) ?? true
41+
5242
}
5343

54-
/**
55-
Getter for the duration of the keyboard appear/disappear animation.
56-
By default: `0.25`.
57-
*/
44+
45+
/// Getter for the duration of the keyboard appear/disappear animation.
46+
/// By default: `0.25`.
5847
public var animationDuration: Double {
5948
return (userInfo[UIKeyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue ?? 0.25
6049
}
61-
62-
/**
63-
Getter for the animation curve.
64-
By default: `EaseInOut`.
65-
*/
50+
51+
/// Getter for the animation curve.
52+
/// By default: `EaseInOut`.
6653
public var animationCurve: UIViewAnimationCurve {
6754
guard let value = userInfo[UIKeyboardAnimationCurveUserInfoKey] as? Int else { return .easeInOut }
6855
return UIViewAnimationCurve(rawValue: value) ?? .easeInOut
6956
}
7057

71-
/**
72-
Getter for the animation option.
73-
That variable will help to keep track of the keyboard appearence.
74-
*/
58+
59+
/// Getter for the animation option.
60+
/// That variable will help to keep track of the keyboard appearence.
7561
public var animationOptions: UIViewAnimationOptions {
7662
return UIViewAnimationOptions(rawValue: UInt(animationCurve.rawValue << 16))
7763
}
7864

79-
/**
80-
Animate a `UView` while the keyboard appears and check if animation is finished.
81-
If finished do completion.
82-
83-
Parameters:
84-
- animationBlock: Animation that should happen.
85-
- completion: Function that happens after the animation is finished.
86-
*/
65+
/// Animate a `UView` while the keyboard appears and check if animation is finished.
66+
/// If finished do completion.
67+
///
68+
/// Parameters:
69+
/// - animationBlock: Animation that should happen.
70+
/// - completion: Function that happens after the animation is finished.
8771
public func animateAlong(_ animationBlock: @escaping (() -> Void), completion: @escaping ((_ finished: Bool) -> Void) = { _ in }) {
8872
UIView.animate(
8973
withDuration: animationDuration,

KeyboardHelper/Classes/KeyboardHelper.swift

+18-22
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,43 @@
99
import Foundation
1010
import UIKit
1111

12-
/**
13-
Protocol `KeyboardHelperDelegate` requires two functions.
14-
Function `keyboardWillAppear` and `keyboardWillDisappear` with parameter `info` struct `KeyboardAppearanceInfo`.
15-
*/
1612

13+
/// Protocol `KeyboardHelperDelegate` requires two functions, `keyboardWillAppear` and `keyboardWillDisappear` with parameter `info` struct `KeyboardAppearanceInfo`.
1714
public protocol KeyboardHelperDelegate: class {
1815

19-
/**
20-
This function will recongnize a change of `KeyboardAppearanceInfo` and will be fired when the keyboard will appaear.
21-
- Parameter info: Struct `KeyboardAppearanceInfo`.
22-
*/
16+
17+
/// This function will recongnize a change of `KeyboardAppearanceInfo` and will be fired when the keyboard will appaear.
18+
///
19+
/// - Parameter info: Struct `KeyboardAppearanceInfo`.
2320
func keyboardWillAppear(_ info: KeyboardAppearanceInfo)
21+
2422

25-
/**
26-
This function will recongnize a change of `KeyboardAppearanceInfo` and will be fired when the keyboard will disappaear.
27-
- Parameter info: Struct `KeyboardAppearanceInfo`.
28-
*/
23+
/// This function will recongnize a change of `KeyboardAppearanceInfo` and will be fired when the keyboard will disappaear.
24+
///
25+
/// - Parameter info: Struct `KeyboardAppearanceInfo`.
2926
func keyboardWillDisappear(_ info: KeyboardAppearanceInfo)
3027
}
3128

32-
/**
33-
Useful helper to keep track of keyboard changes.
34-
*/
29+
30+
/// Useful helper to keep track of keyboard changes.
3531
public class KeyboardHelper {
3632

37-
/**
38-
Delegate that conforms with the `KeyboardHelperDelegate`.
39-
*/
33+
/// Delegate that conforms with the `KeyboardHelperDelegate`.
4034
public weak var delegate: KeyboardHelperDelegate?
4135

42-
/**
43-
Initialize the `delegate` and add the two observer for `keyboardWillAppear` and `keyboardWillDisappear`.
44-
Observers are nessecary for tracking the `UIKeyboardWillShowNotification` and `UIKeyboardWillHideNotification`, so the function that are connectet are getting fired.
45-
*/
36+
/// Initialize the `delegate` and add the two observer for `keyboardWillAppear` and `keyboardWillDisappear`.
37+
/// Observers are nessecary for tracking the `UIKeyboardWillShowNotification` and `UIKeyboardWillHideNotification`, so the function that are connectet are getting fired.
38+
///
39+
/// - Parameter delegate: KeyboardHelperDelegate
4640
required public init(delegate: KeyboardHelperDelegate) {
4741
self.delegate = delegate
4842

4943
NotificationCenter.default.addObserver(self, selector: #selector(KeyboardHelper.keyboardWillAppear(_:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
5044
NotificationCenter.default.addObserver(self, selector: #selector(KeyboardHelper.keyboardWillDisappear(_:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
5145
}
5246

47+
48+
/// Making sure that you can't intantiate it without a delegate
5349
private init() {
5450
delegate = nil
5551
}

KeyboardHelperTests/Tests/KeyboardAppearanceInfoTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ class KeyboardAppearanceInfoTests: XCTestCase {
6969
}
7070

7171
func testAnimationCurve() {
72-
XCTAssertEqual(appearanceInfo.animationCurve, UIViewAnimationCurve(rawValue: 2),
72+
XCTAssertEqual(appearanceInfo.animationCurve, UIViewAnimationCurve.easeOut,
7373
"Parsing animationCurve from keyboard appearance info failed.")
74-
XCTAssertEqual(defaultsAppearanceInfo.animationCurve, UIViewAnimationCurve(rawValue: defaultsAppearanceInfo.animationCurve.rawValue),
74+
XCTAssertEqual(defaultsAppearanceInfo.animationCurve, UIViewAnimationCurve.easeInOut,
7575
"Parsing default animationCurve from keyboard appearance info failed.")
7676
}
7777

KeyboardHelperTests/Tests/KeyboardHelperTests.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ class KeyboardHelperTests: XCTestCase {
9595
XCTAssertEqual(result.animationDuration, 0.25)
9696
XCTAssertEqual(result.beginFrame, CGRect(x: 0, y: 667, width: 375, height: 0))
9797
XCTAssertEqual(result.endFrame, CGRect(x: 0, y: 409, width: 375, height: 258))
98-
XCTAssertEqual(result.belongsToCurrentApp, true)
98+
if #available(iOS 9.0, *) {
99+
XCTAssertEqual(result.belongsToCurrentApp, true)
100+
} else {
101+
// don't test this
102+
}
99103

100104
}
101105
}

0 commit comments

Comments
 (0)