From 94645b7e9a7b9e07fc0b3e268880173488f7447f Mon Sep 17 00:00:00 2001 From: Miltiadis Vasilakis Date: Thu, 27 Feb 2025 16:18:15 +0200 Subject: [PATCH] Support pencil squeeze interaction --- .../PDF/Views/PDFDocumentViewController.swift | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/Zotero/Scenes/Detail/PDF/Views/PDFDocumentViewController.swift b/Zotero/Scenes/Detail/PDF/Views/PDFDocumentViewController.swift index ed071c388..90eb6e2e7 100644 --- a/Zotero/Scenes/Detail/PDF/Views/PDFDocumentViewController.swift +++ b/Zotero/Scenes/Detail/PDF/Views/PDFDocumentViewController.swift @@ -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) } } @@ -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 @@ -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 {