Example #1
0
        /// <summary>
        /// Navigates to the specified route on the route's router depth with an optional argument.
        /// </summary>
        /// <param name="route">The destination route to navigate to.</param>
        /// <param name="argument">The optional argument to pass to the page (null by default).</param>
        public void NavigateTo(Route route, object?argument = null)
        {
            // Fire off the navigation started event
            var navigationStartedEventArgs = new RouterNavigationCancelEventArgs(route);

            NavigationStarted?.Invoke(this, navigationStartedEventArgs);

            // Cancel the navigation if the event was handled to do so
            if (navigationStartedEventArgs.Cancel)
            {
                NavigationCanceled?.Invoke(this, new RouterNavigationEventArgs(route));
                return;
            }

            // If the specified route doesn't exist or it's already active, raise the navigation error event and cancel the navigation
            if (!mRoutes.Contains(route))
            {
                NavigationError?.Invoke(this, new RouterNavigationErrorEventArgs(route, RouterNavigationError.NonExistingRoute));
                return;
            }
            else if (mActiveRoutes[route.Depth] == route)
            {
                NavigationError?.Invoke(this, new RouterNavigationErrorEventArgs(route, RouterNavigationError.RouteAlreadyActive));
                return;
            }

            // Otherwise set the destination route's argument and make it the active route on its depth
            route.Argument             = argument;
            mActiveRoutes[route.Depth] = route;

            // Raise the navigation completed event as navigation was successful
            NavigationCompleted?.Invoke(this, new RouterNavigationEventArgs(route));
        }
Example #2
0
        public async Task GoTo(PageType nextPageType, object parameter = null)
        {
            var nextPage = _pages[nextPageType];

            NavigationStarted?.Invoke(new NavigationEventArgs(_currentPage.Type, nextPageType));

            await _currentPage.Hide();

            _currentPage = nextPage;
            await nextPage.Show(parameter);

            NavigationEnded?.Invoke(new NavigationEventArgs(_currentPage.Type, nextPageType));
        }
        private async Task NavigateIntenal(object viewModel)
        {
            NavigationStarted?.Invoke(viewModel);

            var request = new NavigationRequest(viewModel);

            NavigationRequested?.Invoke(this, request);

            if (request.NavigationTasks != null)
            {
                await Task.WhenAll(request.NavigationTasks);
            }

            NavigatedTo?.Invoke(viewModel);
        }
        /// <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(NavigationStarted == null ? eventObject as NavigationRequestedDelegate : NavigationStarted.Invoke(eventObject as NavigationRequestedDelegate));

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

            case WebViewEventType.JavascriptCallback:
                var            data = (eventObject as JavascriptResponseDelegate).Data;
                ActionResponse ar;
                if (data.ValidateJSON() && (ar = data.AttemptParseActionResponse()) != null)
                {
                    if (RegisteredActions.ContainsKey(ar.Action))
                    {
                        RegisteredActions[ar.Action]?.Invoke(ar.Data);
                    }
                }
                else
                {
                    OnJavascriptResponse?.Invoke(eventObject as JavascriptResponseDelegate);
                }
                break;
            }

            return(eventObject);
        }