Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions Sources/KeyboardToolbar/Views/KeyboardToolButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ final class KeyboardToolButton: UIButton {
}
addSubview(backgroundView)
addTarget(self, action: #selector(touchDown(_:event:)), for: .touchDown)
addTarget(self, action: #selector(touchUp), for: .touchUpInside)
addTarget(self, action: #selector(touchUp), for: .touchUpOutside)
addTarget(self, action: #selector(touchUp), for: .touchCancel)
addTarget(self, action: #selector(touchUpInside), for: .touchUpInside)
addTarget(self, action: #selector(touchUpOutside), for: .touchUpOutside)
addTarget(self, action: #selector(touchCancelled), for: .touchCancel)
addTarget(self, action: #selector(touchDragged(_:event:)), for: .touchDragInside)
addTarget(self, action: #selector(touchDragged(_:event:)), for: .touchDragOutside)
setupRepresentativeTool()
Expand Down Expand Up @@ -142,17 +142,31 @@ private extension KeyboardToolButton {
presentToolPicker(with: item.allTools, atSize: .large)
}
}

@objc private func touchUp() {

@objc private func touchUpInside() {
cleanupAfterTouch()
handleTouchUp(insideButton: true)
}
@objc private func touchUpOutside() {
cleanupAfterTouch()
handleTouchUp(insideButton: false)
}
@objc private func touchCancelled() {
cleanupAfterTouch()
}
private func cleanupAfterTouch() {
setContentHidden(false)
cancelToolPickerTimer()
backgroundView.isHidden = false
toolPickerView.removeFromSuperview()
toolPickerBackgroundView.removeFromSuperview()
}
private func handleTouchUp(insideButton: Bool) {
if let highlightedIndex = toolPickerView.highlightedIndex {
let tool = item.allTools[highlightedIndex]
tool.performAction()
} else {
} else if insideButton {
// If not using the picker menu, we should only act on a press if still inside the main button
item.representativeTool.performAction()
}
}
Expand Down