Skip to content

Commit

Permalink
Added link support to epub reader
Browse files Browse the repository at this point in the history
  • Loading branch information
michalrentka committed Oct 30, 2024
1 parent cb604b6 commit 74832a2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
8 changes: 4 additions & 4 deletions Zotero/Scenes/Detail/DetailCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,10 @@ final class DetailCoordinator: Coordinator {
let controller = SFSafariViewController(url: url.withHttpSchemeIfMissing)
controller.modalPresentationStyle = .fullScreen
// Changes transition to normal modal transition instead of push from right.
self.transitionDelegate = EmptyTransitioningDelegate()
controller.transitioningDelegate = self.transitionDelegate
self.transitionDelegate = nil
self.navigationController?.present(controller, animated: true, completion: nil)
transitionDelegate = EmptyTransitioningDelegate()
controller.transitioningDelegate = transitionDelegate
transitionDelegate = nil
(navigationController?.presentedViewController ?? navigationController)?.present(controller, animated: true, completion: nil)
}

private func showSettings(using presenter: UINavigationController, initialScreen: SettingsCoordinator.InitialScreen? = nil) {
Expand Down
5 changes: 5 additions & 0 deletions Zotero/Scenes/Detail/HTML:EPUB/HtmlEpubCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ protocol HtmlEpubReaderCoordinatorDelegate: AnyObject {
func show(error: HtmlEpubReaderState.Error)
func showToolSettings(tool: AnnotationTool, colorHex: String?, sizeValue: Float?, sender: SourceView, userInterfaceStyle: UIUserInterfaceStyle, valueChanged: @escaping (String?, Float?) -> Void)
func showDocumentChangedAlert(completed: @escaping () -> Void)
func show(url: URL)
}

protocol HtmlEpubSidebarCoordinatorDelegate: AnyObject {
Expand Down Expand Up @@ -344,4 +345,8 @@ extension HtmlEpubCoordinator: HtmlEpubSidebarCoordinatorDelegate {

return viewModel
}

func show(url: URL) {
(parentCoordinator as? DetailCoordinator)?.show(url: url)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ class HtmlEpubDocumentViewController: UIViewController {
}

if let data = state.documentData {
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(5)) {
load(documentData: data)
}
load(documentData: data)
return
}

Expand Down Expand Up @@ -258,6 +256,13 @@ class HtmlEpubDocumentViewController: UIViewController {
}
viewModel.process(action: .setViewState(params))

case "onOpenLink":
guard let params = data["params"] as? [String: Any], let urlString = params["url"] as? String, let url = URL(string: urlString) else {
DDLogWarn("HtmlEpubDocumentViewController: event \(event) missing params - \(message)")
return
}
parentDelegate?.show(url: url)

default:
break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ protocol HtmlEpubReaderContainerDelegate: AnyObject {
var statusBarHeight: CGFloat { get }
var navigationBarHeight: CGFloat { get }
var isSidebarVisible: Bool { get }

func show(url: URL)
}

class HtmlEpubReaderViewController: UIViewController, ParentWithSidebarController {
Expand Down Expand Up @@ -532,7 +534,11 @@ extension HtmlEpubReaderViewController: UIPopoverPresentationControllerDelegate
}
}

extension HtmlEpubReaderViewController: HtmlEpubReaderContainerDelegate {}
extension HtmlEpubReaderViewController: HtmlEpubReaderContainerDelegate {
func show(url: URL) {
coordinatorDelegate?.show(url: url)
}
}

extension HtmlEpubReaderViewController: HtmlEpubAnnotationsDelegate {
func parseAndCacheIfNeededAttributedText(for annotation: HtmlEpubAnnotation, with font: UIFont) -> NSAttributedString? {
Expand Down

0 comments on commit 74832a2

Please sign in to comment.