public XamarinFormsWebViewSamplePage() { InitializeComponent(); var serializer = new JsonSerializer(); var webView = new HybridWebView(serializer) { VerticalOptions = LayoutOptions.FillAndExpand, Margin = new Thickness(20, 30), Uri = new Uri(WebViewUrl) }; webView.RegisterCallback(LoginCallback, (arg) => { var loginForm = serializer.Deserialize <LoginFormDto>(arg); var result = loginForm.Username == Username; webView.CallJsFunction(DisplayLoginAlertFunctioName, new[] { result.ToString() }); }); Content = webView; }
protected override bool OnBackButtonPressed() { webView.CallJsFunction("goBack"); return(true); // if (browser.CanGoBack) // { // // Task<string> task = Task.Run<string>(async () => await GetValueFromTextbox()); // // var cccc = task.Result; // browser.GoBack(); // return true; // } // return true; // //else return base.OnBackButtonPressed(); //} //void OnNavigating(object sender, WebNavigatingEventArgs args) //{ // // Checking if we are at the home page url // // browser.CanGoBack does not seem to be working (not updating in time) // NavigationPage.SetHasNavigationBar(this, args.Url != Url); }
// I'm so insanely mad that I need to even do this…. The problem is that the Android // renderer for the HybridWebView does not marshal back to the UI thread when the // native function is complete at that causes Android to fail on Lollipop+. Since building // my own version of HybridWebView is insanely hard and subclassing the existing one is // impossible, we have our *2 version of this method which works the same way but puts // the callback onto the right flippin thread! public static void RegisterNativeFunction_Custom(this HybridWebView hybridWebView, string name, Func <string, object[]> func) { hybridWebView.RegisterCallback(name, (s) => { // Get the appended callback ID var index = s.LastIndexOf('!'); var callbackId = s.Substring(index + 1); s = s.Substring(0, index); Task.Run(() => { // Run the native function var args = func(s); // The magic that was missing from the original... Device.BeginInvokeOnMainThread(() => { hybridWebView.CallJsFunction("nativeFuncs2[" + callbackId + "]", args); }); }); }); }
private void loadHtml(object sender, EventArgs e) { hybrid.CallJsFunction($"loadHtml", _html); }
void OnCallJavaScriptButton1Clicked(object sender, EventArgs e) { webView.CallJsFunction("Etherify.Eth.createRandom12Words", ""); }
public void SetHookekEthereumHost(string value) { //TODO Validate url in 'value' parameter. Ex: http://hookedethereum:8545 _hybridWebView.CallJsFunction(EhterifyNamespacePrefix + "setHookekEthereumHost", value); }