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

Commit ed9edd5

Browse files
Merge pull request #214 from diegostamigni/master
Support for disabling keyboard show/hide handling in ASTableView
2 parents 8595dbc + cfbc81f commit ed9edd5

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

Sources/ASCollectionView/ASTableView+Modifiers.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ public extension ASTableView
9797
this.scrollPositionSetter = binding
9898
return this
9999
}
100+
101+
/// Set whether the TableView should handle keyboard appearance and disappearance
102+
func shouldHandleKeyboardAppearance(_ isEnabled: Bool) -> Self
103+
{
104+
var this = self
105+
this.shouldHandleKeyboardAppereance = isEnabled
106+
return this
107+
}
100108
}
101109

102110
// MARK: ASTableView specific header modifiers

Sources/ASCollectionView/Implementation/ASTableView.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public struct ASTableView<SectionID: Hashable>: UIViewControllerRepresentable, C
4545

4646
internal var dodgeKeyboard: Bool = true
4747

48+
internal var shouldHandleKeyboardAppereance: Bool = true
49+
4850
// MARK: Environment variables
4951

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

828+
var shouldHandleKeyboardAppereance: Bool {
829+
parent.shouldHandleKeyboardAppereance
830+
}
831+
826832
var extraKeyboardSpacing: CGFloat = 25
827833
func setupKeyboardObservers()
828834
{
@@ -866,6 +872,7 @@ public struct ASTableView<SectionID: Hashable>: UIViewControllerRepresentable, C
866872

867873
@objc func keyBoardWillShow(notification: Notification)
868874
{
875+
guard shouldHandleKeyboardAppereance else { return }
869876
guard containsFirstResponder()
870877
else
871878
{
@@ -892,6 +899,8 @@ public struct ASTableView<SectionID: Hashable>: UIViewControllerRepresentable, C
892899

893900
@objc func keyBoardWillHide(notification _: Notification)
894901
{
902+
guard shouldHandleKeyboardAppereance else { return }
903+
895904
keyboardFrame = nil
896905
tableViewController?.tableView.layoutIfNeeded()
897906
}

0 commit comments

Comments
 (0)