public void EnableSpinnerOnce_ThenDisable() { uniWebView.SetShowSpinnerWhileLoading(true); uniWebView.SetSpinnerText(loadingText); UniWebView.PageFinishedDelegate disableSpinnerDelegate = null; disableSpinnerDelegate = (webview, __, ___) => { uniWebView.SetShowSpinnerWhileLoading(false); uniWebView.OnPageFinished -= disableSpinnerDelegate; }; uniWebView.OnPageFinished += disableSpinnerDelegate; }
// private void UniWebviewShownEvent(){ // Debug.Log("UniWebView Shown"); // onUniWebviewShown(myWebview); // } public void Hide() { this.myWebview.Hide(fade, transitionEdge, transitionDuration, UniWebviewHideEvent); if (this.myWebview.Url != this.myWebview.urlOnStart) { //Don't show loading spinner while reloading, then set it back to how it was before this.myWebview.SetShowSpinnerWhileLoading(false); bool showSpinner = this.GetComponent <WebViewSpinner>()?.enableLoadingSpinner ?? true; UniWebView.PageFinishedDelegate resetSpinnerSetting = null; resetSpinnerSetting = (_, __, ___) => { this.myWebview.SetShowSpinnerWhileLoading(showSpinner); this.myWebview.OnPageFinished -= resetSpinnerSetting; }; this.myWebview.OnPageFinished += resetSpinnerSetting; this.myWebview.Load(this.myWebview.urlOnStart); //-------------- } }
public static void Init(Action <bool> InInitCallback) { if (_webView != null) { InInitCallback?.Invoke(true); return; } _webView = UnityEngine.Object.FindObjectOfType <UniWebView>(); if (_webView != null) { InInitCallback?.Invoke(true); return; } GameObject gameObject = GameObject.Find("UniWebView"); if (null == gameObject) { gameObject = new GameObject("UniWebView"); } _webView = gameObject.AddComponent <UniWebView>(); UnityEngine.Object.DontDestroyOnLoad(gameObject); _webView.SetShowToolbar(false); _webView.SetBackButtonEnabled(false); _webView.SetBouncesEnabled(false); _webView.SetAllowFileAccessFromFileURLs(true); _webView.BackgroundColor = Color.white; UniWebView.PageFinishedDelegate onPageFinished = null; onPageFinished = (InWebView, InCode, InUrl) => { isWebViewShowing = false; #if !UNITY_EDITOR && UNITY_IOS RegisterKeyboardNotification(); #endif _webView.Hide(); // ReSharper disable once AccessToModifiedClosure _webView.OnPageFinished -= onPageFinished; InInitCallback?.Invoke(true); }; UniWebView.PageErrorReceivedDelegate onPageErrorReceived = null; onPageErrorReceived = (InView, InCode, InMessage) => { Log.Error($"[WebViewBridge] UniWebView.OnPageErrorReceived : errorCode = {InCode}, msg = {InMessage}"); _webView.Hide(); _webView.OnPageErrorReceived -= onPageErrorReceived; UnityEngine.Object.DestroyImmediate(_webView); InInitCallback?.Invoke(false); }; _webView.OnPageFinished += onPageFinished; _webView.OnPageErrorReceived += onPageErrorReceived; _webView.OnShouldClose += InView => { #if UNITY_ANDROID if (isWebViewShowing) { CallJsFunction("goBack"); } else { ADA_Manager.PageManager.Instance.BackButtonAction(); } #endif return(isWebViewShowing); }; }