Skip to content

Commit

Permalink
Fix crash when user taps tab key on external keyboard (#2205)
Browse files Browse the repository at this point in the history
* Fix crash when user taps tab key on external keyboard

* Fix CI Xcode version

* Address comments and fix warning
  • Loading branch information
mats-claassen authored Jan 18, 2022
1 parent 94475e8 commit f3ef384
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ jobs:
runs-on: macOS-latest
strategy:
matrix:
destination: ['platform=iOS Simulator,OS=14.4,name=iPhone 11']
destination: ['platform=iOS Simulator,OS=15.2,name=iPhone 11']

steps:
- uses: actions/checkout@v2
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '13.2.1'
- name: Build and test
run: set -o pipefail && xcodebuild -project Eureka.xcodeproj -scheme 'Eureka' -sdk 'iphonesimulator' -destination "${{ matrix.destination }}" -configuration Debug test | xcpretty
2 changes: 1 addition & 1 deletion Source/Core/Cell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ open class BaseCell: UITableViewCell, BaseCellType {
if let formVC = responder as? FormViewController {
return formVC
}
responder = (responder as? UIResponder)?.next
responder = responder?.next
}
return nil
}
Expand Down
20 changes: 20 additions & 0 deletions Source/Core/Core.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,26 @@ extension FormViewController {
navigateTo(direction: .down)
}

open override func pressesBegan(_ presses: Set<UIPress>, with event: UIPressesEvent?) {
var didHandleEvent = false
for press in presses {
guard let key = press.key,
key.keyCode == .keyboardTab,
!key.modifierFlags.contains(.command) else { continue }
if key.modifierFlags.contains(.shift) {
navigateTo(direction: .up)
} else {
navigateTo(direction: .down)
}
didHandleEvent = true
}

if !didHandleEvent {
// Didn't handle this key press, so pass the event to the next responder.
super.pressesBegan(presses, with: event)
}
}

public func navigateTo(direction: Direction) {
guard let currentCell = tableView?.findFirstResponder()?.formCell() else { return }
guard let currentIndexPath = tableView?.indexPath(for: currentCell) else { return }
Expand Down

0 comments on commit f3ef384

Please sign in to comment.