Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -193,6 +196,14 @@ private void updateJsMode(int mode) {
}
}

private void updateZoomMode(boolean mode) {
//webView.getSettings().setLoadWithOverviewMode(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete this line

webView.getSettings().setUseWideViewPort(mode);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this tied to the zoom mode?

Copy link
Author

@Dn-a Dn-a Mar 30, 2019

Choose a reason for hiding this comment

The 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(
Expand Down
1 change: 1 addition & 0 deletions packages/webview_flutter/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class WebViewExample extends StatelessWidget {
body: Builder(builder: (BuildContext context) {
return WebView(
initialUrl: 'https://flutter.io',
zoom: true,
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
Expand Down
19 changes: 12 additions & 7 deletions packages/webview_flutter/lib/webview_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -130,7 +131,10 @@ class WebView extends StatefulWidget {
///
/// A null value is equivalent to an empty set.
final Set<JavascriptChannel> javascriptChannels;


/// Enable/Disable zoom.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to do the same on iOS?
If yes we should support that as well, if no the comment should mention that this is a no-op on iOS.

Copy link
Author

Choose a reason for hiding this comment

The 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;
Copy link
Contributor

Choose a reason for hiding this comment

The 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)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, of course


@override
State<StatefulWidget> createState() => _WebViewState();
}
Expand Down Expand Up @@ -256,19 +260,19 @@ class _CreationParams {
}

class _WebSettings {
_WebSettings({
this.javascriptMode,
});

_WebSettings({this.javascriptMode, this.zoom});
Copy link
Contributor

Choose a reason for hiding this comment

The 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,
};
}

Expand All @@ -278,6 +282,7 @@ class _WebSettings {
}
return <String, dynamic>{
'jsMode': newSettings.javascriptMode.index,
'zoom': newSettings.zoom,
};
}
}
Expand Down
Empty file.