Skip to content

Commit

Permalink
fix: ignore floating keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
toshi0383 committed Dec 9, 2022
1 parent bfc242a commit 2f7b392
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions Sources/KeyboardLayoutGuide/KeyboardLayoutGuide.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,29 @@ extension UILayoutGuide {

extension Notification {
var keyboardHeight: CGFloat? {
guard let keyboardFrame = userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue else {
guard let keyboardEndFrame = userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue else {
return nil
}

if name == UIResponder.keyboardWillHideNotification {
return 0.0
}

let keyboardMinY = keyboardFrame.cgRectValue.minY
let keyboardMinY = keyboardEndFrame.cgRectValue.minY

let isLikelyFloating: Bool = {
if keyboardMinY == 0 { return true }

guard let keyboardBeginFrame = userInfo?[UIResponder.keyboardFrameBeginUserInfoKey] as? NSValue else {
return false
}

return keyboardBeginFrame.cgRectValue.minY == 0
}()

if isLikelyFloating {
return nil
}

// Weirdly enough UIKeyboardFrameEndUserInfoKey doesn't have the same behaviour
// in ios 10 or iOS 11 so we can't rely on v.cgRectValue.width
Expand Down

0 comments on commit 2f7b392

Please sign in to comment.