Пример #1
0
        void ConfigureTabbedPage(TabbedPage tabbedPage, string segment)
        {
            foreach (var child in tabbedPage.Children)
            {
                PageUtilities.SetAutowireViewModelOnPage(child);
                _pageBehaviorFactory.ApplyPageBehaviors(child);
                if (child is NavigationPage navPage)
                {
                    PageUtilities.SetAutowireViewModelOnPage(navPage.CurrentPage);
                    _pageBehaviorFactory.ApplyPageBehaviors(navPage.CurrentPage);
                }
            }

            var parameters = UriParsingHelper.GetSegmentParameters(segment);

            var tabsToCreate = parameters.GetValues <string>(KnownNavigationParameters.CreateTab);

            if (tabsToCreate.Count() > 0)
            {
                foreach (var tabToCreate in tabsToCreate)
                {
                    //created tab can be a single view or a view nested in a NavigationPage with the syntax "NavigationPage|ViewToCreate"
                    var tabSegements = tabToCreate.Split('|');
                    if (tabSegements.Length > 1)
                    {
                        var navigationPage = CreatePageFromSegment(tabSegements[0]) as NavigationPage;
                        if (navigationPage != null)
                        {
                            var navigationPageChild = CreatePageFromSegment(tabSegements[1]);

                            navigationPage.PushAsync(navigationPageChild);

                            //when creating a NavigationPage w/ DI, a blank Page object is injected into the ctor. Let's remove it
                            if (navigationPage.Navigation.NavigationStack.Count > 1)
                            {
                                navigationPage.Navigation.RemovePage(navigationPage.Navigation.NavigationStack[0]);
                            }

                            //set the title because Xamarin doesn't do this for us.
                            navigationPage.Title = navigationPageChild.Title;
                            navigationPage.Icon  = navigationPageChild.Icon;

                            tabbedPage.Children.Add(navigationPage);
                        }
                    }
                    else
                    {
                        var tab = CreatePageFromSegment(tabToCreate);
                        tabbedPage.Children.Add(tab);
                    }
                }
            }

            var selectedTab = parameters.GetValue <string>(KnownNavigationParameters.SelectedTab);

            if (!string.IsNullOrWhiteSpace(selectedTab))
            {
                var selectedTabType = PageNavigationRegistry.GetPageType(UriParsingHelper.GetSegmentName(selectedTab));

                var childFound = false;
                foreach (var child in tabbedPage.Children)
                {
                    if (!childFound && child.GetType() == selectedTabType)
                    {
                        tabbedPage.CurrentPage = child;
                        childFound             = true;
                    }

                    if (child is NavigationPage)
                    {
                        if (!childFound && ((NavigationPage)child).CurrentPage.GetType() == selectedTabType)
                        {
                            tabbedPage.CurrentPage = child;
                            childFound             = true;
                        }
                    }
                }
            }
        }
 private static void HandleIDestructiblePage(PopupPage page) =>
 PageUtilities.InvokeViewAndViewModelAction <IDestructible>(page, (view) => view.Destroy());
        void SetIsActive(object view, bool isActive)
        {
            var pageToSetIsActive = view is NavigationPage ? ((NavigationPage)view).CurrentPage : view;

            PageUtilities.InvokeViewAndViewModelAction <IActiveAware>(pageToSetIsActive, activeAware => activeAware.IsActive = isActive);
        }
Пример #4
0
        protected virtual async Task UseReverseNavigation(Page currentPage, string nextSegment, Queue <string> segments, INavigationParameters parameters, bool?useModalNavigation, bool animated)
        {
            var navigationStack = new Stack <string>();

            if (!String.IsNullOrWhiteSpace(nextSegment))
            {
                navigationStack.Push(nextSegment);
            }

            var illegalSegments = new Queue <string>();

            bool illegalPageFound = false;

            foreach (var item in segments)
            {
                //if we run into an illegal page, we need to create new navigation segments to properly handle the deep link
                if (illegalPageFound)
                {
                    illegalSegments.Enqueue(item);
                    continue;
                }

                //if any page decide to go modal, we need to consider it and all pages after it an illegal page
                var pageParameters = UriParsingHelper.GetSegmentParameters(item);
                if (pageParameters.ContainsKey(KnownNavigationParameters.UseModalNavigation))
                {
                    if (pageParameters.GetValue <bool>(KnownNavigationParameters.UseModalNavigation))
                    {
                        illegalSegments.Enqueue(item);
                        illegalPageFound = true;
                    }
                    else
                    {
                        navigationStack.Push(item);
                    }
                }
                else
                {
                    var pageType = PageNavigationRegistry.GetPageType(UriParsingHelper.GetSegmentName(item));
                    if (PageUtilities.IsSameOrSubclassOf <MasterDetailPage>(pageType))
                    {
                        illegalSegments.Enqueue(item);
                        illegalPageFound = true;
                    }
                    else
                    {
                        navigationStack.Push(item);
                    }
                }
            }

            var pageOffset = currentPage.Navigation.NavigationStack.Count;

            if (currentPage.Navigation.NavigationStack.Count > 2)
            {
                pageOffset = currentPage.Navigation.NavigationStack.Count - 1;
            }

            var onNavigatedFromTarget = currentPage;

            if (currentPage is NavigationPage navPage && navPage.CurrentPage != null)
            {
                onNavigatedFromTarget = navPage.CurrentPage;
            }

            bool insertBefore = false;

            while (navigationStack.Count > 0)
            {
                var segment  = navigationStack.Pop();
                var nextPage = CreatePageFromSegment(segment);
                await DoNavigateAction(onNavigatedFromTarget, segment, nextPage, parameters, async() =>
                {
                    await DoPush(currentPage, nextPage, useModalNavigation, animated, insertBefore, pageOffset);
                });

                insertBefore = true;
            }

            //if an illegal page is found, we force a Modal navigation
            if (illegalSegments.Count > 0)
            {
                await ProcessNavigation(currentPage.Navigation.NavigationStack.Last(), illegalSegments, parameters, true, animated);
            }
        }
Пример #5
0
        public static async Task <INavigationResult> GoBackToTargetInternal <T>(INavigationParameters parameters)
        {
            _logger?.Log();
            var result = new NavigationResult();

            try
            {
                if (parameters == null)
                {
                    parameters = new NavigationParameters();
                }

                ((INavigationParametersInternal)parameters).Add("__NavigationMode", NavigationMode.Back); // __NavigationMode is hardcode of Prism.Navigation.KnownInternalParameters.NavigationMode

                var currentPage = PageUtilities.GetCurrentPage(Application.Current.MainPage);

                NavigationPage navigationPage = null;
                var            tmp            = currentPage;
                while (tmp.Parent != null)
                {
                    if (tmp.Parent is NavigationPage)
                    {
                        navigationPage = tmp.Parent as NavigationPage;
                        break;
                    }
                    else
                    {
                        tmp = tmp.Parent as Page;
                    }
                }

                if (navigationPage == null)
                {
                    result.Exception = new NavigationException("Require NavigationPage", currentPage);
                    return(result);
                }

                var canNavigate = await PageUtilities.CanNavigateAsync(currentPage, parameters);

                if (!canNavigate)
                {
                    result.Exception = new NavigationException(NavigationException.IConfirmNavigationReturnedFalse, currentPage);
                    return(result);
                }

                // Cache the stack to avoid mutation.
                var  stack = currentPage.Navigation.NavigationStack.ToList();
                Page root  = navigationPage.RootPage; // Initial root value.

                var pagesToDestroy = new List <Page>();

                // For stack, A > B > C > D. We want to navigate from D to B.
                // A > B > D.
                // The remove order is D > C.
                for (int i = stack.Count - 1; i >= 1; i--) // i = 0 is root page. we don't remove it.
                {
                    var page = stack[i];
                    if (page.BindingContext.GetType() == typeof(T)) // Assume target key is ViewModel's name.
                    {
                        root = page;                                // Root is B.
                        break;
                    }
                    pagesToDestroy.Add(page);
                }

                // Temporary remove prism navigation aware
                var systemGoBackBehavior = navigationPage.Behaviors.FirstOrDefault(p => p is NavigationPageSystemGoBackBehavior);
                if (systemGoBackBehavior != null)
                {
                    navigationPage.Behaviors.Remove(systemGoBackBehavior);
                }

                for (int i = 1; i < pagesToDestroy.Count; i++) // Skip page D, remove page C,
                {
                    currentPage.Navigation.RemovePage(pagesToDestroy[i]);
                }

                await currentPage.Navigation.PopAsync();    // Navigate from D to B.

                foreach (var destroyPage in pagesToDestroy) // D, C OnNavigatedFrom and Destroy
                {
                    PageUtilities.OnNavigatedFrom(destroyPage, parameters);
                    PageUtilities.DestroyPage(destroyPage);
                }
                PageUtilities.OnNavigatedTo(root, parameters); // B OnNavigatedTo

                // Re-add prism navigation aware
                if (systemGoBackBehavior != null)
                {
                    navigationPage.Behaviors.Add(systemGoBackBehavior);
                }

                result.Success = true;
                return(result);
            }
            catch (Exception ex)
            {
                result.Exception = ex;
                return(result);
            }
        }
Пример #6
0
        protected override void OnSleep()
        {
            var page = PageUtilities.GetCurrentPage(MainPage);

            PageUtilities.InvokeViewAndViewModelAction <AppModel.IApplicationLifecycle>(page, x => x.OnSleep());
        }
Пример #7
0
        public void ShowDialog(string name, IDialogParameters parameters, Action <IDialogResult> callback)
        {
            try
            {
                parameters = UriParsingHelper.GetSegmentParameters(name, parameters);

                var view = CreateViewFor(UriParsingHelper.GetSegmentName(name));

                var dialogAware = InitializeDialog(view, parameters);
                var currentPage = GetCurrentPage();

                dialogAware.RequestClose += DialogAware_RequestClose;

                void DialogAware_RequestClose(IDialogParameters outParameters)
                {
                    try
                    {
                        var result = CloseDialog(outParameters ?? new DialogParameters(), currentPage);
                        if (result.Exception is DialogException de && de.Message == DialogException.CanCloseIsFalse)
                        {
                            return;
                        }

                        dialogAware.RequestClose -= DialogAware_RequestClose;
                        callback?.Invoke(result);
                        GC.Collect();
                    }
                    catch (DialogException dex)
                    {
                        if (dex.Message != DialogException.CanCloseIsFalse)
                        {
                            callback?.Invoke(new DialogResult
                            {
                                Exception  = dex,
                                Parameters = parameters
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                        callback?.Invoke(new DialogResult
                        {
                            Exception  = ex,
                            Parameters = parameters
                        });
                    }
                }

                if (!parameters.TryGetValue <bool>(KnownDialogParameters.CloseOnBackgroundTapped, out var closeOnBackgroundTapped))
                {
                    var dialogLayoutCloseOnBackgroundTapped = DialogLayout.GetCloseOnBackgroundTapped(view);
                    if (dialogLayoutCloseOnBackgroundTapped.HasValue)
                    {
                        closeOnBackgroundTapped = dialogLayoutCloseOnBackgroundTapped.Value;
                    }
                }

                InsertPopupViewInCurrentPage(currentPage as ContentPage, view, closeOnBackgroundTapped, DialogAware_RequestClose);

                PageUtilities.InvokeViewAndViewModelAction <IActiveAware>(currentPage, aa => aa.IsActive = false);
                PageUtilities.InvokeViewAndViewModelAction <IActiveAware>(view, aa => aa.IsActive        = true);
            }
            catch (Exception ex)
            {
                var error = ex.ToString();
                callback?.Invoke(new DialogResult {
                    Exception = ex
                });
            }
        }
Пример #8
0
 public void FilterByDepartment(string DepartmentName)
 {
     AboutPage.FilterByDepartment(DepartmentName);
     Assert.AreEqual(PageUtilities.GetRecordCount(), PageUtilities.GetPeopleDisplayedcount(), "Record count mismatch");
 }
Пример #9
0
        private async Task <NavigationResult> PushRegion(string path, INavigationParameters parameters)
        {
            var result = new NavigationResult();

            try
            {
                View currentRegion = null;
                parameters = GetParams(path, parameters);

                if (PagesContainer.Count > 0)
                {
                    currentRegion = PagesContainer.Last().Value;
                    var canNavigate = await PageUtilities.CanNavigateAsync(currentRegion, parameters);

                    if (!canNavigate)
                    {
                        result.Exception = new Exception(NavigationException.IConfirmNavigationReturnedFalse);
                        return(result);
                    }
                }

                View nextRegion = null;
                if (path.Contains('/'))
                {
                    foreach (var splitPath in path.Split(new[] { '/' },
                                                         StringSplitOptions.RemoveEmptyEntries))
                    {
                        if (PagesContainer.Keys.Contains(splitPath))
                        {
                            continue;
                        }
                        nextRegion = _containerProvider.ResolveRegion(splitPath);
                        PagesContainer.Add(splitPath, nextRegion);
                    }
                }
                else if (PagesContainer.Keys.Contains(path))
                {
                    nextRegion = PagesContainer[path];
                }
                else
                {
                    nextRegion = _containerProvider.ResolveRegion(path);
                    PagesContainer.Add(path, nextRegion);
                }

                GetContentPresenter().Content = nextRegion;

                await PageUtilities.OnInitializedAsync(currentRegion, parameters);

                PageUtilities.OnNavigatedFrom(currentRegion, parameters);
                PageUtilities.OnNavigatedTo(nextRegion, parameters);

                CurrentRegionName = path;
                NavigationHistory.Push(CurrentRegionName);

                result.Success = true;
                return(result);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                result.Exception = ex;
                return(result);
            }
        }
Пример #10
0
 private void OnNavigated(object sender, ShellNavigatedEventArgs e)
 {
     PageUtilities.InvokeViewAndViewModelAction <IInitialize>(AssociatedObject, aware => aware.Initialize(null));
 }
Пример #11
0
        internal ListItem GetPage(Web web, string listToLoad)
        {
            bool loadViaId = false;
            int  idToLoad  = -1;

            // Check what we got via the pagepipebind constructor and prep for getting the page
            if (!string.IsNullOrEmpty(this.name))
            {
                if (int.TryParse(this.Name, out int pageId))
                {
                    idToLoad  = pageId;
                    loadViaId = true;
                }
                else
                {
                    if (!this.BlogPage && !this.DelveBlogPage)
                    {
                        this.name = PageUtilities.EnsureCorrectPageName(this.name);
                    }
                    this.pageListItem = null;
                }
            }
            else if (this.pageListItem != null)
            {
                if (this.pageListItem != null)
                {
                    if (this.BlogPage || this.DelveBlogPage)
                    {
                        this.name = this.pageListItem.FieldValues["Title"].ToString();
                    }
                    else
                    {
                        this.name = this.pageListItem.FieldValues["FileLeafRef"].ToString();
                    }
                }
            }

            if (!string.IsNullOrEmpty(this.Library))
            {
                listToLoad = this.Library;
            }

            // Blogs live in a list, not in a library
            if (this.BlogPage && !listToLoad.StartsWith("lists/", StringComparison.InvariantCultureIgnoreCase))
            {
                listToLoad = $"lists/{listToLoad}";
            }

            web.EnsureProperty(w => w.ServerRelativeUrl);
            var listServerRelativeUrl = UrlUtility.Combine(web.ServerRelativeUrl, listToLoad);

            List libraryContainingPage = null;

            libraryContainingPage = web.GetList(listServerRelativeUrl);

            if (libraryContainingPage != null)
            {
                if (loadViaId)
                {
                    var page = libraryContainingPage.GetItemById(idToLoad);
                    web.Context.Load(page);
                    web.Context.ExecuteQueryRetry();
                    return(page);
                }
                else
                {
                    CamlQuery query = null;
                    if (!string.IsNullOrEmpty(this.name))
                    {
                        if (this.BlogPage || this.DelveBlogPage)
                        {
                            query = new CamlQuery
                            {
                                ViewXml = string.Format(CAMLQueryForBlogByTitle, System.Text.Encodings.Web.HtmlEncoder.Default.Encode(this.name))
                            };
                        }
                        else
                        {
                            query = new CamlQuery
                            {
                                ViewXml = string.Format(CAMLQueryByExtensionAndName, System.Text.Encodings.Web.HtmlEncoder.Default.Encode(this.name))
                            };
                        }

                        if (!string.IsNullOrEmpty(this.Folder))
                        {
                            libraryContainingPage.EnsureProperty(p => p.RootFolder);
                            query.FolderServerRelativeUrl = $"{libraryContainingPage.RootFolder.ServerRelativeUrl}/{Folder}";
                        }

                        var page = libraryContainingPage.GetItems(query);
                        web.Context.Load(page);
                        web.Context.ExecuteQueryRetry();

                        if (page.Count >= 1)
                        {
                            // Return the first match
                            return(page[0]);
                        }
                    }
                }
            }

            return(null);
        }
Пример #12
0
 private void OnDisappearing(object sender, EventArgs e)
 {
     PageUtilities.InvokeViewAndViewModelAction <IPageLifecycleAware>(AssociatedObject, aware => aware.OnDisappearing());
 }
Пример #13
0
 private static void OnNavigatedTo(Page toPage, NavigationParameters parameters)
 {
     PageUtilities.OnNavigatedTo(toPage, parameters);
 }
 void SetIsActive(object view, bool isActive)
 {
     PageUtilities.InvokeViewAndViewModelAction <IActiveAware>(_lastNavigationCurrent, activeAware => activeAware.IsActive = isActive);
 }
        public void DestroyTabbedPage()
        {
            var recorder            = new PageNavigationEventRecorder();
            var tabbedPage          = new TabbedPageMock(recorder);
            var tabbedPageViewModel = tabbedPage.BindingContext;
            var tab1               = tabbedPage.Children[0];
            var tab1ViewModel      = tab1.BindingContext;
            var tab2               = tabbedPage.Children[1];
            var tab2ViewModel      = tab2.BindingContext;
            var tab3               = tabbedPage.Children[2];
            var tab3ViewModel      = tab3.BindingContext;
            var tab4               = tabbedPage.Children[3];
            var tab4Child          = ((NavigationPage)tab4).CurrentPage;
            var tab4ViewModel      = tab4.BindingContext;
            var tab4ChildViewModel = tab4Child.BindingContext;
            var tab5               = tabbedPage.Children[4];
            var tab5Child          = ((NavigationPage)tab5).CurrentPage;
            var tab5ViewModel      = tab5.BindingContext;
            var tab5ChildViewModel = tab5Child.BindingContext;


            PageUtilities.DestroyPage(tabbedPage);

            Assert.Equal(13, recorder.Records.Count);

            //tab 5
            Assert.Equal(tab5ViewModel, recorder.Records[0].Sender);
            Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[0].Event);

            Assert.Equal(tab5, recorder.Records[1].Sender);
            Assert.Equal(0, tab5.Behaviors.Count);
            Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[1].Event);

            Assert.Equal(tab5ChildViewModel, recorder.Records[2].Sender);
            Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[2].Event);

            //tab 4
            Assert.Equal(tab4Child, recorder.Records[3].Sender);
            Assert.Equal(0, tab4Child.Behaviors.Count);
            Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[3].Event);

            Assert.Equal(tab4ChildViewModel, recorder.Records[4].Sender);
            Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[4].Event);

            Assert.Equal(tab4, recorder.Records[5].Sender);
            Assert.Equal(0, tab4.Behaviors.Count);
            Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[5].Event);

            Assert.Equal(tab4ViewModel, recorder.Records[6].Sender);
            Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[6].Event);

            //tab 3
            Assert.Equal(tab3, recorder.Records[7].Sender);
            Assert.Null(tab3.BindingContext);
            Assert.Equal(0, tab3.Behaviors.Count);
            Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[7].Event);

            Assert.Equal(tab3ViewModel, recorder.Records[8].Sender);
            Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[8].Event);

            //tab 2 : PageMock has no binding context so it has no entries.

            //tab 1
            Assert.Equal(tab1, recorder.Records[9].Sender);
            Assert.Null(tab1.BindingContext);
            Assert.Equal(0, tab1.Behaviors.Count);
            Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[9].Event);

            Assert.Equal(tab1ViewModel, recorder.Records[10].Sender);
            Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[10].Event);

            //TabbedPage
            Assert.Equal(tabbedPage, recorder.Records[11].Sender);
            Assert.Null(tabbedPage.BindingContext);
            Assert.Equal(0, tabbedPage.Behaviors.Count);
            Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[11].Event);

            Assert.Equal(tabbedPageViewModel, recorder.Records[12].Sender);
            Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[12].Event);
        }
        protected virtual async Task ProcessNavigationForMasterDetailPage(MasterDetailPage currentPage, string nextSegment, Queue <string> segments, INavigationParameters parameters, bool?useModalNavigation, bool animated)
        {
            bool isPresented = GetMasterDetailPageIsPresented(currentPage);

            var detail = currentPage.Detail;

            if (detail == null)
            {
                var newDetail = CreatePageFromSegment(nextSegment);
                await ProcessNavigation(newDetail, segments, parameters, useModalNavigation, animated);
                await DoNavigateAction(null, nextSegment, newDetail, parameters, onNavigationActionCompleted : () =>
                {
                    currentPage.IsPresented = isPresented;
                    currentPage.Detail      = newDetail;
                });

                return;
            }

            if (useModalNavigation.HasValue && useModalNavigation.Value)
            {
                var nextPage = CreatePageFromSegment(nextSegment);
                await ProcessNavigation(nextPage, segments, parameters, useModalNavigation, animated);
                await DoNavigateAction(currentPage, nextSegment, nextPage, parameters, async() =>
                {
                    currentPage.IsPresented = isPresented;
                    await DoPush(currentPage, nextPage, true, animated);
                });

                return;
            }

            var nextSegmentType = PageNavigationRegistry.GetPageType(UriParsingHelper.GetSegmentName(nextSegment));

            //we must recreate the NavigationPage everytime or the transitions on iOS will not work properly, unless we meet the two scenarios below
            bool detailIsNavPage = false;
            bool reuseNavPage    = false;

            if (detail is NavigationPage navPage)
            {
                detailIsNavPage = true;

                //first we check to see if we are being forced to reuse the NavPage by checking the interface
                reuseNavPage = !GetClearNavigationPageNavigationStack(navPage);

                if (!reuseNavPage)
                {
                    //if we weren't forced to reuse the NavPage, then let's check the NavPage.CurrentPage against the next segment type as we don't want to recreate the entire nav stack
                    //just in case the user is trying to navigate to the same page which may be nested in a NavPage
                    var nextPageType    = PageNavigationRegistry.GetPageType(UriParsingHelper.GetSegmentName(segments.Peek()));
                    var currentPageType = navPage.CurrentPage.GetType();

                    if (nextPageType == currentPageType)
                    {
                        reuseNavPage = true;
                    }
                }
            }

            if ((detailIsNavPage && reuseNavPage) || (!detailIsNavPage && detail.GetType() == nextSegmentType))
            {
                await ProcessNavigation(detail, segments, parameters, useModalNavigation, animated);
                await DoNavigateAction(null, nextSegment, detail, parameters, onNavigationActionCompleted : () =>
                {
                    currentPage.IsPresented = isPresented;
                });

                return;
            }
            else
            {
                var newDetail = CreatePageFromSegment(nextSegment);
                await ProcessNavigation(newDetail, segments, parameters, newDetail is NavigationPage?false : true, animated);
                await DoNavigateAction(detail, nextSegment, newDetail, parameters, onNavigationActionCompleted : () =>
                {
                    currentPage.IsPresented = isPresented;
                    currentPage.Detail      = newDetail;
                    PageUtilities.DestroyPage(detail);
                });

                return;
            }
        }
Пример #17
0
 void SetIsActive(object view, bool isActive)
 {
     PageUtilities.InvokeViewAndViewModelAction <IActiveAware>(_lastSelectedPage, activeAware => activeAware.IsActive = isActive);
 }
 public override void OnNavigatedFrom(INavigationParameters parameters)
 {
     PageUtilities.OnNavigatedFrom(currentView, parameters);
 }
Пример #19
0
        public static async Task <INavigationResult> SelectTabAsync(this INavigationService navigationService, string name, INavigationParameters parameters = null)
        {
            NavigationResult navigationResult = new NavigationResult {
                Success = true
            };

            try
            {
                var currentPage = ((IPageAware)navigationService).Page;
                var canNavigate = await PageUtilities.CanNavigateAsync(currentPage, parameters);

                if (!canNavigate)
                {
                    throw new Exception($"IConfirmNavigation for {currentPage} returned false");
                }
                TabbedPage tabbedPage = null;
                if (currentPage is TabbedPage)
                {
                    tabbedPage = currentPage as TabbedPage;
                }
                if (currentPage.Parent is TabbedPage parent)
                {
                    tabbedPage = parent;
                }
                else if (currentPage.Parent is NavigationPage navPage)
                {
                    if (navPage.Parent != null && navPage.Parent is TabbedPage parent2)
                    {
                        tabbedPage = parent2;
                    }
                }
                if (tabbedPage == null)
                {
                    throw new Exception("No parent TabbedPage could be found");
                }
                var tabToSelectedType = PageNavigationRegistry.GetPageType(UriParsingHelper.GetSegmentName(name));
                if (tabToSelectedType is null)
                {
                    throw new Exception($"No View Type has been registered for '{name}'");
                }
                Page target = null;
                foreach (var child in tabbedPage.Children)
                {
                    if (child.GetType() == tabToSelectedType)
                    {
                        target = child;
                        break;
                    }
                    if (child is NavigationPage childNavPage)
                    {
                        if (childNavPage.CurrentPage.GetType() == tabToSelectedType ||
                            childNavPage.RootPage.GetType() == tabToSelectedType)
                        {
                            target = child;
                            break;
                        }
                    }
                }
                if (target is null)
                {
                    throw new Exception($"Could not find a Child Tab for '{name}'");
                }
                var tabParameters = UriParsingHelper.GetSegmentParameters(name, parameters);
                tabbedPage.CurrentPage = target;
                PageUtilities.OnNavigatedFrom(currentPage, tabParameters);
                PageUtilities.OnNavigatedTo(target, tabParameters);
            }
            catch (Exception ex)
            {
                navigationResult = new NavigationResult {
                    Exception = ex
                };
            }
            return(navigationResult);
        }
 private void OnDisappearing(object sender, EventArgs e) =>
 PageUtilities.InvokeViewAndViewModelAction <IActiveAware>(AssociatedObject, v => v.IsActive = false);
Пример #21
0
        protected virtual async Task ProcessNavigationForNavigationPage(NavigationPage currentPage, string nextSegment, Queue <string> segments, INavigationParameters parameters, bool?useModalNavigation, bool animated)
        {
            if (currentPage.Navigation.NavigationStack.Count == 0)
            {
                await UseReverseNavigation(currentPage, nextSegment, segments, parameters, false, animated);

                return;
            }

            var clearNavigationStack     = GetClearNavigationPageNavigationStack(currentPage);
            var isEmptyOfNavigationStack = currentPage.Navigation.NavigationStack.Count == 0;

            List <Page> destroyPages;

            if (clearNavigationStack && !isEmptyOfNavigationStack)
            {
                destroyPages = currentPage.Navigation.NavigationStack.ToList();
                destroyPages.Reverse();

                await currentPage.Navigation.PopToRootAsync(false);
            }
            else
            {
                destroyPages = new List <Page>();
            }

            var topPage      = currentPage.Navigation.NavigationStack.LastOrDefault();
            var nextPageType = PageNavigationRegistry.GetPageType(UriParsingHelper.GetSegmentName(nextSegment));

            if (topPage?.GetType() == nextPageType)
            {
                if (clearNavigationStack)
                {
                    destroyPages.Remove(destroyPages.Last());
                }

                if (segments.Count > 0)
                {
                    await UseReverseNavigation(topPage, segments.Dequeue(), segments, parameters, false, animated);
                }

                await DoNavigateAction(topPage, nextSegment, topPage, parameters, onNavigationActionCompleted : () =>
                {
                    if (nextSegment.Contains(KnownNavigationParameters.SelectedTab))
                    {
                        var segmentParams = UriParsingHelper.GetSegmentParameters(nextSegment);
                        SelectPageTab(topPage, segmentParams);
                    }
                });
            }
            else
            {
                await UseReverseNavigation(currentPage, nextSegment, segments, parameters, false, animated);

                if (clearNavigationStack && !isEmptyOfNavigationStack)
                {
                    currentPage.Navigation.RemovePage(topPage);
                }
            }

            foreach (var destroyPage in destroyPages)
            {
                PageUtilities.DestroyPage(destroyPage);
            }
        }
 private static void HandleINavigatingAware(PopupPage page, NavigationParameters parameters) =>
 PageUtilities.InvokeViewAndViewModelAction <INavigatingAware>(page, (view) => view.OnNavigatingTo(parameters));
Пример #23
0
 internal static bool UseReverseNavigation(Page currentPage, Type nextPageType)
 {
     return(PageUtilities.HasNavigationPageParent(currentPage) && PageUtilities.IsSameOrSubclassOf <ContentPage>(nextPageType));
 }
Пример #24
0
        protected virtual async Task ProcessNavigationForNavigationPage(NavigationPage currentPage, string nextSegment, Queue <string> segments, NavigationParameters parameters, bool?useModalNavigation, bool animated)
        {
            if (currentPage.Navigation.NavigationStack.Count == 0)
            {
                await UseReverseNavigation(currentPage, nextSegment, segments, parameters, false, animated);

                return;
            }

            var clearNavigationStack     = GetClearNavigationPageNavigationStack(currentPage);
            var isEmptyOfNavigationStack = currentPage.Navigation.NavigationStack.Count == 0;

            List <Page> destroyPages;

            if (clearNavigationStack && !isEmptyOfNavigationStack)
            {
                destroyPages = currentPage.Navigation.NavigationStack.ToList();
                destroyPages.Reverse();

                await currentPage.Navigation.PopToRootAsync(false);
            }
            else
            {
                destroyPages = new List <Page>();
            }

            var topPage      = currentPage.Navigation.NavigationStack.LastOrDefault();
            var nextPageType = PageNavigationRegistry.GetPageType(UriParsingHelper.GetSegmentName(nextSegment));

            if (topPage?.GetType() == nextPageType)
            {
                if (clearNavigationStack)
                {
                    destroyPages.Remove(destroyPages.Last());
                }

                await ProcessNavigation(topPage, segments, parameters, false, animated);
                await DoNavigateAction(topPage, nextSegment, topPage, parameters);
            }
            else
            {
                // Replace RootPage of NavigationStack
                var nextPage = CreatePageFromSegment(nextSegment);
                await ProcessNavigation(nextPage, segments, parameters, false, animated);
                await DoNavigateAction(topPage ?? currentPage, nextSegment, nextPage, parameters, async() =>
                {
                    var push = DoPush(currentPage, nextPage, false, animated);

                    if (clearNavigationStack && !isEmptyOfNavigationStack)
                    {
                        currentPage.Navigation.RemovePage(topPage);
                    }

                    await push;
                });
            }

            foreach (var destroyPage in destroyPages)
            {
                PageUtilities.DestroyPage(destroyPage);
            }
        }