Skip to content
This repository has been archived by the owner on Nov 4, 2022. It is now read-only.

Commit

Permalink
Merge pull request #214 from diegostamigni/master
Browse files Browse the repository at this point in the history
Support for disabling keyboard show/hide handling in ASTableView
  • Loading branch information
apptekstudios authored Jun 26, 2021
2 parents 8595dbc + cfbc81f commit ed9edd5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Sources/ASCollectionView/ASTableView+Modifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ public extension ASTableView
this.scrollPositionSetter = binding
return this
}

/// Set whether the TableView should handle keyboard appearance and disappearance
func shouldHandleKeyboardAppearance(_ isEnabled: Bool) -> Self
{
var this = self
this.shouldHandleKeyboardAppereance = isEnabled
return this
}
}

// MARK: ASTableView specific header modifiers
Expand Down
9 changes: 9 additions & 0 deletions Sources/ASCollectionView/Implementation/ASTableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public struct ASTableView<SectionID: Hashable>: UIViewControllerRepresentable, C

internal var dodgeKeyboard: Bool = true

internal var shouldHandleKeyboardAppereance: Bool = true

// MARK: Environment variables

@Environment(\.invalidateCellLayout) var invalidateParentCellLayout // Call this if using content size binding (nested inside another ASCollectionView)
Expand Down Expand Up @@ -823,6 +825,10 @@ public struct ASTableView<SectionID: Hashable>: UIViewControllerRepresentable, C
}
}

var shouldHandleKeyboardAppereance: Bool {
parent.shouldHandleKeyboardAppereance
}

var extraKeyboardSpacing: CGFloat = 25
func setupKeyboardObservers()
{
Expand Down Expand Up @@ -866,6 +872,7 @@ public struct ASTableView<SectionID: Hashable>: UIViewControllerRepresentable, C

@objc func keyBoardWillShow(notification: Notification)
{
guard shouldHandleKeyboardAppereance else { return }
guard containsFirstResponder()
else
{
Expand All @@ -892,6 +899,8 @@ public struct ASTableView<SectionID: Hashable>: UIViewControllerRepresentable, C

@objc func keyBoardWillHide(notification _: Notification)
{
guard shouldHandleKeyboardAppereance else { return }

keyboardFrame = nil
tableViewController?.tableView.layoutIfNeeded()
}
Expand Down

0 comments on commit ed9edd5

Please sign in to comment.