Skip to content

Commit f7db0e4

Browse files
authored
Merge pull request #111 from KevinnZou/feature/ios_zoom_disable
feat:make support zoom a common feature (desktop excluded)
2 parents b3f99a3 + 5d8b65e commit f7db0e4

File tree

5 files changed

+13
-12
lines changed

5 files changed

+13
-12
lines changed

webview/src/androidMain/kotlin/com/multiplatform/webview/web/AccompanistWebView.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ fun AccompanistWebView(
178178
userAgentString = it.customUserAgentString
179179
allowFileAccessFromFileURLs = it.allowFileAccessFromFileURLs
180180
allowUniversalAccessFromFileURLs = it.allowUniversalAccessFromFileURLs
181+
setSupportZoom(it.supportZoom)
181182
}
182183

183184
state.webSettings.androidWebSettings.let {
@@ -187,7 +188,6 @@ fun AccompanistWebView(
187188
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
188189
isAlgorithmicDarkeningAllowed = it.isAlgorithmicDarkeningAllowed
189190
}
190-
setSupportZoom(it.supportZoom)
191191
setBackgroundColor(state.webSettings.backgroundColor.toArgb())
192192
allowFileAccess = it.allowFileAccess
193193
textZoom = it.textZoom

webview/src/commonMain/kotlin/com/multiplatform/webview/setting/PlatformWebSettings.kt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@ sealed class PlatformWebSettings {
1010
* Android web settings
1111
*/
1212
data class AndroidWebSettings(
13-
/**
14-
* whether the WebView should support zooming using its on-screen zoom
15-
* controls and gestures. The particular zoom mechanisms that should be used
16-
* can be set with {@link #setBuiltInZoomControls}. This setting does not
17-
* affect zooming performed using the {@link WebView#zoomIn()} and
18-
* {@link WebView#zoomOut()} methods. The default is {@code true}.
19-
*
20-
* @param support whether the WebView should support zoom
21-
*/
22-
var supportZoom: Boolean = true,
2313
/**
2414
* Enables or disables file access within WebView.
2515
* Note that this enables or disables file system access only. Assets and resources

webview/src/commonMain/kotlin/com/multiplatform/webview/setting/WebSettings.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ class WebSettings {
3030
*/
3131
var zoomLevel: Double = 1.0
3232

33+
/**
34+
* whether the WebView should support zooming using its on-screen zoom
35+
* controls and gestures. The default is {@code true}.
36+
*
37+
* @param support whether the WebView should support zoom
38+
*/
39+
var supportZoom: Boolean = true
40+
3341
/**
3442
* Whether cross-origin requests in the context of a file scheme URL should be allowed to
3543
* access content from other file scheme URLs. Note that some accesses such as image HTML

webview/src/iosMain/kotlin/com/multiplatform/webview/web/WKNavigationDelegate.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ class WKNavigationDelegate(
4141
webView: WKWebView,
4242
didCommitNavigation: WKNavigation?,
4343
) {
44+
val supportZoom = if (state.webSettings.supportZoom) "yes" else "no"
45+
4446
@Suppress("ktlint:standard:max-line-length")
45-
val script = "var meta = document.createElement('meta');meta.setAttribute('name', 'viewport');meta.setAttribute('content', 'width=device-width, initial-scale=${state.webSettings.zoomLevel}, maximum-scale=10.0, minimum-scale=0.1,user-scalable=yes');document.getElementsByTagName('head')[0].appendChild(meta);"
47+
val script = "var meta = document.createElement('meta');meta.setAttribute('name', 'viewport');meta.setAttribute('content', 'width=device-width, initial-scale=${state.webSettings.zoomLevel}, maximum-scale=10.0, minimum-scale=0.1,user-scalable=$supportZoom');document.getElementsByTagName('head')[0].appendChild(meta);"
4648
webView.evaluateJavaScript(script) { _, _ -> }
4749
KLogger.info { "didCommitNavigation" }
4850
}

webview/src/iosMain/kotlin/com/multiplatform/webview/web/WebView.ios.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ fun IOSWebView(
9393
val scrollViewColor = (it.iOSWebSettings.underPageBackgroundColor ?: it.backgroundColor).toUIColor()
9494
setBackgroundColor(backgroundColor)
9595
scrollView.setBackgroundColor(scrollViewColor)
96+
scrollView.pinchGestureRecognizer?.enabled = it.supportZoom
9697
}
9798
state.webSettings.iOSWebSettings.let {
9899
with(scrollView) {

0 commit comments

Comments
 (0)