Ejemplo n.º 1
0
        public Xamarin.Forms.View CreateWebView()
        {
            var preferences = new WKPreferences()
            {
                JavaScriptEnabled = true,
                JavaScriptCanOpenWindowsAutomatically = false
            };
            var configuration = new WKWebViewConfiguration()
            {
                UserContentController = userContentController = new WKUserContentController()
            };
            var helper         = new Ao3TrackHelper(this);
            var messageHandler = new Ao3TrackReader.iOS.ScriptMessageHandler(helper);

            userContentController.AddScriptMessageHandler((WKScriptMessageHandler)messageHandler, "ao3track");
            this.helper = helper;

            configuration.Preferences = preferences;

            webView = new WKWebView(configuration)
            {
                NavigationDelegate = new NavigationDelegate(this)
            };

            webView.FocuseChanged += WebView_FocusChange;

            var xview = webView.ToView();

            xview.SizeChanged += Xview_SizeChanged;

            return(xview);
        }
Ejemplo n.º 2
0
        public void CreateWebViewAdditional()
        {
            var helper         = new Ao3TrackHelper(this);
            var messageHandler = new Win81.ScriptMessageHandler(helper);

            webView.ScriptNotify += messageHandler.WebView_ScriptNotify;
            this.helper           = helper;

            contextMenuPlaceholder = new Xamarin.Forms.ContentView();
            Xamarin.Forms.AbsoluteLayout.SetLayoutBounds(contextMenuPlaceholder, new Xamarin.Forms.Rectangle(0, 0, 0, 0));
            Xamarin.Forms.AbsoluteLayout.SetLayoutFlags(contextMenuPlaceholder, Xamarin.Forms.AbsoluteLayoutFlags.PositionProportional);
            MainContent.Children.Insert(0, contextMenuPlaceholder);

            webView.SizeChanged += WebView_SizeChanged;
        }
Ejemplo n.º 3
0
 public ScriptMessageHandler(Ao3TrackHelper helper) : base(helper)
 {
 }
Ejemplo n.º 4
0
        public void CreateWebViewAdditional()
        {
            webView.NewWindowRequested += WebView_NewWindowRequested;

            helper = new Ao3TrackHelper(this);
        }
Ejemplo n.º 5
0
 protected ScriptMessageHandler(Ao3TrackHelper helper)
 {
     this.helper = helper;
 }
Ejemplo n.º 6
0
        public Xamarin.Forms.View CreateWebView()
        {
            webView = new MyWebView(MainActivity.Instance, this);
            webView.SetWebViewClient(webClient = new WebClient(this));
            webView.SetWebChromeClient(new ChromeClient(this));
            webView.Settings.AllowContentAccess  = true;
            webView.Settings.JavaScriptEnabled   = true;
            webView.Settings.BuiltInZoomControls = true;
            webView.Settings.DisplayZoomControls = false;
            webView.Settings.UseWideViewPort     = true;
            if (Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat)
            {
#if DEBUG
                WebView.SetWebContentsDebuggingEnabled(true);
#else
                WebView.SetWebContentsDebuggingEnabled(false);
#endif
            }
            if (Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
            {
                webView.Settings.MixedContentMode = MixedContentHandling.AlwaysAllow;
            }
            if (Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.N)
            {
                webView.Settings.DisabledActionModeMenuItems = MenuItems.ProcessText | MenuItems.Share | MenuItems.WebSearch;
            }

            AddJavascriptObject("Ao3TrackHelperNative", helper);

            var placeholder = new Android.Views.View(Forms.Context);
            contextMenuPlaceholder = placeholder.ToView();
            Xamarin.Forms.AbsoluteLayout.SetLayoutBounds(contextMenuPlaceholder, new Rectangle(0, 0, 0, 0));
            Xamarin.Forms.AbsoluteLayout.SetLayoutFlags(contextMenuPlaceholder, AbsoluteLayoutFlags.None);
            helper = new Ao3TrackHelper(this);

            contextMenu = new ContextMenu(Forms.Context, placeholder);
            var menu = contextMenu.Menu;
            for (int i = 0; i < ContextMenuItems.Count; i++)
            {
                var kvp = ContextMenuItems[i];
                if (kvp.Key == "-")
                {
                    // Looks better without
                    //menu.Add(Menu.None, i, i, "\x23AF\x23AF\x23AF\x23AF").SetEnabled(false);
                }
                else
                {
                    menu.Add(Android.Views.Menu.None, i, i, kvp.Key);
                }
            }

            contextMenu.MenuItemClick += (sender, arg) =>
            {
                ContextMenuItems[arg.Item.ItemId].Value?.Execute(contextMenu.CommandParameter);
            };

            MainContent.Children.Add(contextMenuPlaceholder);

            webView.FocusChange += WebView_FocusChange;

            return(webView.ToView());
        }