Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zoom support #34

Closed
Gustik opened this issue Feb 3, 2018 · 9 comments
Closed

Zoom support #34

Gustik opened this issue Feb 3, 2018 · 9 comments

Comments

@Gustik
Copy link

Gustik commented Feb 3, 2018

I want zoom content in webview with gestures. Is it possible?

@lejard-h
Copy link
Collaborator

lejard-h commented Feb 6, 2018

The webview is an Android/iOS native element so zoom should be builtin. Do you have any problem to make it work ?

@Gustik
Copy link
Author

Gustik commented Feb 7, 2018

Yes, I do not have zoom. I use Android.
My widget where I use the webview

class DocumentPage extends StatelessWidget {
  final Document _document;

  DocumentPage(this._document);

  @override
  Widget build(BuildContext context) {
    return new WebviewScaffold(
      url: "http://example.org/pdf.php?doc=docs/project/${_document.file}",
      appBar: new AppBar(
        title: new Text(_document.name),
      ),
      withJavascript: true,
    );
  }
}

@agreensh
Copy link

agreensh commented Feb 19, 2018

@lejard-h

Although pinch and zoom are built-in to WebView (Android) and UIWebView (iOS), they need to be "switched-on".

In Android, the plugin needs to call the following:
this.webView.getSettings().setBuiltInZoomControls(true);
this.webView.getSettings().setSupportZoom(true);
to allow pinch/zoom.

In iOS, the plugin needs to call the following:
self.webview.scalesPageToFit = YES; to allow pinch/zoom.

@lejard-h
Copy link
Collaborator

Tested on Android, it does not seem to work,

But I have not tested on iOS

@agreensh
Copy link

I have tested on Android and iOS. It does work.

Remember, you also have to take into account the web page - the meta data can prevent pinch/zoom (eg in your example, the page (https://github.com/dart-flitter/flutter_webview_plugin) does that by setting <meta name='viewport' content='width=device-width'>, so that page will NOT pinch/zoom). Try on another page that is 'reactive' eg 'https://flutter.io'

If that doesn't work, then I think you've put the code in the wrong place.

On Android

WebviewManager(Activityactivity) {
    this.webView = new WebView(activity);
    this.webView.getSettings().setBuiltInZoomControls(true);
    this.webView.getSettings().setSupportZoom(true);
    WebViewClient webViewClient = new BrowserClient();
    webView.setWebViewClient(webViewClient);
}

@Gustik
Copy link
Author

Gustik commented Feb 26, 2018

Tried to open a 'https://flutter.io', all the same the zooming does not work.
But the patch works:

this.webView.getSettings().setBuiltInZoomControls(true);
this.webView.getSettings().setSupportZoom(true);

Can make it optional? e.g. 'withZoom: true'
Thanks!

@lejard-h
Copy link
Collaborator

fixed in 0.1.3

@AleksandarFaraj
Copy link

Can we split up ZoomControls and SupportZoom into two variables?
ZoomControls could be named AndroidZoomControl: boolean

@kakyoism
Copy link

kakyoism commented Sep 8, 2020

Need a step-by-step for this. I'm not sure how to add the native code in Kotlin, Swift. Where is the exact place to insert the native code? Should I create a webview on the fly in native code instead of creating the WebView widget in flutter??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants