Skip to content

Commit

Permalink
Merge pull request #199 from aldrincb/master
Browse files Browse the repository at this point in the history
Apply additionalBottomSpace to interactive dismissal
  • Loading branch information
Kaspik authored Mar 25, 2021
2 parents 999423a + 39d8c86 commit e35131b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog
- Master:
- Nothing yet
- Applied `additionalBottomSpace` to interactive dismissal
- 5.3.0
- Allow setting `canBecomeFirstResponder`
- Fix interactive keyboard dismissal lag
Expand Down
17 changes: 16 additions & 1 deletion Sources/KeyboardManager/KeyboardManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,16 @@ open class KeyboardManager: NSObject, UIGestureRecognizerDelegate {
/// A flag that indicates if a portion of the keyboard is visible on the screen
private(set) public var isKeyboardHidden: Bool = true

/// A flag that indicates if the additional bottom space should be applied to
/// the interactive dismissal of the keyboard
public var shouldApplyAdditionBottomSpaceToInteractiveDismissal: Bool = false

// MARK: - Properties [Private]

/// The additional bottom space specified for laying out the input accessory view
/// when binding to it
private var additionalBottomSpace: (() -> CGFloat)?

/// The `NSLayoutConstraintSet` that holds the `inputAccessoryView` to the bottom if its superview
private var constraints: NSLayoutConstraintSet?

Expand Down Expand Up @@ -143,6 +151,7 @@ open class KeyboardManager: NSObject, UIGestureRecognizerDelegate {
fatalError("`inputAccessoryView` must have a superview")
}
self.inputAccessoryView = inputAccessoryView
self.additionalBottomSpace = additionalBottomSpace
inputAccessoryView.translatesAutoresizingMaskIntoConstraints = false
constraints = NSLayoutConstraintSet(
bottom: inputAccessoryView.bottomAnchor.constraint(equalTo: superview.bottomAnchor),
Expand Down Expand Up @@ -287,7 +296,13 @@ open class KeyboardManager: NSObject, UIGestureRecognizerDelegate {
frame.size.height = window.bounds.height - frame.origin.y
keyboardNotification.endFrame = frame

let yCoordinateDirectlyAboveKeyboard = -frame.height
var yCoordinateDirectlyAboveKeyboard = -frame.height

if shouldApplyAdditionBottomSpaceToInteractiveDismissal,
let additionalBottomSpace = additionalBottomSpace {
yCoordinateDirectlyAboveKeyboard -= additionalBottomSpace()
}

/// If a tab bar is shown, letting this number becoming > 0 makes it so the accessoryview disappears below the tab bar. setting the max value to 0 prevents that
let aboveKeyboardAndAboveTabBar = min(0, yCoordinateDirectlyAboveKeyboard)
self.constraints?.bottom?.constant = aboveKeyboardAndAboveTabBar
Expand Down

0 comments on commit e35131b

Please sign in to comment.