Reader Mode

This commit is contained in:
James Magahern
2021-02-15 22:34:05 -08:00
parent 6611e381a2
commit 2b5475d7f8
9 changed files with 2474 additions and 4 deletions

View File

@@ -240,6 +240,23 @@ class BrowserViewController: UIViewController, WKNavigationDelegate, WKUIDelegat
documentControls.navigationControlView.forwardButton.isEnabled = webView.canGoForward
}))
// Reader mode
documentControls.readabilityView.addAction(UIAction { [unowned self] _ in
tab.bridge.parseDocumentForReaderMode { string in
DispatchQueue.main.async {
documentControls.dismiss(animated: true, completion: nil)
let readableViewController = ReaderViewController(readableHTMLString: string, baseURL: tab.bridge.webView.url)
readableViewController.title = tab.bridge.webView.title
readableViewController.darkModeEnabled = tab.bridge.darkModeEnabled
readableViewController.delegate = self
let navigationController = UINavigationController(rootViewController: readableViewController)
present(navigationController, animated: true, completion: nil)
}
}
}, for: .touchUpInside)
present(documentControls, animated: true, completion: nil)
}), for: .touchUpInside)
@@ -708,3 +725,10 @@ class BrowserViewController: UIViewController, WKNavigationDelegate, WKUIDelegat
tab.webView._viewScale -= 0.10
}
}
extension BrowserViewController: ReaderViewControllerDelegate
{
func readerViewController(_ reader: ReaderViewController, didRequestNavigationToURL navigationURL: URL) {
tab.beginLoadingURL(navigationURL)
}
}