Skip to content

Commit

Permalink
Merge pull request #114 from UbiqueInnovation/bugfix/keyboard-info
Browse files Browse the repository at this point in the history
Fixes keyboard info crash
  • Loading branch information
bastianmorath authored Nov 28, 2024
2 parents 031e33d + 5e46235 commit d412160
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions Sources/UBUserInterface/Keyboard/KeyboardInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct KeyboardInfo {
// :nodoc:
let endFrame: CGRect
// :nodoc:
let animationCurve: UIView.AnimationCurve
let animationOptions: UIView.AnimationOptions
// :nodoc:
let animationDuration: TimeInterval

Expand All @@ -28,12 +28,11 @@ struct KeyboardInfo {

self.endFrame = endFrame

// UIViewAnimationOption is shifted by 16 bit from UIViewAnimationCurve, which we get here:
// http://stackoverflow.com/questions/18870447/how-to-use-the-default-ios7-uianimation-curve
if let animationCurveRaw = userInfo[UIResponder.keyboardAnimationCurveUserInfoKey] as? Int, let animationCurve = UIView.AnimationCurve(rawValue: animationCurveRaw) {
self.animationCurve = animationCurve
// https://developer.apple.com/documentation/uikit/uikeyboardanimationcurveuserinfokey
if let animationCurveRaw = userInfo[UIResponder.keyboardAnimationCurveUserInfoKey] as? UInt {
self.animationOptions = UIView.AnimationOptions(rawValue: animationCurveRaw << 16)
} else {
animationCurve = .linear
animationOptions = UIView.AnimationOptions.curveLinear
}

if let animationDuration = userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double {
Expand All @@ -46,21 +45,11 @@ struct KeyboardInfo {
// :nodoc:
func animateAlongsideKeyboard(_ animations: @escaping () -> Void) {
#if !os(visionOS)
UIView.animate(withDuration: animationDuration, delay: 0, options: [.beginFromCurrentState, getAnimationOption(from: animationCurve)]) {
UIView.animate(withDuration: animationDuration, delay: 0, options: [.beginFromCurrentState, animationOptions]) {
animations()
}
#else
animations()
#endif
}

private func getAnimationOption(from curve: UIView.AnimationCurve) -> UIView.AnimationOptions {
switch curve {
case .easeInOut: .curveEaseInOut
case .easeIn: .curveEaseIn
case .easeOut: .curveEaseOut
case .linear: .curveLinear
@unknown default: fatalError()
}
}
}

0 comments on commit d412160

Please sign in to comment.