Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

HybridWebViewRenderer to cancel navigation not working... help appreciated..

$
0
0

Hi guys, I'm trying to use the hybridwebviewrenderer to cancel navigation but somehow the renderer code is not being called... I have also tried using the Navigating event... but then in the Xlabs.Eventargs there is no way to cancel the event... Any ideas?

var serializer = new XLabs.Serialization.JsonNET.JsonSerializer();
var hwv = new HybridWebView (serializer) { 
VerticalOptions = LayoutOptions.FillAndExpand, 
HorizontalOptions = LayoutOptions.FillAndExpand,
WidthRequest = DetailLayout.Width,
HeightRequest = DetailLayout.Height
};

hwv.Navigating += (object sender, XLabs.EventArgs<Uri> e) => {
Device.OpenUri(e.Value);
};

[assembly: ExportRendererAttribute(typeof(HybridWebView), typeof(MyWebViewRenderer))]
namespace NieuwsApp.iOS
{
    public class MyWebViewRenderer : XLabs.Forms.Controls.HybridWebViewRenderer
    {
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);
        }

        protected override void OnElementChanged (ElementChangedEventArgs<HybridWebView> e)
        {
            base.OnElementChanged (e);
            if (e.OldElement != null || Element == null)
                return;
//          this.Control.ScrollView.ScrollEnabled = false;
//          this.Control.ScrollView.Bounces = false;
            this.Control.ShouldStartLoad += (UIWebView webView, NSUrlRequest request, UIWebViewNavigationType navigationType) => 
            {
                if (navigationType == UIWebViewNavigationType.LinkClicked)
                {
                    UIAlertView av = new UIAlertView();
                    av.Show();
                    UIApplication.SharedApplication.OpenUrl(request.Url);
                    return false;
                }
                return true;
            };
//
            this.Control.LoadFinished += (object sender, EventArgs ea) => 
            {
                //int contentHeight = Int32.Parse(this.EvaluateJavascript("document.body.offsetHeight;"));
                this.Frame = new CoreGraphics.CGRect(this.Frame.X, this.Frame.Y, this.Frame.Width, this.Control.ScrollView.ContentSize.Height);
            };
        }

    }
}

Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>