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); }
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); }
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 }
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); }
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 }
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 }