-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[webview_flutter] Implement zoom enabled for ios and android #4417
Changes from 13 commits
5c72815
1172d73
68283a0
3d5467c
b0f92d6
a342931
b6b4c30
ef139b6
8b7bcb0
64db0db
74addca
f2dd5ad
6672b4f
024397a
59e1b03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| ## 2.1.0 | ||
|
|
||
| * Add `zoomEnabled` functionality. | ||
|
|
||
| ## 2.0.15 | ||
|
|
||
| * Added Overrides in FlutterWebView.java | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,6 +63,17 @@ - (void)webView:(WKWebView *)webView | |
| } | ||
|
|
||
| - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation { | ||
| if (!self.shouldEnableZoom) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What would happen if
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense but I'm not totally sure where you are suggesting I should also make this check? Inside
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This workaround actually makes me question if this feature should even be supported by iOS directly. I'm leaning towards that a platform shouldn't support a feature from the platform interface unless it is directly supported by the API or there is a reasonable workaround. And I wouldn't consider running java script as a reasonable workaround. @stuartmorgan Do we have a policy for this already?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, the WKWebView API doesn't provide a built-in way of toggling whether or not zoom is enabled. This workaround was intended to at least allow Flutter devs to toggle that on both Android and iOS. The original intention of this work was strictly to ENABLE zoom for Android as that functionality is currently missing. My background is in Android but in my research, I couldn't find a cleaner way of DISABLING zoom for iOS.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One other proposal, although it would require reverting #4404, is to just enable zooming for Android, and not make it togglable in the Flutter
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I can see this either way. I spent years working on a project that attempted to make UIWebView usable in a browser context though, and basically everything had to be done with JS in that case, so my judgement on this may well be skewed. In this case, my take was:
Given that my feeling is that it's reasonable to provide a best-effort implementation rather than nothing, as if someone is explicitly trying to turn on this behavior they presumably would want it to work on iOS too.
We don't have an explicit policy. There are obvious cases where we would say no, like use of private API on iOS, but this isn't doing anything like that, and using JS as a polyfill for OS web view limitations is something that definitely has a history of being relatively common on iOS, so I don't think this is a clear-cut case of "unreasonable".
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense. Then I'm fine with the current implementation of the feature. I would just make it clear how the feature works on iOS in the followup PR for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you both! |
||
| NSString *source = | ||
| @"var meta = document.createElement('meta');" | ||
| @"meta.name = 'viewport';" | ||
| @"meta.content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0," | ||
| @"user-scalable=no';" | ||
| @"var head = document.getElementsByTagName('head')[0];head.appendChild(meta);"; | ||
|
|
||
| [webView evaluateJavaScript:source completionHandler:nil]; | ||
| } | ||
|
|
||
| [_methodChannel invokeMethod:@"onPageFinished" arguments:@{@"url" : webView.URL.absoluteString}]; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.