Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when user taps tab key on external keyboard #2205

Merged
merged 3 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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']

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this updates your framework to be built against iOS 15.2 and Xcode version 13.2.1?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but just for the tests


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
21 changes: 21 additions & 0 deletions Source/Core/Core.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,27 @@ 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 else { continue }
if key.keyCode == .keyboardTab,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could add to existing or create another guard clause to avoid nesting.

Suggested change
if key.keyCode == .keyboardTab,
guard key.keyCode == .keyboardTab, key.modifiedFlags.contains(.command) else { continue }
// Remaining code

!key.modifierFlags.contains(.command) {
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