Exemple #1
0
        /// <summary>
        /// Internal Use Only.
        /// </summary>
        /// <param name="type">The type of event</param>
        /// <param name="eventObject">The WVE object to pass</param>
        /// <returns></returns>
        public object InvokeEvent(WebViewEventType type, WebViewDelegate eventObject)
        {
            switch (type)
            {
            case WebViewEventType.NavigationRequested:
                return(OnNavigationStarted == null ? eventObject as NavigationRequestedDelegate : OnNavigationStarted.Invoke(eventObject as NavigationRequestedDelegate));

            case WebViewEventType.NavigationComplete:
                OnNavigationCompleted?.Invoke(eventObject as NavigationCompletedDelegate);
                break;

            case WebViewEventType.NavigationError:
                OnNavigationError?.Invoke(eventObject as NavigationErrorDelegate);
                break;

            case WebViewEventType.ContentLoaded:
                OnContentLoaded?.Invoke(eventObject as ContentLoadedDelegate);
                break;

            case WebViewEventType.NavigationStackUpdate:
                CanGoBack    = (eventObject as NavigationStackUpdateDelegate).CanGoBack;
                CanGoForward = (eventObject as NavigationStackUpdateDelegate).CanGoForward;
                break;

            case WebViewEventType.JavascriptCallback:
                var            data = (eventObject as JavascriptResponseDelegate).Data;
                ActionResponse ar;

                if (data.ValidateJSON() && (ar = data.AttemptParseActionResponse()) != null)
                {
                    // Attempt Locals
                    if (RegisteredActions[this].ContainsKey(ar.Action))
                    {
                        RegisteredActions[this][ar.Action]?.Invoke(ar.Data);
                    }

                    // Attempt Globals
                    if (RegisteredActions[_globalKey].ContainsKey(ar.Action))
                    {
                        RegisteredActions[_globalKey][ar.Action]?.Invoke(ar.Data);
                    }
                }
                else
                {
                    OnJavascriptResponse?.Invoke(eventObject as JavascriptResponseDelegate);
                }

                break;
            }

            return(eventObject);
        }
Exemple #2
0
        /// <summary>
        /// Internal Use Only.
        /// </summary>
        /// <param name="type">The type of event</param>
        /// <param name="eventObject">The WVE object to pass</param>
        /// <returns></returns>
        public object InvokeEvent(WebViewEventType type, WebViewDelegate eventObject)
        {
            switch (type)
            {
            case WebViewEventType.NavigationRequested:
                SetValue(NavigatingProperty, true);
                return(OnNavigationStarted?.Invoke(eventObject as NavigationRequestedDelegate));

            case WebViewEventType.NavigationComplete:
                SetValue(NavigatingProperty, false);
                OnNavigationCompleted?.Invoke(eventObject as NavigationCompletedDelegate);
                break;

            case WebViewEventType.NavigationError:
                SetValue(NavigatingProperty, false);
                OnNavigationError?.Invoke(eventObject as NavigationErrorDelegate);
                break;

            case WebViewEventType.ContentLoaded:
                SetValue(NavigatingProperty, false);
                OnContentLoaded?.Invoke(eventObject as ContentLoadedDelegate);
                break;

            case WebViewEventType.NavigationStackUpdate:
                var stackUpdateDelegate           = eventObject as NavigationStackUpdateDelegate;
                var navigationStackUpdateDelegate = eventObject as NavigationStackUpdateDelegate;

                if (stackUpdateDelegate != null)
                {
                    SetValue(CanGoBackProperty, stackUpdateDelegate.CanGoBack);
                }

                if (navigationStackUpdateDelegate != null)
                {
                    SetValue(CanGoForwardProperty, navigationStackUpdateDelegate.CanGoForward);
                }
                break;

            case WebViewEventType.JavascriptCallback:
                var javascriptResponseDelegate = eventObject as JavascriptResponseDelegate;
                if (javascriptResponseDelegate != null)
                {
                    var            data = javascriptResponseDelegate.Data;
                    ActionResponse ar;
                    if (data.ValidateJSON() && (ar = data.AttemptParseActionResponse()) != null)
                    {
                        // Attempt Locals
                        if (LocalRegisteredActions.ContainsKey(ar.Action))
                        {
                            LocalRegisteredActions[ar.Action]?.Invoke(ar.Data);
                        }

                        // Attempt Globals
                        if (GlobalRegisteredActions.ContainsKey(ar.Action))
                        {
                            GlobalRegisteredActions[ar.Action]?.Invoke(ar.Data);
                        }
                    }
                    else
                    {
                        OnJavascriptResponse?.Invoke((JavascriptResponseDelegate)eventObject);
                    }
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }

            return(eventObject);
        }