11import UIKit
22
33
4+ #if swift(>=4.2)
5+ public typealias AnimationOptions = UIView . AnimationOptions
6+ #else
7+ public typealias AnimationOptions = UIViewAnimationOptions
8+ #endif
9+
10+
411//MARK: - MAIN
512@nonobjc
613public extension Keyboard {
@@ -14,13 +21,13 @@ public extension Keyboard {
1421 /// The keyboard's transition duration.
1522 public let transitionDuration : Double
1623 /// The keyboard's transition animation options.
17- public let transitionAnimationOptions : UIViewAnimationOptions
24+ public let transitionAnimationOptions : AnimationOptions
1825
1926 //MARK: - Setup
2027 private init ( initialTransitionRect: CGRect ,
2128 finalTransitionRect: CGRect ,
2229 transitionDuration: Double ,
23- transitionAnimationOptions: UIViewAnimationOptions )
30+ transitionAnimationOptions: AnimationOptions )
2431 {
2532 self . initialTransitionRect = initialTransitionRect
2633 self . finalTransitionRect = finalTransitionRect
@@ -30,12 +37,20 @@ public extension Keyboard {
3037
3138 fileprivate init ? ( userInfo: [ AnyHashable : Any ] )
3239 {
40+ #if swift(>=4.2)
41+ guard let initialRect = ( userInfo [ UIResponder . keyboardFrameBeginUserInfoKey] as? NSValue ) ? . cgRectValue,
42+ let finalRect = ( userInfo [ UIResponder . keyboardFrameEndUserInfoKey] as? NSValue ) ? . cgRectValue,
43+ let duration = ( userInfo [ UIResponder . keyboardAnimationDurationUserInfoKey] as? NSNumber ) ? . doubleValue,
44+ let options = ( userInfo [ UIResponder . keyboardAnimationCurveUserInfoKey] as? NSNumber ) ? . uintValue
45+ else { return nil }
46+ #else
3347 guard let initialRect = ( userInfo [ UIKeyboardFrameBeginUserInfoKey] as? NSValue ) ? . cgRectValue,
3448 let finalRect = ( userInfo [ UIKeyboardFrameEndUserInfoKey] as? NSValue ) ? . cgRectValue,
3549 let duration = ( userInfo [ UIKeyboardAnimationDurationUserInfoKey] as? NSNumber ) ? . doubleValue,
3650 let options = ( userInfo [ UIKeyboardAnimationCurveUserInfoKey] as? NSNumber ) ? . uintValue
3751 else { return nil }
38- let animationOptions = UIViewAnimationOptions ( rawValue: options) . union ( . beginFromCurrentState)
52+ #endif
53+ let animationOptions = AnimationOptions ( rawValue: options) . union ( . beginFromCurrentState)
3954 self . init ( initialTransitionRect: initialRect,
4055 finalTransitionRect: finalRect,
4156 transitionDuration: duration,
@@ -154,9 +169,16 @@ fileprivate extension NotificationCenter
154169//MARK: - Notification + Keyboard Change Handler
155170fileprivate extension Notification
156171{
172+ #if swift(>=4.2)
173+ static var allKeyboardNotifications = [
174+ UIResponder . keyboardWillChangeFrameNotification
175+ ]
176+ #else
157177 static var allKeyboardNotifications = [
158178 Notification . Name. UIKeyboardWillChangeFrame
159179 ]
180+ #endif
181+
160182
161183 var keyboardChange : Keyboard . Change ? {
162184 guard Notification . allKeyboardNotifications. contains ( name) else { return nil }
0 commit comments