Skip to content

Commit

Permalink
Support pencil squeeze interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
mvasilak committed Feb 27, 2025
1 parent 0b13130 commit 94645b7
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions Zotero/Scenes/Detail/PDF/Views/PDFDocumentViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -933,18 +933,16 @@ extension PDFDocumentViewController: AnnotationStateManagerDelegate {
}

extension PDFDocumentViewController: UIPencilInteractionDelegate {
func pencilInteractionDidTap(_ interaction: UIPencilInteraction) {
guard self.parentDelegate?.isToolbarVisible == true else { return }

switch UIPencilInteraction.preferredTapAction {
private func process(action: UIPencilPreferredAction) {
switch action {
case .switchEraser:
if let tool = self.pdfController?.annotationStateManager.state {
if let tool = pdfController?.annotationStateManager.state {
if tool != .eraser {
self.toggle(annotationTool: .eraser, color: nil, tappedWithStylus: true)
toggle(annotationTool: .eraser, color: nil, tappedWithStylus: true)
} else {
let previous = (PDFDocumentViewController.toolHistory.last(where: { $0 != .eraser }) ?? nil) ?? .ink
let color = self.viewModel.state.toolColors[previous]
self.toggle(annotationTool: previous, color: color, tappedWithStylus: true)
let color = viewModel.state.toolColors[previous]
toggle(annotationTool: previous, color: color, tappedWithStylus: true)
}
}

Expand All @@ -961,7 +959,7 @@ extension PDFDocumentViewController: UIPencilInteractionDelegate {
toggle(annotationTool: previous, color: color, tappedWithStylus: true)

case .showColorPalette, .showInkAttributes, .showContextualPalette:
self.parentDelegate?.showToolOptions()
parentDelegate?.showToolOptions()

case .runSystemShortcut, .ignore:
break
Expand All @@ -970,6 +968,17 @@ extension PDFDocumentViewController: UIPencilInteractionDelegate {
break
}
}

func pencilInteractionDidTap(_ interaction: UIPencilInteraction) {
guard self.parentDelegate?.isToolbarVisible == true else { return }
process(action: UIPencilInteraction.preferredTapAction)
}

@available(iOS 17.5, *)
func pencilInteraction(_ interaction: UIPencilInteraction, didReceiveSqueeze squeeze: UIPencilInteraction.Squeeze) {
guard self.parentDelegate?.isToolbarVisible == true else { return }
process(action: UIPencilInteraction.preferredTapAction)
}
}

extension PDFDocumentViewController: UIPopoverPresentationControllerDelegate {
Expand Down

0 comments on commit 94645b7

Please sign in to comment.