Skip to content

Commit 78e93d9

Browse files
committed
Add extra padding for zoomed in
1 parent 99356e3 commit 78e93d9

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

Model/Utilities/Javascript.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// This file is part of Kiwix for iOS & macOS.
2+
//
3+
// Kiwix is free software; you can redistribute it and/or modify it
4+
// under the terms of the GNU General Public License as published by
5+
// the Free Software Foundation; either version 3 of the License, or
6+
// any later version.
7+
//
8+
// Kiwix is distributed in the hope that it will be useful, but
9+
// WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+
// General Public License for more details.
12+
//
13+
// You should have received a copy of the GNU General Public License
14+
// along with Kiwix; If not, see https://www.gnu.org/licenses/.
15+
16+
import Foundation
17+
18+
enum CSSUnit: String {
19+
case em
20+
}
21+
22+
enum Javascript {
23+
static func webkitPadding(size: UInt8, unit: CSSUnit = .em) -> String {
24+
let paddingTemplate = "document.getElementsByTagName('body')[0].style.webkit%@='%d%@'"
25+
return ["PaddingStart", "PaddingEnd", "PaddingBefore", "PaddingAfter"].map { property in
26+
String(format: paddingTemplate, property, size, unit.rawValue)
27+
}.joined(separator: "; ")
28+
}
29+
}

Views/BuildingBlocks/WebView.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,14 @@ final class WebViewController: UIViewController {
7474
private var layoutCancellable: AnyCancellable?
7575
private var currentScrollViewOffset: CGFloat = 0.0
7676
private var compactViewNavigationController: UINavigationController?
77-
77+
private static let webkitPaddingJS: String = Javascript.webkitPadding(size: 1, unit: .em)
78+
7879
init(webView: WKWebView) {
7980
self.webView = webView
8081
pageZoomObserver = Defaults.observe(.webViewPageZoom) { change in
8182
webView.adjustTextSize(pageZoom: change.newValue)
83+
// adjust padding, as with large zoom in the content is too close to the sides
84+
webView.evaluateJavaScript(Self.webkitPaddingJS, completionHandler: nil)
8285
}
8386
super.init(nibName: nil, bundle: nil)
8487
}

0 commit comments

Comments
 (0)