public void RunJavaScriptTextInputPanel(WebKit.WKWebView webView, string prompt, string defaultText, WebKit.WKFrameInfo frame, System.Action <string> completionHandler) { // Create a native UIAlertController with the message var alertController = UIAlertController.Create(null, prompt, UIAlertControllerStyle.Alert); // Add a text field to the alert, set the placeholder text and keep a refernce to the field UITextField alertTextField = null; alertController.AddTextField((textField) => { textField.Placeholder = defaultText; alertTextField = textField; }); // Pass the text to the completion handler when the "OK" button is tapped alertController.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, okAction => { completionHandler(alertTextField.Text); })); // If "Cancel" is tapped, we can just return null alertController.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Default, cancelAction => { completionHandler(null); })); // Present the alert PresentViewController(alertController, true, null); }
public override void DidFinishNavigation(WebKit.WKWebView webView, WKNavigation navigation) { if (canDoOnContentLoaded) { wvp.OnContentLoaded(); canDoOnContentLoaded = false; } }
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(); }
public void RunJavaScriptAlertPanel(WebKit.WKWebView webView, string message, WebKit.WKFrameInfo frame, System.Action completionHandler) { // Create and present a native UIAlertController with the message var alertController = UIAlertController.Create(null, message, UIAlertControllerStyle.Alert); alertController.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null)); PresentViewController(alertController, true, null); // Call the completion handler completionHandler(); }
public override void DecidePolicy(WebKit.WKWebView webView, WKNavigationAction navigationAction, Action <WKNavigationActionPolicy> decisionHandler) { if (wvp.OnNavigationStarting(new Uri(navigationAction.Request.Url.AbsoluteString))) { decisionHandler(WKNavigationActionPolicy.Cancel); } else { decisionHandler(WKNavigationActionPolicy.Allow); } }
public static NSMutableData CreatePdfFile(this WebKit.WKWebView webView, UIViewPrintFormatter printFormatter) { var renderer = new PdfRenderer(); renderer.AddPrintFormatter(printFormatter, 0); // Letter = 8.5" * 72 x 11" * 72 // Inset = .5"/2 * 72 x 1"/2 * 72 var page = new CGRect(0, 0, 8.5 * 72, 11 * 72); var pdfPageFrame = page.Inset(dx: (nfloat).25 * 72, dy: (nfloat).5 * 72); renderer.SetValueForKey(NSValue.FromCGRect(page), new NSString("paperRect")); renderer.SetValueForKey(NSValue.FromCGRect(pdfPageFrame), new NSString("printableRect")); return(renderer.PrintToPdf()); }
public static NSMutableData CreatePdfFile(this WebKit.WKWebView webView, UIViewPrintFormatter printFormatter) { var bounds = webView.Bounds; webView.Bounds = new CoreGraphics.CGRect(bounds.X, bounds.Y, bounds.Width, webView.ScrollView.ContentSize.Height); var pdfPageFrame = new CoreGraphics.CGRect(0, 0, webView.Bounds.Width, webView.Bounds.Height); var renderer = new PdfRenderer(); renderer.AddPrintFormatter(printFormatter, 0); renderer.SetValueForKey(NSValue.FromCGRect(UIScreen.MainScreen.Bounds), new NSString("paperRect")); renderer.SetValueForKey(NSValue.FromCGRect(pdfPageFrame), new NSString("printableRect")); webView.Bounds = bounds; return(renderer.PrintToPdf()); }
static void UserAgentFromWKWebView() { WebKit.WKWebViewConfiguration wkconf = new WebKit.WKWebViewConfiguration() { }; WebKit.WKWebView wkwv = new WebKit.WKWebView(CoreGraphics.CGRect.Empty, wkconf); // TODO: WKWebKit UserAgent JavaScript handler not triggered from JavaScript WebKit.WKJavascriptEvaluationResult handler = HandleWKJavascriptEvaluationResult; // case sensitive stuff: // navigator.* // few SO posts with Pascal case will not work! wkwv.EvaluateJavaScript((NSString)"navigator.userAgent", handler); //wkwv.EvaluateJavaScript((NSString)"navigator.appName", handler); wkwv.LoadHtmlString("<html></html>", null); return; }
public void RunJavaScriptTextInputPanel(WebKit.WKWebView webView, string prompt, string defaultText, WebKit.WKFrameInfo frame, System.Action <string> completionHandler) { var alertController = UIAlertController.Create(null, prompt, UIAlertControllerStyle.Alert); UITextField alertTextField = null; alertController.AddTextField((textField) => { textField.Placeholder = defaultText; alertTextField = textField; }); alertController.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, okAction => { completionHandler(alertTextField.Text); })); alertController.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Default, cancelAction => { completionHandler(null); })); UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(alertController, true, null); }
public override void DidCommitNavigation(WebKit.WKWebView webView, WKNavigation navigation) { wvp.OnContentLoading(); canDoOnContentLoaded = true; }