Skip to content

Instantly share code, notes, and snippets.

Last active February 3, 2019 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiagocrizanto/6def58c7ed1b7d2e1a8e62496f069f7d to your computer and use it in GitHub Desktop.
Save tiagocrizanto/6def58c7ed1b7d2e1a8e62496f069f7d to your computer and use it in GitHub Desktop.
[assembly: ExportRenderer(typeof(HybridWebView), typeof(HybridWebViewRenderer))]
namespace FcaBrain.Droid.Renderers
public class HybridWebViewRenderer : WebViewRenderer
private new HybridWebView Element { get { return (HybridWebView)base.Element; } }
public HybridWebViewRenderer(Android.Content.Context context) : base(context) { }
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e)
var formsWebView = e.NewElement as Xamarin.Forms.WebView;
if (formsWebView != null)
var nativeWebView = Control as Android.Webkit.WebView;
nativeWebView.Settings.BuiltInZoomControls = true;
nativeWebView.Settings.DisplayZoomControls = true;
nativeWebView.Settings.LoadWithOverviewMode = true;
nativeWebView.Settings.DomStorageEnabled = true;
nativeWebView.Settings.JavaScriptEnabled = true;
nativeWebView.Settings.MixedContentMode = MixedContentHandling.AlwaysAllow;
nativeWebView.SetWebViewClient(new CustomWebViewClient(Element));
if ((e.NewElement.Source as UrlWebViewSource) != null)
string localUrl = System.Web.HttpUtility.UrlPathEncode((e.NewElement.Source as UrlWebViewSource).Url);
private class CustomWebViewClient : WebViewClient
private HybridWebView _webclient;
private Android.Webkit.WebView _view;
public CustomWebViewClient(HybridWebView webclient)
_webclient = webclient;
public override void OnReceivedHttpAuthRequest(Android.Webkit.WebView view, Android.Webkit.HttpAuthHandler handler, string host, string realm)
handler.Proceed(_webclient.Username, _webclient.Password);
public override bool ShouldOverrideUrlLoading(Android.Webkit.WebView view, string url)
return base.ShouldOverrideUrlLoading(view, url);
public override void OnPageFinished(Android.Webkit.WebView view, string url)
view.Settings.BuiltInZoomControls = true;
view.Settings.DisplayZoomControls = true;
//If the page don't allow zoom, insert metatag to allow it
var newMeta = document.createElement('meta');
newMeta.setAttribute('name', 'viewport');
newMeta.setAttribute('content', 'user-scalable=yes, width=device-width');
base.OnPageFinished(view, url);
_view = view;
private void GoBackNow(string goBack) => _view.GoBack();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment