From 94ea9ec17e20d3ac9654e1bd6b490dd3167f98da Mon Sep 17 00:00:00 2001 From: Miltiadis Vasilakis Date: Tue, 3 Sep 2024 16:35:02 +0300 Subject: [PATCH 1/5] Improve code --- .../PDF/Views/PDFDocumentViewController.swift | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/Zotero/Scenes/Detail/PDF/Views/PDFDocumentViewController.swift b/Zotero/Scenes/Detail/PDF/Views/PDFDocumentViewController.swift index c9070e64f..6e3499309 100644 --- a/Zotero/Scenes/Detail/PDF/Views/PDFDocumentViewController.swift +++ b/Zotero/Scenes/Detail/PDF/Views/PDFDocumentViewController.swift @@ -688,7 +688,7 @@ extension PDFDocumentViewController: PDFViewControllerDelegate { } func pdfViewController(_ sender: PDFViewController, menuForText glyphs: GlyphSequence, onPageView pageView: PDFPageView, appearance: EditMenuAppearance, suggestedMenu: UIMenu) -> UIMenu { - return self.filterActions( + return filterActions( forMenu: suggestedMenu, predicate: { menuId, action -> UIAction? in switch menuId { @@ -709,27 +709,27 @@ extension PDFDocumentViewController: PDFViewControllerDelegate { case .share: guard action.identifier == .PSPDFKit.share else { return nil } return action.replacing(handler: { [weak self] _ in - guard let view = self?.pdfController?.view else { return } - self?.coordinatorDelegate?.share(text: glyphs.text, rect: glyphs.boundingBox, view: view) + guard let self, let view = pdfController?.view else { return } + coordinatorDelegate?.share(text: glyphs.text, rect: glyphs.boundingBox, view: view) }) case .pspdfkitActions: switch action.identifier { case .PSPDFKit.define: return action.replacing(title: L10n.lookUp, handler: { [weak self] _ in - guard let self, let view = self.pdfController?.view else { return } - self.coordinatorDelegate?.lookup( + guard let self, let view = pdfController?.view else { return } + coordinatorDelegate?.lookup( text: glyphs.text, rect: glyphs.boundingBox, view: view, - userInterfaceStyle: self.viewModel.state.settings.appearanceMode.userInterfaceStyle + userInterfaceStyle: viewModel.state.settings.appearanceMode.userInterfaceStyle ) }) case .PSPDFKit.searchDocument: return action.replacing(handler: { [weak self] _ in - guard let self, let pdfController = self.pdfController else { return } - self.parentDelegate?.showSearch(pdfController: pdfController, text: glyphs.text) + guard let self, let pdfController else { return } + parentDelegate?.showSearch(pdfController: pdfController, text: glyphs.text) }) default: @@ -740,7 +740,7 @@ extension PDFDocumentViewController: PDFViewControllerDelegate { let rects = pageView.selectionView.selectionRects.map({ pageView.convert($0.cgRectValue, to: pageView.pdfCoordinateSpace) }) return action.replacing(title: L10n.Pdf.highlight, handler: { [weak self] _ in guard let self else { return } - self.viewModel.process(action: .createHighlight(pageIndex: pageView.pageIndex, rects: rects)) + viewModel.process(action: .createHighlight(pageIndex: pageView.pageIndex, rects: rects)) pageView.selectionView.selectedGlyphs = nil }) @@ -755,7 +755,7 @@ extension PDFDocumentViewController: PDFViewControllerDelegate { return [ UIAction(title: L10n.Pdf.highlight, handler: { [weak self] _ in guard let self else { return } - self.viewModel.process(action: .createHighlight(pageIndex: pageView.pageIndex, rects: rects)) + viewModel.process(action: .createHighlight(pageIndex: pageView.pageIndex, rects: rects)) pageView.selectionView.selectedGlyphs = nil }) ] @@ -765,27 +765,27 @@ extension PDFDocumentViewController: PDFViewControllerDelegate { } } ) - } - private func filterActions(forMenu menu: UIMenu, predicate: (UIMenu.Identifier, UIAction) -> UIAction?, populatingEmptyMenu: (UIMenu) -> [UIAction]?) -> UIMenu { - return menu.replacingChildren(menu.children.compactMap { element in - if let action = element as? UIAction { - if let action = predicate(menu.identifier, action) { - return action - } else { - return nil - } - } else if let menu = element as? UIMenu { - if menu.children.isEmpty { - return populatingEmptyMenu(menu).flatMap({ menu.replacingChildren($0) }) ?? menu + func filterActions(forMenu menu: UIMenu, predicate: (UIMenu.Identifier, UIAction) -> UIAction?, populatingEmptyMenu: (UIMenu) -> [UIAction]?) -> UIMenu { + return menu.replacingChildren(menu.children.compactMap { element -> UIMenuElement? in + if let action = element as? UIAction { + if let action = predicate(menu.identifier, action) { + return action + } else { + return nil + } + } else if let menu = element as? UIMenu { + if menu.children.isEmpty { + return populatingEmptyMenu(menu).flatMap({ menu.replacingChildren($0) }) ?? menu + } else { + // Filter children of submenus recursively. + return filterActions(forMenu: menu, predicate: predicate, populatingEmptyMenu: populatingEmptyMenu) + } } else { - // Filter children of submenus recursively. - return self.filterActions(forMenu: menu, predicate: predicate, populatingEmptyMenu: populatingEmptyMenu) + return element } - } else { - return element - } - }) + }) + } } func pdfViewController(_ pdfController: PDFViewController, didSelectText text: String, with glyphs: [Glyph], at rect: CGRect, on pageView: PDFPageView) { From 9866dcf0819185157e71e1854e7c95bf5d93bf49 Mon Sep 17 00:00:00 2001 From: Miltiadis Vasilakis Date: Tue, 3 Sep 2024 17:16:05 +0300 Subject: [PATCH 2/5] Fix coordinates for lookup/share popup from selected PDF text --- .../Detail/PDF/Views/PDFDocumentViewController.swift | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Zotero/Scenes/Detail/PDF/Views/PDFDocumentViewController.swift b/Zotero/Scenes/Detail/PDF/Views/PDFDocumentViewController.swift index 6e3499309..89bd807d9 100644 --- a/Zotero/Scenes/Detail/PDF/Views/PDFDocumentViewController.swift +++ b/Zotero/Scenes/Detail/PDF/Views/PDFDocumentViewController.swift @@ -709,19 +709,18 @@ extension PDFDocumentViewController: PDFViewControllerDelegate { case .share: guard action.identifier == .PSPDFKit.share else { return nil } return action.replacing(handler: { [weak self] _ in - guard let self, let view = pdfController?.view else { return } - coordinatorDelegate?.share(text: glyphs.text, rect: glyphs.boundingBox, view: view) + self?.coordinatorDelegate?.share(text: glyphs.text, rect: pageView.convert(glyphs.boundingBox, from: pageView.pdfCoordinateSpace), view: pageView) }) case .pspdfkitActions: switch action.identifier { case .PSPDFKit.define: return action.replacing(title: L10n.lookUp, handler: { [weak self] _ in - guard let self, let view = pdfController?.view else { return } + guard let self else { return } coordinatorDelegate?.lookup( text: glyphs.text, - rect: glyphs.boundingBox, - view: view, + rect: pageView.convert(glyphs.boundingBox, from: pageView.pdfCoordinateSpace), + view: pageView, userInterfaceStyle: viewModel.state.settings.appearanceMode.userInterfaceStyle ) }) From b92a5f76bfbe363ad2bf3630fdc91313f146b8aa Mon Sep 17 00:00:00 2001 From: Miltiadis Vasilakis Date: Tue, 3 Sep 2024 18:23:37 +0300 Subject: [PATCH 3/5] Add PDF text selection menu action for creating underline annotation --- .../Detail/PDF/Models/PDFReaderAction.swift | 1 + .../ViewModels/PDFReaderActionHandler.swift | 27 +++++----- .../PDF/Views/PDFDocumentViewController.swift | 49 +++++++++++++------ 3 files changed, 49 insertions(+), 28 deletions(-) diff --git a/Zotero/Scenes/Detail/PDF/Models/PDFReaderAction.swift b/Zotero/Scenes/Detail/PDF/Models/PDFReaderAction.swift index d1ce1b3df..33666ccc5 100644 --- a/Zotero/Scenes/Detail/PDF/Models/PDFReaderAction.swift +++ b/Zotero/Scenes/Detail/PDF/Models/PDFReaderAction.swift @@ -44,6 +44,7 @@ enum PDFReaderAction { case createNote(pageIndex: PageIndex, origin: CGPoint) case createImage(pageIndex: PageIndex, origin: CGPoint) case createHighlight(pageIndex: PageIndex, rects: [CGRect]) + case createUnderline(pageIndex: PageIndex, rects: [CGRect]) case parseAndCacheText(key: String, text: String, font: UIFont) case parseAndCacheComment(key: String, comment: String) case setComment(key: String, comment: NSAttributedString) diff --git a/Zotero/Scenes/Detail/PDF/ViewModels/PDFReaderActionHandler.swift b/Zotero/Scenes/Detail/PDF/ViewModels/PDFReaderActionHandler.swift index f8e6181b9..504c73178 100644 --- a/Zotero/Scenes/Detail/PDF/ViewModels/PDFReaderActionHandler.swift +++ b/Zotero/Scenes/Detail/PDF/ViewModels/PDFReaderActionHandler.swift @@ -226,7 +226,10 @@ final class PDFReaderActionHandler: ViewModelActionHandler, BackgroundDbProcessi addNote(onPage: pageIndex, origin: origin, in: viewModel) case .createHighlight(let pageIndex, let rects): - addHighlight(onPage: pageIndex, rects: rects, in: viewModel) + addHighlightOrUnderline(isHighlight: true, onPage: pageIndex, rects: rects, in: viewModel) + + case .createUnderline(let pageIndex, let rects): + addHighlightOrUnderline(isHighlight: false, onPage: pageIndex, rects: rects, in: viewModel) case .setVisiblePage(let page, let userActionFromDocument, let fromThumbnailList): set(page: page, userActionFromDocument: userActionFromDocument, fromThumbnailList: fromThumbnailList, in: viewModel) @@ -1182,22 +1185,22 @@ final class PDFReaderActionHandler: ViewModelActionHandler, BackgroundDbProcessi } } - private func addHighlight(onPage pageIndex: PageIndex, rects: [CGRect], in viewModel: ViewModel) { - guard let activeColor = viewModel.state.toolColors[tool(from: .highlight)] else { return } + private func addHighlightOrUnderline(isHighlight: Bool, onPage pageIndex: PageIndex, rects: [CGRect], in viewModel: ViewModel) { + guard let activeColor = viewModel.state.toolColors[tool(from: isHighlight ? .highlight : .underline)] else { return } let (color, alpha, blendMode) = AnnotationColorGenerator.color(from: activeColor, isHighlight: true, userInterfaceStyle: viewModel.state.interfaceStyle) - let highlight = HighlightAnnotation() - highlight.rects = rects - highlight.boundingBox = AnnotationBoundingBoxCalculator.boundingBox(from: rects) - highlight.alpha = alpha - highlight.color = color + let annotation = isHighlight ? HighlightAnnotation() : UnderlineAnnotation() + annotation.rects = rects + annotation.boundingBox = AnnotationBoundingBoxCalculator.boundingBox(from: rects) + annotation.alpha = alpha + annotation.color = color if let blendMode { - highlight.blendMode = blendMode + annotation.blendMode = blendMode } - highlight.pageIndex = pageIndex + annotation.pageIndex = pageIndex - viewModel.state.document.undoController.recordCommand(named: nil, adding: [highlight]) { - viewModel.state.document.add(annotations: [highlight], options: nil) + viewModel.state.document.undoController.recordCommand(named: nil, adding: [annotation]) { + viewModel.state.document.add(annotations: [annotation], options: nil) } } diff --git a/Zotero/Scenes/Detail/PDF/Views/PDFDocumentViewController.swift b/Zotero/Scenes/Detail/PDF/Views/PDFDocumentViewController.swift index 89bd807d9..dca778c00 100644 --- a/Zotero/Scenes/Detail/PDF/Views/PDFDocumentViewController.swift +++ b/Zotero/Scenes/Detail/PDF/Views/PDFDocumentViewController.swift @@ -690,7 +690,7 @@ extension PDFDocumentViewController: PDFViewControllerDelegate { func pdfViewController(_ sender: PDFViewController, menuForText glyphs: GlyphSequence, onPageView pageView: PDFPageView, appearance: EditMenuAppearance, suggestedMenu: UIMenu) -> UIMenu { return filterActions( forMenu: suggestedMenu, - predicate: { menuId, action -> UIAction? in + predicate: { menuId, action -> UIMenuElement? in switch menuId { case .standardEdit: switch action.identifier { @@ -736,12 +736,11 @@ extension PDFDocumentViewController: PDFViewControllerDelegate { } case .PSPDFKit.annotate: - let rects = pageView.selectionView.selectionRects.map({ pageView.convert($0.cgRectValue, to: pageView.pdfCoordinateSpace) }) - return action.replacing(title: L10n.Pdf.highlight, handler: { [weak self] _ in - guard let self else { return } - viewModel.process(action: .createHighlight(pageIndex: pageView.pageIndex, rects: rects)) - pageView.selectionView.selectedGlyphs = nil - }) + let actions = [ + action.replacing(title: L10n.Pdf.highlight, handler: createHighlightActionHandler(for: self, pageView: pageView)), + UIAction(title: L10n.Pdf.underline, identifier: .underline, handler: createUnderlineActionHandler(for: self, pageView: pageView)) + ] + return UIMenu(options: [.displayInline], children: actions) default: return action @@ -750,13 +749,9 @@ extension PDFDocumentViewController: PDFViewControllerDelegate { populatingEmptyMenu: { menu -> [UIAction]? in switch menu.identifier { case .PSPDFKit.annotate: - let rects = pageView.selectionView.selectionRects.map({ pageView.convert($0.cgRectValue, to: pageView.pdfCoordinateSpace) }) return [ - UIAction(title: L10n.Pdf.highlight, handler: { [weak self] _ in - guard let self else { return } - viewModel.process(action: .createHighlight(pageIndex: pageView.pageIndex, rects: rects)) - pageView.selectionView.selectedGlyphs = nil - }) + UIAction(title: L10n.Pdf.highlight, handler: createHighlightActionHandler(for: self, pageView: pageView)), + UIAction(title: L10n.Pdf.underline, identifier: .underline, handler: createUnderlineActionHandler(for: self, pageView: pageView)) ] default: @@ -765,11 +760,11 @@ extension PDFDocumentViewController: PDFViewControllerDelegate { } ) - func filterActions(forMenu menu: UIMenu, predicate: (UIMenu.Identifier, UIAction) -> UIAction?, populatingEmptyMenu: (UIMenu) -> [UIAction]?) -> UIMenu { + func filterActions(forMenu menu: UIMenu, predicate: (UIMenu.Identifier, UIAction) -> UIMenuElement?, populatingEmptyMenu: (UIMenu) -> [UIAction]?) -> UIMenu { return menu.replacingChildren(menu.children.compactMap { element -> UIMenuElement? in if let action = element as? UIAction { - if let action = predicate(menu.identifier, action) { - return action + if let element = predicate(menu.identifier, action) { + return element } else { return nil } @@ -785,6 +780,24 @@ extension PDFDocumentViewController: PDFViewControllerDelegate { } }) } + + func createHighlightActionHandler(for documentViewController: PDFDocumentViewController, pageView: PDFPageView) -> UIActionHandler { + let rects = pageView.selectionView.selectionRects.map({ pageView.convert($0.cgRectValue, to: pageView.pdfCoordinateSpace) }) + return { [weak documentViewController] _ in + guard let documentViewController else { return } + documentViewController.viewModel.process(action: .createHighlight(pageIndex: pageView.pageIndex, rects: rects)) + pageView.selectionView.selectedGlyphs = nil + } + } + + func createUnderlineActionHandler(for documentViewController: PDFDocumentViewController, pageView: PDFPageView) -> UIActionHandler { + let rects = pageView.selectionView.selectionRects.map({ pageView.convert($0.cgRectValue, to: pageView.pdfCoordinateSpace) }) + return { [weak documentViewController] _ in + guard let documentViewController else { return } + documentViewController.viewModel.process(action: .createUnderline(pageIndex: pageView.pageIndex, rects: rects)) + pageView.selectionView.selectedGlyphs = nil + } + } } func pdfViewController(_ pdfController: PDFViewController, didSelectText text: String, with glyphs: [Glyph], at rect: CGRect, on pageView: PDFPageView) { @@ -1037,3 +1050,7 @@ extension UIAction { ) } } + +extension UIAction.Identifier { + fileprivate static let underline = UIAction.Identifier(rawValue: "org.zotero.menu") +} From e4b814e336917f8c3185dc44fe779a90710b739e Mon Sep 17 00:00:00 2001 From: Miltiadis Vasilakis Date: Tue, 3 Sep 2024 19:10:47 +0300 Subject: [PATCH 4/5] Improve code --- .../PDF/Views/PDFDocumentViewController.swift | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Zotero/Scenes/Detail/PDF/Views/PDFDocumentViewController.swift b/Zotero/Scenes/Detail/PDF/Views/PDFDocumentViewController.swift index dca778c00..a23f470ae 100644 --- a/Zotero/Scenes/Detail/PDF/Views/PDFDocumentViewController.swift +++ b/Zotero/Scenes/Detail/PDF/Views/PDFDocumentViewController.swift @@ -737,8 +737,8 @@ extension PDFDocumentViewController: PDFViewControllerDelegate { case .PSPDFKit.annotate: let actions = [ - action.replacing(title: L10n.Pdf.highlight, handler: createHighlightActionHandler(for: self, pageView: pageView)), - UIAction(title: L10n.Pdf.underline, identifier: .underline, handler: createUnderlineActionHandler(for: self, pageView: pageView)) + action.replacing(title: L10n.Pdf.highlight, handler: createHighlightActionHandler(for: pageView, in: viewModel)), + UIAction(title: L10n.Pdf.underline, identifier: .underline, handler: createUnderlineActionHandler(for: pageView, in: viewModel)) ] return UIMenu(options: [.displayInline], children: actions) @@ -750,8 +750,8 @@ extension PDFDocumentViewController: PDFViewControllerDelegate { switch menu.identifier { case .PSPDFKit.annotate: return [ - UIAction(title: L10n.Pdf.highlight, handler: createHighlightActionHandler(for: self, pageView: pageView)), - UIAction(title: L10n.Pdf.underline, identifier: .underline, handler: createUnderlineActionHandler(for: self, pageView: pageView)) + UIAction(title: L10n.Pdf.highlight, handler: createHighlightActionHandler(for: pageView, in: viewModel)), + UIAction(title: L10n.Pdf.underline, identifier: .underline, handler: createUnderlineActionHandler(for: pageView, in: viewModel)) ] default: @@ -781,20 +781,20 @@ extension PDFDocumentViewController: PDFViewControllerDelegate { }) } - func createHighlightActionHandler(for documentViewController: PDFDocumentViewController, pageView: PDFPageView) -> UIActionHandler { + func createHighlightActionHandler(for pageView: PDFPageView, in viewModel: ViewModel) -> UIActionHandler { let rects = pageView.selectionView.selectionRects.map({ pageView.convert($0.cgRectValue, to: pageView.pdfCoordinateSpace) }) - return { [weak documentViewController] _ in - guard let documentViewController else { return } - documentViewController.viewModel.process(action: .createHighlight(pageIndex: pageView.pageIndex, rects: rects)) + return { [weak viewModel] _ in + guard let viewModel else { return } + viewModel.process(action: .createHighlight(pageIndex: pageView.pageIndex, rects: rects)) pageView.selectionView.selectedGlyphs = nil } } - func createUnderlineActionHandler(for documentViewController: PDFDocumentViewController, pageView: PDFPageView) -> UIActionHandler { + func createUnderlineActionHandler(for pageView: PDFPageView, in viewModel: ViewModel) -> UIActionHandler { let rects = pageView.selectionView.selectionRects.map({ pageView.convert($0.cgRectValue, to: pageView.pdfCoordinateSpace) }) - return { [weak documentViewController] _ in - guard let documentViewController else { return } - documentViewController.viewModel.process(action: .createUnderline(pageIndex: pageView.pageIndex, rects: rects)) + return { [weak viewModel] _ in + guard let viewModel else { return } + viewModel.process(action: .createUnderline(pageIndex: pageView.pageIndex, rects: rects)) pageView.selectionView.selectedGlyphs = nil } } From 5356179c6077263e421e1a886447073e4f3b1593 Mon Sep 17 00:00:00 2001 From: Miltiadis Vasilakis Date: Tue, 3 Sep 2024 19:46:49 +0300 Subject: [PATCH 5/5] Use PDF reader's style for text selection lookup/share --- .../Architecture/Coordinator.swift | 19 +++++++++++++++++-- Zotero/Scenes/Detail/PDF/PDFCoordinator.swift | 10 ++++++---- .../PDF/Views/PDFDocumentViewController.swift | 8 +++++++- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/Zotero/Controllers/Architecture/Coordinator.swift b/Zotero/Controllers/Architecture/Coordinator.swift index e0c8f1725..8bf3dd36a 100644 --- a/Zotero/Controllers/Architecture/Coordinator.swift +++ b/Zotero/Controllers/Architecture/Coordinator.swift @@ -20,7 +20,13 @@ protocol Coordinator: AnyObject { func start(animated: Bool) func childDidFinish(_ child: Coordinator) - func share(item: Any, sourceView: SourceView, presenter: UIViewController?, completionWithItemsHandler: UIActivityViewController.CompletionWithItemsHandler?) + func share( + item: Any, + sourceView: SourceView, + presenter: UIViewController?, + userInterfaceStyle: UIUserInterfaceStyle?, + completionWithItemsHandler: UIActivityViewController.CompletionWithItemsHandler? + ) } extension Coordinator { @@ -36,8 +42,17 @@ extension Coordinator { } } - func share(item: Any, sourceView: SourceView, presenter: UIViewController? = nil, completionWithItemsHandler: UIActivityViewController.CompletionWithItemsHandler? = nil) { + func share( + item: Any, + sourceView: SourceView, + presenter: UIViewController? = nil, + userInterfaceStyle: UIUserInterfaceStyle? = nil, + completionWithItemsHandler: UIActivityViewController.CompletionWithItemsHandler? = nil + ) { let controller = UIActivityViewController(activityItems: [item], applicationActivities: nil) + if let userInterfaceStyle { + controller.overrideUserInterfaceStyle = userInterfaceStyle + } controller.modalPresentationStyle = .pageSheet controller.completionWithItemsHandler = completionWithItemsHandler diff --git a/Zotero/Scenes/Detail/PDF/PDFCoordinator.swift b/Zotero/Scenes/Detail/PDF/PDFCoordinator.swift index 8895da2aa..24ef90f66 100644 --- a/Zotero/Scenes/Detail/PDF/PDFCoordinator.swift +++ b/Zotero/Scenes/Detail/PDF/PDFCoordinator.swift @@ -26,7 +26,7 @@ protocol PdfReaderCoordinatorDelegate: AnyObject { func show(error: PDFReaderState.Error) func show(error: PDFDocumentExporter.Error) func share(url: URL, barButton: UIBarButtonItem) - func share(text: String, rect: CGRect, view: UIView) + func share(text: String, rect: CGRect, view: UIView, userInterfaceStyle: UIUserInterfaceStyle) func lookup(text: String, rect: CGRect, view: UIView, userInterfaceStyle: UIUserInterfaceStyle) func showDeletedAlertForPdf(completion: @escaping (Bool) -> Void) func showSettings(with settings: PDFSettings, sender: UIBarButtonItem) -> ViewModel @@ -289,13 +289,15 @@ extension PDFCoordinator: PdfReaderCoordinatorDelegate { self.share(item: url, sourceView: .item(barButton)) } - func share(text: String, rect: CGRect, view: UIView) { - self.share(item: text, sourceView: .view(view, rect)) + func share(text: String, rect: CGRect, view: UIView, userInterfaceStyle: UIUserInterfaceStyle) { + self.share(item: text, sourceView: .view(view, rect), userInterfaceStyle: userInterfaceStyle) } func lookup(text: String, rect: CGRect, view: UIView, userInterfaceStyle: UIUserInterfaceStyle) { DDLogInfo("PDFCoordinator: show lookup") - let controller = UIReferenceLibraryViewController(term: text) + // When presented as a popover, UIReferenceLibraryViewController ignores overrideUserInterfaceStyle, so we wrap it in a navigation controller to force it. + let controller = UINavigationController(rootViewController: UIReferenceLibraryViewController(term: text)) + controller.setNavigationBarHidden(true, animated: false) controller.overrideUserInterfaceStyle = userInterfaceStyle controller.modalPresentationStyle = .popover controller.popoverPresentationController?.sourceView = view diff --git a/Zotero/Scenes/Detail/PDF/Views/PDFDocumentViewController.swift b/Zotero/Scenes/Detail/PDF/Views/PDFDocumentViewController.swift index a23f470ae..59478582f 100644 --- a/Zotero/Scenes/Detail/PDF/Views/PDFDocumentViewController.swift +++ b/Zotero/Scenes/Detail/PDF/Views/PDFDocumentViewController.swift @@ -709,7 +709,13 @@ extension PDFDocumentViewController: PDFViewControllerDelegate { case .share: guard action.identifier == .PSPDFKit.share else { return nil } return action.replacing(handler: { [weak self] _ in - self?.coordinatorDelegate?.share(text: glyphs.text, rect: pageView.convert(glyphs.boundingBox, from: pageView.pdfCoordinateSpace), view: pageView) + guard let self else { return } + coordinatorDelegate?.share( + text: glyphs.text, + rect: pageView.convert(glyphs.boundingBox, from: pageView.pdfCoordinateSpace), + view: pageView, + userInterfaceStyle: viewModel.state.settings.appearanceMode.userInterfaceStyle + ) }) case .pspdfkitActions: