Ejemplo n.º 1
0
        public void RunJavaScriptAlertPanel(WKWebView webView, string message, WKFrameInfo frame, Action completionHandler)
        {
            var controller = UIAlertController.Create(null, message, UIAlertControllerStyle.Alert);

            controller.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, x => completionHandler()));
            PresentViewController(controller, true, null);
        }
            public override void RunJavaScriptAlertPanel
            (
                WKWebView webView,
                string message,
                WKFrameInfo frame,
                Action completionHandler
            )
            {
                // custom javascript Alert() code possible

                #if DEBUG
                StringBuilder sb = new StringBuilder();
                sb.AppendLine($"WKWebViewUIDelegate.RunJavaScriptAlertPanel ");
                sb.AppendLine($"        webView.Url.AbsoluteString = {webView.Url.AbsoluteString}");
                System.Diagnostics.Debug.WriteLine(sb.ToString());
                #endif

                // COSMOS

                var alertController = UIAlertController.Create(null, message, UIAlertControllerStyle.Alert);
                alertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, (obj) => { completionHandler(); }));

                controller.PresentViewController(alertController, animated: true, null);
                return;
            }
 public override void RunJavaScriptTextInputPanel(
     WKWebView webView, string prompt, string defaultText, WKFrameInfo frame, Action <string> completionHandler)
 {
     PresentAlertController(
         webView,
         prompt,
         defaultText: defaultText,
         okAction: x => completionHandler(x.TextFields[0].Text),
         cancelAction: _ => completionHandler(null)
         );
 }
Ejemplo n.º 4
0
        public void RunJavaScriptConfirmPanel(WKWebView webView, string message, WKFrameInfo frame, Action <bool> completionHandler)
        {
            var alertController = UIAlertController.Create(null, message, UIAlertControllerStyle.Alert);

            alertController.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, okAction => {
                completionHandler(true);
            }));
            alertController.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Default, cancelAction => {
                completionHandler(false);
            }));

            UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(alertController, true, null);
        }
Ejemplo n.º 5
0
        private void OnRunJavaScriptAlertPanel(WKWebView webview, string message, WKFrameInfo frame, Action completionHandler)
        {
            if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
            {
                this.Log().DebugFormat("OnRunJavaScriptAlertPanel: {0}", message);
            }

            var controller = webview.FindViewController();
            var alert      = UIKit.UIAlertController.Create(string.Empty, message, UIKit.UIAlertControllerStyle.Alert);

            alert.AddAction(UIKit.UIAlertAction.Create(OkString, UIKit.UIAlertActionStyle.Default, null));

            controller?.PresentViewController(alert, true, completionHandler);
        }
Ejemplo n.º 6
0
		public void RunJavaScriptConfirmPanel (WKWebView webView, string message, WKFrameInfo frame, Action<bool> completionHandler)
		{
			// Create a native UIAlertController with the message
			var alertController = UIAlertController.Create (null, message, UIAlertControllerStyle.Alert);

			// Add two actions to the alert. Based on the result we call the completion handles and pass either true or false
			alertController.AddAction (UIAlertAction.Create ("Ok", UIAlertActionStyle.Default, okAction => {
				completionHandler(true);
			}));
			alertController.AddAction (UIAlertAction.Create ("Cancel", UIAlertActionStyle.Default, cancelAction => {
				completionHandler (false);
			}));

			// Present the alert
			PresentViewController (alertController, true, null);
		}
Ejemplo n.º 7
0
        public void RunJavaScriptConfirmPanel(WKWebView webView, string message, WKFrameInfo frame, Action <bool> completionHandler)
        {
            // Create a native UIAlertController with the message
            var alertController = UIAlertController.Create(null, message, UIAlertControllerStyle.Alert);

            // Add two actions to the alert. Based on the result we call the completion handles and pass either true or false
            alertController.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, okAction => {
                completionHandler(true);
            }));
            alertController.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Default, cancelAction => {
                completionHandler(false);
            }));

            // Present the alert
            PresentViewController(alertController, true, null);
        }
            public override void RunJavaScriptAlertPanel
            (
                WKWebView webView,
                string message,
                WKFrameInfo frame,
                Action completionHandler
            )
            {
                // custom javascript Alert() code possible

                #if DEBUG
                StringBuilder sb = new StringBuilder();
                sb.AppendLine($"WKWebViewUIDelegate.RunJavaScriptAlertPanel ");
                sb.AppendLine($"        webView.Url.AbsoluteString = {webView.Url.AbsoluteString}");
                System.Diagnostics.Debug.WriteLine(sb.ToString());
                #endif

                return;
            }
Ejemplo n.º 9
0
        private void OnRunJavaScriptConfirmPanel(WKWebView webview, string message, WKFrameInfo frame, Action <bool> completionHandler)
        {
            if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
            {
                this.Log().DebugFormat("OnRunJavaScriptConfirmPanel: {0}", message);
            }

            /*
             *	Code taken from:
             *  https://github.com/xamarin/recipes/pull/20/files
             */
            var controller = webview.FindViewController();
            var alert      = UIKit.UIAlertController.Create(string.Empty, message, UIKit.UIAlertControllerStyle.Alert);

            alert.AddAction(UIKit.UIAlertAction.Create(OkString, UIKit.UIAlertActionStyle.Default,
                                                       okAction => completionHandler(true)));

            alert.AddAction(UIKit.UIAlertAction.Create(CancelString, UIKit.UIAlertActionStyle.Cancel,
                                                       cancelAction => completionHandler(false)));

            controller?.PresentViewController(alert, true, null);
        }
Ejemplo n.º 10
0
        private void OnRunJavaScriptAlertPanel(WKWebView webview, string message, WKFrameInfo frame, Action completionHandler)
        {
            if (this.Log().IsEnabled(Uno.Foundation.Logging.LogLevel.Debug))
            {
                this.Log().DebugFormat("OnRunJavaScriptAlertPanel: {0}", message);
            }

            var controller = webview.FindViewController();

#if __IOS__
            var alert = UIKit.UIAlertController.Create(string.Empty, message, UIKit.UIAlertControllerStyle.Alert);
            alert.AddAction(UIKit.UIAlertAction.Create(OkString, UIKit.UIAlertActionStyle.Default, null));
            controller?.PresentViewController(alert, true, null);
            completionHandler();
#else
            var alert = new NSAlert()
            {
                AlertStyle      = NSAlertStyle.Informational,
                InformativeText = message
            };
            alert.RunModal();
            completionHandler();
#endif
        }
Ejemplo n.º 11
0
        private void OnRunJavaScriptConfirmPanel(WKWebView webview, string message, WKFrameInfo frame, Action <bool> completionHandler)
        {
            if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
            {
                this.Log().DebugFormat("OnRunJavaScriptConfirmPanel: {0}", message);
            }

            /*
             *	Code taken from:
             *  https://github.com/xamarin/recipes/pull/20/files
             */
            var controller = webview.FindViewController();

#if __IOS__
            var alert = UIKit.UIAlertController.Create(string.Empty, message, UIKit.UIAlertControllerStyle.Alert);
            alert.AddAction(UIKit.UIAlertAction.Create(OkString, UIKit.UIAlertActionStyle.Default,
                                                       okAction => completionHandler(true)));

            alert.AddAction(UIKit.UIAlertAction.Create(CancelString, UIKit.UIAlertActionStyle.Cancel,
                                                       cancelAction => completionHandler(false)));

            controller?.PresentViewController(alert, true, null);
#else
            var alert = new NSAlert()
            {
                AlertStyle      = NSAlertStyle.Informational,
                InformativeText = message,
            };
            alert.AddButton(OkString);
            alert.AddButton(CancelString);
            alert.BeginSheetForResponse(webview.Window, (result) => {
                var okButtonClicked = result == 1000;
                completionHandler(okButtonClicked);
            });
#endif
        }
Ejemplo n.º 12
0
        public override void RunJavaScriptAlertPanel(WKWebView webView, string message, WKFrameInfo frame, Action completionHandler)
        {
            var alert = UIAlertController.Create("Alert", message, UIAlertControllerStyle.Alert);

            alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));

            // Let javascript handle the OK click by passing the completionHandler to the controller
            ParentController.PresentViewController(alert, true, completionHandler);
        }
Ejemplo n.º 13
0
 public override void RunJavaScriptConfirmPanel(WKWebView webView, string message, WKFrameInfo frame, Action <bool> completionHandler)
 {
     PresentAlertController(
         webView,
         message,
         okAction: _ => completionHandler(true),
         cancelAction: _ => completionHandler(false)
         );
 }
Ejemplo n.º 14
0
 public override void RunJavaScriptAlertPanel(WKWebView webView, string message, WKFrameInfo frame, Action completionHandler)
 {
     PresentAlertController(
         webView,
         message,
         okAction: _ => completionHandler()
         );
 }
Ejemplo n.º 15
0
        public void RunJavaScriptTextInputPanel(WKWebView webView, string prompt, string defaultText, WKFrameInfo frame, Action <string> completionHandler)
        {
            var controller = UIAlertController.Create(null, prompt, UIAlertControllerStyle.Alert);

            controller.AddTextField(textField =>
            {
                textField.Placeholder = defaultText;
                controller.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, x => completionHandler(textField.Text)));
                controller.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Default, x => completionHandler(null)));
                PresentViewController(controller, true, null);
            });
        }
Ejemplo n.º 16
0
        public void RunJavaScriptAlertPanel(WebKit.WKWebView webView, string message, WKFrameInfo frame, Action completionHandler)
        {
            var alertController = UIAlertController.Create(null, message, UIAlertControllerStyle.Alert);

            alertController.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null));
            UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(alertController, true, null);

            completionHandler();
        }
Ejemplo n.º 17
0
        public override void RunJavaScriptTextInputPanel(WKWebView webView, string prompt, string defaultText, WKFrameInfo frame, Action <string> completionHandler)
        {
            var alertController = UIAlertController.Create("", prompt, UIAlertControllerStyle.Alert);

            alertController.AddTextField((UITextField obj) => obj.Text = defaultText);
            var actionOk = UIAlertAction.Create("Ok", UIAlertActionStyle.Default, (UIAlertAction obj) =>
            {
                string text = alertController.TextFields.Any() ? alertController.TextFields.First().Text : defaultText;
                completionHandler(text);
            });
            var actionCancel = UIAlertAction.Create("Cancel", UIAlertActionStyle.Default, (UIAlertAction obj) =>
            {
                completionHandler(null);
            });

            alertController.AddAction(actionOk);
            alertController.AddAction(actionCancel);

            UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(alertController, true, null);
        }
Ejemplo n.º 18
0
            public override void RunJavaScriptConfirmPanel(WKWebView webView, string message, WKFrameInfo frame, Action <bool> completionHandler)
            {
                if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
                {
                    this.Log().Debug($"WKUIDelegate.RunJavaScriptConfirmPanel: {message}");
                }

                _runJavaScriptConfirmPanel?.Invoke(webView, message, frame, completionHandler);
            }
Ejemplo n.º 19
0
            public override void RunJavaScriptTextInputPanel(WKWebView webView, string prompt, string defaultText, WKFrameInfo frame, Action <string> completionHandler)
            {
                if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
                {
                    this.Log().Debug($"WKUIDelegate.RunJavaScriptTextInputPanel: {prompt} / {defaultText}");
                }

                _runJavaScriptTextInputPanel?.Invoke(webView, prompt, defaultText, frame, completionHandler);
            }
Ejemplo n.º 20
0
        private void OnRunJavaScriptTextInputPanel(WKWebView webview, string prompt, string defaultText, WKFrameInfo frame, Action <string> completionHandler)
        {
            if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
            {
                this.Log().Debug($"OnRunJavaScriptTextInputPanel: {prompt}, {defaultText}");
            }

            var         alert          = UIKit.UIAlertController.Create(string.Empty, prompt, UIKit.UIAlertControllerStyle.Alert);
            UITextField alertTextField = null;

            alert.AddTextField((textField) =>
            {
                textField.Placeholder = defaultText;
                alertTextField        = textField;
            });

            alert.AddAction(UIKit.UIAlertAction.Create(OkString, UIKit.UIAlertActionStyle.Default,
                                                       okAction => completionHandler(alertTextField.Text)));

            alert.AddAction(UIKit.UIAlertAction.Create(CancelString, UIKit.UIAlertActionStyle.Cancel,
                                                       cancelAction => completionHandler(null)));

            var controller = webview.FindViewController();

            controller?.PresentViewController(alert, true, null);
        }
Ejemplo n.º 21
0
            public override void RunJavaScriptAlertPanel(WKWebView webView, string message, WKFrameInfo frame, Action completionHandler)
            {
                if (this.Log().IsEnabled(Uno.Foundation.Logging.LogLevel.Debug))
                {
                    this.Log().Debug($"WKUIDelegate.RunJavaScriptAlertPanel: {message}");
                }

                _runJavaScriptAlertPanel?.Invoke(webView, message, frame, completionHandler);
            }
Ejemplo n.º 22
0
        private void OnRunJavaScriptTextInputPanel(WKWebView webview, string prompt, string defaultText, WKFrameInfo frame, Action <string> completionHandler)
        {
            if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
            {
                this.Log().Debug($"OnRunJavaScriptTextInputPanel: {prompt}, {defaultText}");
            }

#if __IOS__
            var         alert          = UIKit.UIAlertController.Create(string.Empty, prompt, UIKit.UIAlertControllerStyle.Alert);
            UITextField alertTextField = null;

            alert.AddTextField((textField) =>
            {
                textField.Placeholder = defaultText;
                alertTextField        = textField;
            });

            alert.AddAction(UIKit.UIAlertAction.Create(OkString, UIKit.UIAlertActionStyle.Default,
                                                       okAction => completionHandler(alertTextField.Text)));

            alert.AddAction(UIKit.UIAlertAction.Create(CancelString, UIKit.UIAlertActionStyle.Cancel,
                                                       cancelAction => completionHandler(null)));

            var controller = webview.FindViewController();
            controller?.PresentViewController(alert, true, null);
#else
            var alert = new NSAlert()
            {
                AlertStyle      = NSAlertStyle.Informational,
                InformativeText = prompt,
            };
            var textField = new NSTextField(new CGRect(0, 0, 300, 20))
            {
                PlaceholderString = defaultText,
            };
            alert.AccessoryView = textField;
            alert.AddButton(OkString);
            alert.AddButton(CancelString);
            alert.BeginSheetForResponse(webview.Window, (result) => {
                var okButtonClicked = result == 1000;
                completionHandler(okButtonClicked ? textField.StringValue : null);
            });
#endif
        }
Ejemplo n.º 23
0
        public override void RunJavaScriptAlertPanel(WKWebView webView, string message, WKFrameInfo frame, Action completionHandler)
        {
            var alertController = UIAlertController.Create("", message, UIAlertControllerStyle.Alert);

            var actionOk = UIAlertAction.Create("Ok", UIAlertActionStyle.Default, (UIAlertAction obj) =>
            {
                completionHandler();
            });

            alertController.AddAction(actionOk);

            UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(alertController, true, null);
        }