-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Update experiment/test - `swift-programmatic-modal/AdaptiveModal`.
- Loading branch information
1 parent
46b03d3
commit 4a3b652
Showing
3 changed files
with
164 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
experiments/swift-programmatic-modal/RNILayout/RNILayoutKeyboardValues.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// | ||
// RNILayoutKeyboardValues.swift | ||
// swift-programmatic-modal | ||
// | ||
// Created by Dominic Go on 6/21/23. | ||
// | ||
|
||
import UIKit | ||
|
||
struct RNILayoutKeyboardValues { | ||
var frameBegin: CGRect; | ||
var frameEnd: CGRect; | ||
|
||
var animationDuration: CGFloat; | ||
var animationCurve: UIView.AnimationCurve; | ||
}; | ||
|
||
extension RNILayoutKeyboardValues { | ||
init?(fromNotification notification: NSNotification) { | ||
guard let userInfo = notification.userInfo else { return nil }; | ||
|
||
func extract<T>(key: String) throws -> T { | ||
guard let rawValue = userInfo[key], | ||
let value = rawValue as? T | ||
else { throw NSError() }; | ||
|
||
return value; | ||
}; | ||
|
||
func extractValue<T>( | ||
userInfoKey: String, | ||
valueKey: KeyPath<NSValue, T> | ||
) throws -> T { | ||
|
||
guard let rawValue: NSValue = try? extract(key: userInfoKey) | ||
else { throw NSError() }; | ||
|
||
return rawValue[keyPath: valueKey]; | ||
}; | ||
|
||
do { | ||
self.frameBegin = try extractValue( | ||
userInfoKey: UIResponder.keyboardFrameBeginUserInfoKey, | ||
valueKey: \.cgRectValue | ||
); | ||
|
||
self.frameEnd = try extractValue( | ||
userInfoKey: UIResponder.keyboardFrameEndUserInfoKey, | ||
valueKey: \.cgRectValue | ||
); | ||
|
||
self.animationDuration = try extract( | ||
key: UIResponder.keyboardAnimationDurationUserInfoKey | ||
); | ||
|
||
self.animationCurve = try { | ||
let curveValue: Int = try extract( | ||
key: UIResponder.keyboardAnimationCurveUserInfoKey | ||
); | ||
|
||
guard let curve = UIView.AnimationCurve(rawValue: curveValue) else { | ||
throw NSError(); | ||
}; | ||
|
||
return curve; | ||
}(); | ||
|
||
} catch { | ||
return nil; | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters