From 78e93d99370848430e58a53bd5950b39223f067c Mon Sep 17 00:00:00 2001 From: Balazs Perlaki-Horvath Date: Sun, 28 Jul 2024 14:48:31 +0200 Subject: [PATCH 1/2] Add extra padding for zoomed in --- Model/Utilities/Javascript.swift | 29 +++++++++++++++++++++++++++++ Views/BuildingBlocks/WebView.swift | 5 ++++- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 Model/Utilities/Javascript.swift diff --git a/Model/Utilities/Javascript.swift b/Model/Utilities/Javascript.swift new file mode 100644 index 000000000..d7f879861 --- /dev/null +++ b/Model/Utilities/Javascript.swift @@ -0,0 +1,29 @@ +// This file is part of Kiwix for iOS & macOS. +// +// Kiwix is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// any later version. +// +// Kiwix is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Kiwix; If not, see https://www.gnu.org/licenses/. + +import Foundation + +enum CSSUnit: String { + case em +} + +enum Javascript { + static func webkitPadding(size: UInt8, unit: CSSUnit = .em) -> String { + let paddingTemplate = "document.getElementsByTagName('body')[0].style.webkit%@='%d%@'" + return ["PaddingStart", "PaddingEnd", "PaddingBefore", "PaddingAfter"].map { property in + String(format: paddingTemplate, property, size, unit.rawValue) + }.joined(separator: "; ") + } +} diff --git a/Views/BuildingBlocks/WebView.swift b/Views/BuildingBlocks/WebView.swift index c239df23c..2e80eab2a 100644 --- a/Views/BuildingBlocks/WebView.swift +++ b/Views/BuildingBlocks/WebView.swift @@ -74,11 +74,14 @@ final class WebViewController: UIViewController { private var layoutCancellable: AnyCancellable? private var currentScrollViewOffset: CGFloat = 0.0 private var compactViewNavigationController: UINavigationController? - + private static let webkitPaddingJS: String = Javascript.webkitPadding(size: 1, unit: .em) + init(webView: WKWebView) { self.webView = webView pageZoomObserver = Defaults.observe(.webViewPageZoom) { change in webView.adjustTextSize(pageZoom: change.newValue) + // adjust padding, as with large zoom in the content is too close to the sides + webView.evaluateJavaScript(Self.webkitPaddingJS, completionHandler: nil) } super.init(nibName: nil, bundle: nil) } From b6ac11dde5deae8ad3d3c950036727b06fb56896 Mon Sep 17 00:00:00 2001 From: Balazs Perlaki-Horvath Date: Sun, 28 Jul 2024 15:01:28 +0200 Subject: [PATCH 2/2] Fixlint --- Model/Utilities/Javascript.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Model/Utilities/Javascript.swift b/Model/Utilities/Javascript.swift index d7f879861..5f9c04050 100644 --- a/Model/Utilities/Javascript.swift +++ b/Model/Utilities/Javascript.swift @@ -16,6 +16,7 @@ import Foundation enum CSSUnit: String { + // swiftlint:disable:next identifier_name case em }