예제 #1
0
        public async Task <bool> GoBack()
        {
            var navigationEventHandlerArgs = new NavigationEventHandlerArgs(this.currentViewName, NavigationType.Backward, null);

            OnNavigatingFrom(navigationEventHandlerArgs);
            Task <NavigationResult>[] tasks = navigationEventHandlerArgs.Tasks.ToArray();

            NavigationResult[] navigationResults = await Task.WhenAll(tasks);

            if (navigationResults.Any(res => res == NavigationResult.Cancel))
            {
                return(false);
            }

            var poppedView = await NavigationPage.Navigation.PopAsync();

            this.currentViewName = NavigationPage.CurrentPage.GetType().Name;

            // If nothing is popped, we're at the main page, need to exit
            if (poppedView == null)
            {
                if (!lifecycleService.TryCloseApplication())
                {
                }
            }
            else if (this.currentViewName != null)
            {
                this.OnNavigatingTo(new NavigationEventHandlerArgs(currentViewName, NavigationType.Backward, null));
            }

            return(true);
        }
예제 #2
0
        public async Task <bool> GoBack()
        {
            if (this.CanGoBack)
            {
                var navigationEventHandlerArgs = new NavigationEventHandlerArgs(this.currentView, NavigationType.Backward, null);
                this.OnNavigatingFrom(navigationEventHandlerArgs);
                Task <NavigationResult>[] tasks = navigationEventHandlerArgs.Tasks.ToArray();

                NavigationResult[] navigationResults = await Task.WhenAll(tasks);

                if (navigationResults.Any(res => res == NavigationResult.Cancel))
                {
                    return(false);
                }

                this.frame.Navigated += this.FrameNavigatedBack;

                this.frame.GoBack();

                return(true);
            }
            else
            {
                if (!this.lifecycleService.TryCloseApplication())
                {
                }
            }

            return(false);
        }
예제 #3
0
        public async Task <bool> NavigateTo(string pageName, object parameter = null, bool removeBackEntry = false)
        {
            if (this.currentView != null)
            {
                var navigationEventHandlerArgs = new NavigationEventHandlerArgs(
                    this.currentView,
                    NavigationType.Forward,
                    parameter);

                this.OnNavigatingFrom(navigationEventHandlerArgs);
                Task <NavigationResult>[] tasks = navigationEventHandlerArgs.Tasks.ToArray();

                NavigationResult[] navigationResults = await Task.WhenAll(tasks);

                if (navigationResults.Any(res => res == NavigationResult.Cancel))
                {
                    return(false);
                }
            }

            var page = this.instanceFactory.GetInstanceByKey <Page>(pageName);

            page.Title = pageName;
            this.frame.Navigate(page, parameter);

            if (removeBackEntry)
            {
                this.frame.Navigated += this.RemoveBackEntry;
            }

            this.currentView = pageName;
            this.OnNavigatingTo(new NavigationEventHandlerArgs(this.currentView, NavigationType.Forward, parameter));

            return(true);
        }
예제 #4
0
        public async Task <bool> NavigateTo(string viewName, object parameter = null, bool removeBackEntry = false)
        {
            if (this.isNavigating)
            {
                return(false);
            }
            else
            {
                this.isNavigating = true;
            }

            Page desiredPage = this.instanceFactory.GetInstanceByKey <Page>(viewName);

            Page pageToRemove = null;

            if (desiredPage != null)
            {
                if (!string.IsNullOrEmpty(this.currentViewName))
                {
                    var navigationEventHandlerArgs = new NavigationEventHandlerArgs(this.currentViewName, NavigationType.Forward, parameter);
                    this.OnNavigatingFrom(navigationEventHandlerArgs);
                    Task <NavigationResult>[] tasks = navigationEventHandlerArgs.Tasks.ToArray();

                    NavigationResult[] navigationResults = await Task.WhenAll(tasks);

                    if (navigationResults.Any(res => res == NavigationResult.Cancel))
                    {
                        this.isNavigating = false;
                        return(false);
                    }
                }
                else
                {
                    if (this.NavigationPage.Navigation.NavigationStack.Count == 1)
                    {
                        pageToRemove = this.NavigationPage.CurrentPage;
                    }
                }

                this.PrePush(desiredPage, false);
                await this.NavigationPage.Navigation.PushAsync(desiredPage);

                if (pageToRemove != null)
                {
                    this.NavigationPage.Navigation.RemovePage(pageToRemove);
                }
                this.PostPush(desiredPage);

                this.currentViewName = viewName;
                this.OnNavigatingTo(new NavigationEventHandlerArgs(viewName, NavigationType.Forward, parameter));

                this.isNavigating = false;
                return(true);
            }

            this.isNavigating = false;
            return(false);
        }
예제 #5
0
        protected virtual void OnNavigatedTo(NavigationEventHandlerArgs e)
        {
            NavigationEventHandler handler = this.NavigatingTo;

            if (handler != null)
            {
                handler(this, e);
            }
        }
예제 #6
0
        protected virtual void OnNavigatingFrom(NavigationEventHandlerArgs e)
        {
            NavigationEventHandler handler = NavigatingFrom;

            if (handler != null)
            {
                handler(this, e);
            }
        }
예제 #7
0
        public async Task <bool> GoBack()
        {
            if (this.CanGoBack)
            {
                var navigationEventHandlerArgs = new NavigationEventHandlerArgs(this.currentView,
                                                                                NavigationType.Backward,
                                                                                null);
                this.OnNavigatingFrom(navigationEventHandlerArgs);
                Task <NavigationResult>[] tasks = navigationEventHandlerArgs.Tasks.ToArray();

                NavigationResult[] navigationResults = await Task.WhenAll(tasks);

                if (navigationResults.Any(res => res == NavigationResult.Cancel))
                {
                    return(false);
                }

                this.backStack.RemoveAt(this.backStack.Count - 1);
                var viewName = this.backStack[this.backStack.Count - 1];

                this.Bridge.SendMessage(
                    new BridgeMessage()
                {
                    FunctionName = "navigateTo", Params = new object[] { viewName }
                });

                this.currentView = viewName;

                if (this.currentView != null)
                {
                    this.OnNavigatedTo(new NavigationEventHandlerArgs(this.currentView, NavigationType.Backward,
                                                                      null));
                }
                else
                {
                    if (!this.lifecycleService.TryCloseApplication())
                    {
                    }
                }
                return(true);
            }
            else
            {
                if (!this.lifecycleService.TryCloseApplication())
                {
                }
            }
            return(false);
        }
예제 #8
0
        public async Task <bool> GoBack()
        {
            if (this.CanGoBack)
            {
                var navigationEventHandlerArgs = new NavigationEventHandlerArgs(this.currentViewName, NavigationType.Backward, null);

                this.OnNavigatingFrom(navigationEventHandlerArgs);
                Task <NavigationResult>[] tasks = navigationEventHandlerArgs.Tasks.ToArray();

                NavigationResult[] navigationResults = await Task.WhenAll(tasks);

                if (navigationResults.Any(res => res == NavigationResult.Cancel))
                {
                    return(false);
                }

                this.Frame.GoBack();

                this.currentViewName = this.Frame.Content?.GetType().Name;

                if (!string.IsNullOrEmpty(this.currentViewName))
                {
                    this.OnNavigatingTo(new NavigationEventHandlerArgs(this.currentViewName, NavigationType.Backward, null));
                }
                else
                {
                    if (!this.lifecycleService.TryCloseApplication())
                    {
                    }
                }

                return(true);
            }
            else
            {
                if (!this.lifecycleService.TryCloseApplication())
                {
                }
            }

            return(false);
        }
예제 #9
0
        private void NavigationServiceNavigatingFrom(object sender, NavigationEventHandlerArgs args)
        {
            if (args.PageView == this.pageName)
            {
                switch (args.NavigationType)
                {
                case NavigationType.Forward:
                    args.Tasks.Add(this.OnNavigatingForwardFromAsync());
                    break;

                case NavigationType.Backward:
                    args.Tasks.Add(this.OnNavigatingBackwardFromAsync());
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                this.OnNavigatingFrom();
            }
        }
예제 #10
0
        private void NavigationServiceNavigatingTo(object sender, NavigationEventHandlerArgs args)
        {
            if (args.PageView == this.pageName)
            {
                switch (args.NavigationType)
                {
                case NavigationType.Forward:
                    this.OnNavigatedForwardTo((TParam)args.Parameter);
                    break;

                case NavigationType.Backward:
                    this.OnNavigatedBackwardTo((TParam)args.Parameter);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                this.OnNavigatedTo((TParam)args.Parameter);
            }
        }
예제 #11
0
        public async Task <bool> NavigateTo(string pageName, object parameter = null, bool removeBackEntry = false)
        {
            if (!string.IsNullOrEmpty(this.currentViewName))
            {
                var navigationEventHandlerArgs = new NavigationEventHandlerArgs(
                    this.currentViewName,
                    NavigationType.Forward,
                    parameter);

                this.OnNavigatingFrom(navigationEventHandlerArgs);
                Task <NavigationResult>[] tasks = navigationEventHandlerArgs.Tasks.ToArray();

                NavigationResult[] navigationResults = await Task.WhenAll(tasks);

                if (navigationResults.Any(res => res == NavigationResult.Cancel))
                {
                    return(false);
                }
            }

            var page = this.instanceFactory.GetInstanceByKey <Page>(pageName);

            this.Frame.Navigate(page.GetType(), parameter);

            if (removeBackEntry)
            {
                this.Frame.BackStack.RemoveAt(this.Frame.BackStackDepth - 1);
            }

            string desiredViewName = this.Frame.Content?.GetType().Name;

            if (!string.IsNullOrEmpty(desiredViewName))
            {
                this.currentViewName = desiredViewName;
                this.OnNavigatingTo(new NavigationEventHandlerArgs(desiredViewName, NavigationType.Forward, parameter));
            }

            return(true);
        }
예제 #12
0
        public async Task <bool> NavigateTo(string pageName, object parameter = null, bool removeBackEntry = false)
        {
            if (this.currentView != null)
            {
                var navigationEventHandlerArgs = new NavigationEventHandlerArgs(
                    this.currentView,
                    NavigationType.Forward,
                    parameter);

                this.OnNavigatingFrom(navigationEventHandlerArgs);
                Task <NavigationResult>[] tasks = navigationEventHandlerArgs.Tasks.ToArray();

                NavigationResult[] navigationResults = await Task.WhenAll(tasks);

                if (navigationResults.Any(res => res == NavigationResult.Cancel))
                {
                    return(false);
                }
            }

            this.Bridge.SendMessage(
                new BridgeMessage()
            {
                FunctionName = "navigateTo", Params = new object[] { pageName }
            });

            if (!removeBackEntry)
            {
                this.backStack.Add(pageName);
            }

            this.currentView = pageName;
            this.OnNavigatedTo(new NavigationEventHandlerArgs(pageName, NavigationType.Forward, parameter));

            return(true);
        }
예제 #13
0
        protected virtual void OnNavigatingTo(NavigationEventHandlerArgs e)
        {
            NavigationEventHandler handler = this.NavigatingTo;

            handler?.Invoke(this, e);
        }