-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[webview_flutter] Added the ability to activate the zoom (Android) #1235
Changes from all commits
d0cfbb5
619434a
0346929
a87b554
88f417a
060a049
a8e3ca9
a8769eb
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 |
|---|---|---|
|
|
@@ -174,6 +174,9 @@ private void applySettings(Map<String, Object> settings) { | |
| case "jsMode": | ||
| updateJsMode((Integer) settings.get(key)); | ||
| break; | ||
| case "zoom": | ||
| updateZoomMode((boolean) settings.get(key)); | ||
| break; | ||
| default: | ||
| throw new IllegalArgumentException("Unknown WebView setting: " + key); | ||
| } | ||
|
|
@@ -193,6 +196,14 @@ private void updateJsMode(int mode) { | |
| } | ||
| } | ||
|
|
||
| private void updateZoomMode(boolean mode) { | ||
| //webView.getSettings().setLoadWithOverviewMode(true); | ||
| webView.getSettings().setUseWideViewPort(mode); | ||
|
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. Why is this tied to the zoom mode?
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. When the value is true and the page contains the viewport meta tag, the value of the width specified in the tag is used. If the page does not contain the tag or does not provide a width, then a wide viewport will be used. actually i can remove mode and leave it on true. do you suggest to create another parameter for separate management? |
||
| webView.getSettings().setBuiltInZoomControls(mode); | ||
| // Pop-up zoom controls disabled. This is a temporary stop because dialog is not responding to touch events. | ||
| webView.getSettings().setDisplayZoomControls(false); | ||
| } | ||
|
|
||
| private void registerJavaScriptChannelNames(List<String> channelNames) { | ||
| for (String channelName : channelNames) { | ||
| webView.addJavascriptInterface( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,6 +79,7 @@ class WebView extends StatefulWidget { | |
| this.javascriptMode = JavascriptMode.disabled, | ||
| this.javascriptChannels, | ||
| this.gestureRecognizers, | ||
| this.zoom = false, | ||
| }) : assert(javascriptMode != null), | ||
| super(key: key); | ||
|
|
||
|
|
@@ -130,7 +131,10 @@ class WebView extends StatefulWidget { | |
| /// | ||
| /// A null value is equivalent to an empty set. | ||
| final Set<JavascriptChannel> javascriptChannels; | ||
|
|
||
|
|
||
| /// Enable/Disable zoom. | ||
|
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. Is there a way to do the same on iOS?
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. at the moment I have no way to test the ios environment. I will modify the comment in on-op on ios |
||
| final bool zoom; | ||
|
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. nit: I'd suggest calling this zoomEnabled (I can imagine a parameter named zoom being used to set a zoom level)
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. ok, of course |
||
|
|
||
| @override | ||
| State<StatefulWidget> createState() => _WebViewState(); | ||
| } | ||
|
|
@@ -256,19 +260,19 @@ class _CreationParams { | |
| } | ||
|
|
||
| class _WebSettings { | ||
| _WebSettings({ | ||
| this.javascriptMode, | ||
| }); | ||
|
|
||
| _WebSettings({this.javascriptMode, this.zoom}); | ||
|
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. The way this worked has changed a bit, please rebase and use the widget reference. |
||
| static _WebSettings fromWidget(WebView widget) { | ||
| return _WebSettings(javascriptMode: widget.javascriptMode); | ||
| return _WebSettings( | ||
| javascriptMode: widget.javascriptMode, zoom: widget.zoom); | ||
| } | ||
|
|
||
| final JavascriptMode javascriptMode; | ||
|
|
||
| final bool zoom; | ||
|
|
||
| Map<String, dynamic> toMap() { | ||
| return <String, dynamic>{ | ||
| 'jsMode': javascriptMode.index, | ||
| 'zoom': zoom, | ||
| }; | ||
| } | ||
|
|
||
|
|
@@ -278,6 +282,7 @@ class _WebSettings { | |
| } | ||
| return <String, dynamic>{ | ||
| 'jsMode': newSettings.javascriptMode.index, | ||
| 'zoom': newSettings.zoom, | ||
| }; | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete this line