Exemplo n.º 1
0
        /// <summary>
        /// Initiates navigation to the target specified by the <paramref name="uri"/>.
        /// </summary>
        /// <param name="uri">The Uri to navigate to</param>
        /// <param name="parameters">The navigation parameters</param>
        /// <param name="useModalNavigation">If <c>true</c> uses PopModalAsync, if <c>false</c> uses PopAsync</param>
        /// <param name="animated">If <c>true</c> the transition is animated, if <c>false</c> there is no animation on transition.</param>
        /// <remarks>Navigation parameters can be provided in the Uri and by using the <paramref name="parameters"/>.</remarks>
        /// <example>
        /// Navigate(new Uri("MainPage?id=3&name=brian", UriKind.RelativeSource), parameters);
        /// </example>
        public virtual Task NavigateAsync(Uri uri, NavigationParameters parameters = null, bool?useModalNavigation = null, bool animated = true)
        {
            try
            {
                NavigationSource = PageNavigationSource.NavigationService;

                var navigationSegments = UriParsingHelper.GetUriSegments(uri);

                if (uri.IsAbsoluteUri)
                {
                    return(ProcessNavigationForAbsoulteUri(navigationSegments, parameters, useModalNavigation, animated));
                }
                else
                {
                    return(ProcessNavigation(GetCurrentPage(), navigationSegments, parameters, useModalNavigation, animated));
                }
            }
            catch (Exception e)
            {
                _logger.Log(e.ToString(), Category.Exception, Priority.High);
                throw;
            }
            finally
            {
                NavigationSource = PageNavigationSource.Device;
            }
        }
Exemplo n.º 2
0
        protected virtual async Task ProcessNavigationForCarouselPage(CarouselPage currentPage, string nextSegment, Queue <string> segments, NavigationParameters parameters, bool?useModalNavigation, bool animated)
        {
            var nextSegmentType = PageNavigationRegistry.GetPageType(UriParsingHelper.GetSegmentName(nextSegment));

            foreach (var child in currentPage.Children)
            {
                if (child.GetType() != nextSegmentType)
                {
                    continue;
                }

                await ProcessNavigation(child, segments, parameters, useModalNavigation, animated);
                await DoNavigateAction(null, nextSegment, child, parameters, onNavigationActionCompleted : () =>
                {
                    currentPage.CurrentPage = child;
                });

                return;
            }

            var nextPage = CreatePageFromSegment(nextSegment);

            await ProcessNavigation(nextPage, segments, parameters, useModalNavigation, animated);
            await DoNavigateAction(currentPage, nextSegment, nextPage, parameters, async() =>
            {
                await DoPush(currentPage, nextPage, useModalNavigation, animated);
            });
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NavigationContext"/> class for a region name and a
        /// <see cref="Uri"/>.
        /// </summary>
        /// <param name="navigationService">The navigation service.</param>
        /// <param name="navigationParameters">The navigation parameters.</param>
        /// <param name="uri">The Uri.</param>
        public NavigationContext(IRegionNavigationService navigationService, Uri uri, IDictionary <string, object> args)
        {
            NavigationService = navigationService;
            Uri  = uri;
            Args = uri != null?UriParsingHelper.ParseQuery(uri) : null;

            GetNavigationArgs(args);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NavigationContext"/> class for a region name and a
        /// <see cref="Uri"/>.
        /// </summary>
        /// <param name="navigationService">The navigation service.</param>
        /// <param name="navigationParameters">The navigation parameters.</param>
        /// <param name="uri">The Uri.</param>
        public NavigationContext(IRegionNavigationService navigationService, Uri uri, NavigationParameters navigationParameters)
        {
            NavigationService = navigationService;
            Uri        = uri;
            Parameters = uri != null?UriParsingHelper.ParseQuery(uri) : null;

            GetNavigationParameters(navigationParameters);
        }
        public void ParseForAbsoluteUriWithOutProtocol()
        {
            var uri = UriParsingHelper.Parse(_absoluteUriWithOutProtocol);

            Assert.NotNull(uri);
            Assert.Equal("http://localhost" + _absoluteUriWithOutProtocol, uri.OriginalString);
            Assert.True(uri.IsAbsoluteUri);
        }
        public void ParseForDeepLinkRelativeUri()
        {
            var uri = UriParsingHelper.Parse(_deepLinkRelativeUri);

            Assert.NotNull(uri);
            Assert.Equal(_deepLinkRelativeUri, uri.OriginalString);
            Assert.False(uri.IsAbsoluteUri);
        }
        public void ParseForAbsoluteUri()
        {
            var uri = UriParsingHelper.Parse(_absoluteUri);

            Assert.NotNull(uri);
            Assert.Equal(_absoluteUri, uri.OriginalString);
            Assert.True(uri.IsAbsoluteUri);
        }
Exemplo n.º 8
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());
                }

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

                await DoNavigateAction(topPage, nextSegment, topPage, parameters);
            }
            else
            {
                await UseReverseNavigation(currentPage, nextSegment, segments, parameters, false, animated);

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

            foreach (var destroyPage in destroyPages)
            {
                PageUtilities.DestroyPage(destroyPage);
            }
        }
Exemplo n.º 9
0
        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));

            if (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;
            }
        }
Exemplo n.º 10
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)
            {
                var newRoot = CreatePageFromSegment(nextSegment);
                await ProcessNavigation(newRoot, segments, parameters, false, animated);
                await DoNavigateAction(currentPage, nextSegment, newRoot, parameters, async() =>
                {
                    await DoPush(currentPage, newRoot, false, animated);
                });

                return;
            }

            bool clearNavStack = GetClearNavigationPageNavigationStack(currentPage);

            var currentNavRoot = currentPage.Navigation.NavigationStack[0];
            var nextPageType   = PageNavigationRegistry.GetPageType(UriParsingHelper.GetSegmentName(nextSegment));

            if (currentNavRoot.GetType() == nextPageType)
            {
                if (clearNavStack && currentPage.Navigation.NavigationStack.Count > 1)
                {
                    await currentPage.Navigation.PopToRootAsync(false);
                }

                await ProcessNavigation(currentNavRoot, segments, parameters, false, animated);
                await DoNavigateAction(currentNavRoot, nextSegment, currentNavRoot, parameters);

                return;
            }
            else
            {
                if (clearNavStack && currentPage.Navigation.NavigationStack.Count > 1)
                {
                    await currentPage.Navigation.PopToRootAsync(false);
                }

                var newRoot = CreatePageFromSegment(nextSegment);
                await ProcessNavigation(newRoot, segments, parameters, false, animated);

                await DoNavigateAction(currentNavRoot, nextSegment, newRoot, parameters, async() =>
                {
                    var push = DoPush(currentPage, newRoot, false, animated);

                    if (clearNavStack && currentPage.Navigation.NavigationStack.Count > 1)
                    {
                        currentPage.Navigation.RemovePage(currentNavRoot);
                        PageUtilities.DestroyPage(currentNavRoot);
                    }

                    await push;
                });

                return;
            }
        }
Exemplo n.º 11
0
        private void OnGoToPageExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            var uri        = new Uri(e.Parameter as string, UriKind.Relative);
            var target     = UriParsingHelper.GetAbsolutePath(uri);
            var parameters = UriParsingHelper.ParseQuery(uri);

            this.RegionManager.RequestNavigate(RegionNames.MainContent, target, parameters);
            e.Handled = true;
        }
Exemplo n.º 12
0
        /// <summary>
        /// Initiates navigation to the target specified by the <paramref name="name"/>.
        /// </summary>
        /// <param name="name">The name of the target to navigate to.</param>
        /// <param name="parameters">The navigation parameters</param>
        /// <param name="useModalNavigation">If <c>true</c> uses PopModalAsync, if <c>false</c> uses PopAsync</param>
        /// <param name="animated">If <c>true</c> the transition is animated, if <c>false</c> there is no animation on transition.</param>
        public virtual Task NavigateAsync(string name, NavigationParameters parameters = null, bool?useModalNavigation = null, bool animated = true)
        {
            if (name.StartsWith(RemovePageRelativePath))
            {
                name = name.Replace(RemovePageRelativePath, RemovePageInstruction);
            }

            return(NavigateAsync(UriParsingHelper.Parse(name), parameters, useModalNavigation, animated));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Initiates navigation to the target specified by the <paramref name="name"/>.
        /// </summary>
        /// <param name="name">The name of the target to navigate to.</param>
        /// <param name="parameters">The navigation parameters</param>
        /// <param name="useModalNavigation">If <c>true</c> uses PopModalAsync, if <c>false</c> uses PopAsync</param>
        /// <param name="animated">If <c>true</c> the transition is animated, if <c>false</c> there is no animation on transition.</param>
        protected virtual Task <INavigationResult> NavigateInternal(string name, INavigationParameters parameters, bool?useModalNavigation, bool animated)
        {
            if (name.StartsWith(RemovePageRelativePath))
            {
                name = name.Replace(RemovePageRelativePath, RemovePageInstruction);
            }

            return(NavigateInternal(UriParsingHelper.Parse(name), parameters, useModalNavigation, animated));
        }
Exemplo n.º 14
0
        Task INavigateInternal.NavigateInternal(string name, NavigationParameters parameters, bool?useModalNavigation, bool animated)
        {
            if (name.StartsWith(RemovePageRelativePath))
            {
                name = name.Replace(RemovePageRelativePath, RemovePageInstruction);
            }

            return(((INavigateInternal)this).NavigateInternal(UriParsingHelper.Parse(name), parameters, useModalNavigation, animated));
        }
Exemplo n.º 15
0
        protected override async Task <INavigationResult> GoBackInternal(INavigationParameters parameters, bool?useModalNavigation, bool animated)
        {
            INavigationResult result = null;

            try
            {
                NavigationSource = PageNavigationSource.NavigationService;

                switch (PopupUtilities.TopPage(_popupNavigation, _applicationProvider))
                {
                case PopupPage popupPage:
                    var segmentParameters = UriParsingHelper.GetSegmentParameters(null, parameters);
                    ((INavigationParametersInternal)segmentParameters).Add("__NavigationMode", NavigationMode.Back);
                    var previousPage = PopupUtilities.GetOnNavigatedToTarget(_popupNavigation, _applicationProvider);

                    PageUtilities.OnNavigatingTo(previousPage, segmentParameters);
                    await DoPop(popupPage.Navigation, false, animated);

                    if (popupPage != null)
                    {
                        PageUtilities.InvokeViewAndViewModelAction <IActiveAware>(popupPage, a => a.IsActive = false);
                        PageUtilities.OnNavigatedFrom(popupPage, segmentParameters);
                        PageUtilities.OnNavigatedTo(previousPage, segmentParameters);
                        await InvokeOnNavigatedToAsync(previousPage, segmentParameters);

                        PageUtilities.InvokeViewAndViewModelAction <IActiveAware>(previousPage, a => a.IsActive = true);
                        PageUtilities.DestroyPage(popupPage);
                        result = new NavigationResult {
                            Success = true
                        };
                        break;
                    }
                    throw new NullReferenceException("The PopupPage was null following the Pop");

                default:
                    result = await base.GoBackInternal(parameters, useModalNavigation, animated);

                    break;
                }
            }
            catch (Exception e)
            {
#if DEBUG
                System.Diagnostics.Debugger.Break();
#endif
                _logger.Log(e.ToString(), Category.Exception, Priority.High);
                result = new NavigationResult {
                    Success = false, Exception = e
                };;
            }
            finally
            {
                NavigationSource = PageNavigationSource.Device;
            }
            return(result);
        }
Exemplo n.º 16
0
        internal NavigationBuilder(INavigationService navigationService, string name)
            : this(navigationService, NavigationInstruction.Navigate)
        {
            if (name.StartsWith(RemovePageRelativePath))
            {
                name = name.Replace(RemovePageRelativePath, RemovePageInstruction);
            }

            _uri = UriParsingHelper.Parse(name);
        }
Exemplo n.º 17
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);
                    }
                }
            }

            TabbedPageSelectTab(tabbedPage, parameters);
        }
Exemplo n.º 18
0
        async Task ProcessNavigationForMasterDetailPage(MasterDetailPage currentPage, string nextSegment, Queue <string> segments, NavigationParameters parameters, bool?useModalNavigation, bool animated)
        {
            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 = false;
                    await DoPush(currentPage, nextPage, true, animated);
                });

                return;
            }

            var detail = currentPage.Detail;

            if (detail == null)
            {
                var newDetail = CreatePageFromSegment(nextSegment);
                await ProcessNavigation(newDetail, segments, parameters, newDetail is NavigationPage?false : true, animated);
                await DoNavigateAction(null, nextSegment, newDetail, parameters, () =>
                {
                    currentPage.Detail      = newDetail;
                    currentPage.IsPresented = false;
                });

                return;
            }

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

            if (detail.GetType() == nextSegmentType)
            {
                await ProcessNavigation(detail, segments, parameters, useModalNavigation, animated);
                await DoNavigateAction(null, nextSegment, detail, parameters, () =>
                {
                    currentPage.IsPresented = false;
                });

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

                return;
            }
        }
        /// <summary>
        /// Returns the candidate TargetContract based on the <see cref="NavigationContext"/>.
        /// </summary>
        /// <param name="navigationContext">The navigation contract.</param>
        /// <returns>The candidate contract to seek within the <see cref="IRegion"/> and to use, if not found, when resolving from the container.</returns>
        protected virtual string GetContractFromNavigationContext(NavigationContext navigationContext)
        {
            if (navigationContext == null)
            {
                throw new ArgumentNullException(nameof(navigationContext));
            }
            var candidateTargetContract = UriParsingHelper.GetAbsolutePath(navigationContext.Uri);

            candidateTargetContract = candidateTargetContract.TrimStart('/');
            return(candidateTargetContract);
        }
Exemplo n.º 20
0
        private static BaseShellItem GetShellItem(IList <ShellContent> items, string name)
        {
            var shellItem = items.FirstOrDefault(x => !IsImplicitRoute(x) && UriParsingHelper.GetSegmentName(x.Route) == name);

            if (shellItem != null)
            {
                return(shellItem);
            }

            return(null);
        }
Exemplo n.º 21
0
        void ConfigureCarouselPage(CarouselPage carouselPage, string segment)
        {
            foreach (var child in carouselPage.Children)
            {
                PageUtilities.SetAutowireViewModelOnPage(child);
            }

            var parameters = UriParsingHelper.GetSegmentParameters(segment);

            CarouselPageSelectTab(carouselPage, parameters);
        }
Exemplo n.º 22
0
        private static void BeginLoad_OnUIThread(AsyncCallback userCallback, PageResourceContentLoaderAsyncResult result)
        {
            if (result.Exception != null)
            {
                result.IsCompleted = true;
                userCallback(result);
                return;
            }

            try
            {
                string pagePathAndName = UriParsingHelper.InternalUriGetBaseValue(result.Uri);

                Type factoryType = GetXamlPageFactoryType(pagePathAndName);

                if (factoryType == null)
                {
                    result.Exception = new InvalidOperationException(
                        String.Format(
                            CultureInfo.CurrentCulture,
                            Resource.PageResourceContentLoader_NoXAMLWasFound,
                            pagePathAndName));
                    return;
                }

                try
                {
                    result.Content = factoryType.GetMethod("Instantiate").Invoke(null, null);
                }
                catch (Exception ex)
                {
                    result.Exception = new InvalidOperationException(
                        String.Format(
                            CultureInfo.CurrentCulture,
                            Resource.PageResourceContentLoader_XAMLWasUnloadable,
                            pagePathAndName),
                        ex);
                    return;
                }
            }
            catch (Exception ex)
            {
                result.Exception = ex;
            }
            finally
            {
                result.IsCompleted = true;
                if (userCallback != null)
                {
                    userCallback(result);
                }
            }
        }
        public void ParametersParsedFromAbsoluteUri()
        {
            var parameters = UriParsingHelper.GetSegmentParameters(_absoluteUri);

            Assert.NotEmpty(parameters);

            Assert.Contains("id", parameters.Keys);
            Assert.Contains("name", parameters.Keys);

            Assert.Equal("3", parameters["id"]);
            Assert.Equal("brian", parameters["name"]);
        }
Exemplo n.º 24
0
        Page CreatePageFromSegment(string segment)
        {
            var segmentName = UriParsingHelper.GetSegmentName(segment);
            var page        = CreatePage(segmentName);

            if (page == null)
            {
                throw new InvalidOperationException(string.Format("{0} could not be created. Please make sure you have registered {0} for navigation.", segmentName));
            }

            return(page);
        }
        /// <summary>
        /// Navigates to the most recent entry in the back navigation history by popping the calling Page off the navigation stack.
        /// </summary>
        /// <param name="parameters">The navigation parameters</param>
        /// <param name="useModalNavigation">If <c>true</c> uses PopModalAsync, if <c>false</c> uses PopAsync</param>
        /// <param name="animated">If <c>true</c> the transition is animated, if <c>false</c> there is no animation on transition.</param>
        /// <returns>If <c>true</c> a go back operation was successful. If <c>false</c> the go back operation failed.</returns>
        protected virtual async Task <INavigationResult> GoBackInternal(INavigationParameters parameters, bool?useModalNavigation, bool animated)
        {
            var result = new NavigationResult();

            try
            {
                NavigationSource = PageNavigationSource.NavigationService;

                var page = GetCurrentPage();
                var segmentParameters = UriParsingHelper.GetSegmentParameters(null, parameters);
                segmentParameters.GetNavigationParametersInternal().Add(KnownInternalParameters.NavigationMode, NavigationMode.Back);

                var canNavigate = await PageUtilities.CanNavigateAsync(page, segmentParameters);

                if (!canNavigate)
                {
                    result.Exception = new Exception($"IConfirmNavigation for {page} returned false");
                    return(result);
                }

                bool useModalForDoPop = UseModalNavigation(page, useModalNavigation);
                Page previousPage     = PageUtilities.GetOnNavigatedToTarget(page, _applicationProvider.MainPage, useModalForDoPop);

                PageUtilities.OnNavigatingTo(previousPage, segmentParameters);
                await PageUtilitiesExtended.OnNavigatingToAsync(previousPage, segmentParameters);

                var poppedPage = await DoPop(page.Navigation, useModalForDoPop, animated);

                if (poppedPage != null)
                {
                    PageUtilities.OnNavigatedFrom(page, segmentParameters);
                    PageUtilities.OnNavigatedTo(previousPage, segmentParameters);
                    PageUtilities.DestroyPage(poppedPage);

                    result.Success = true;
                    return(result);
                }
            }
            catch (Exception ex)
            {
                _logger.Log(ex.ToString(), Category.Exception, Priority.High);
                result.Exception = ex;
                return(result);
            }
            finally
            {
                NavigationSource = PageNavigationSource.Device;
            }

            result.Exception = new Exception("Unknown error occured.");
            return(result);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NavigationContext"/> class for a region name and a
        /// <see cref="Uri"/>.
        /// </summary>
        /// <param name="navigationService">The navigation service.</param>
        /// <param name="regionParameters">The navigation parameters.</param>
        /// <param name="uri">The Uri.</param>
        public NavigationContext(IRegionNavigationService navigationService, Uri uri, INavigationParameters regionParameters)
        {
            NavigationService = navigationService;
            Uri        = uri;
            Parameters = regionParameters ?? new NavigationParameters();

            var queryString = uri != null?UriParsingHelper.EnsureAbsolute(uri).Query : null;

            if (!string.IsNullOrEmpty(queryString))
            {
                UpdateRegionParameters(new NavigationParameters(queryString));
            }
        }
Exemplo n.º 27
0
        private async Task NavigateInternal(Uri uri, IParameters parameters)
        {
            var navigationSegments = UriParsingHelper.GetUriSegments(uri);

            if (uri.IsAbsoluteUri || _rootNavigationController.View is null)
            {
                await ProcessNavigationForAbsoulteUri(navigationSegments, parameters);
            }
            else
            {
                await ProcessNavigation(_scopedViewLocator.View, navigationSegments, parameters);
            }
        }
Exemplo n.º 28
0
        /// <summary>
        /// Initiates navigation to the target specified by the <paramref name="uri"/>.
        /// </summary>
        /// <param name="uri">The Uri to navigate to</param>
        /// <param name="parameters">The navigation parameters</param>
        /// <param name="useModalNavigation">If <c>true</c> uses PopModalAsync, if <c>false</c> uses PopAsync</param>
        /// <param name="animated">If <c>true</c> the transition is animated, if <c>false</c> there is no animation on transition.</param>
        /// <remarks>Navigation parameters can be provided in the Uri and by using the <paramref name="parameters"/>.</remarks>
        /// <example>
        /// Navigate(new Uri("MainPage?id=3&name=brian", UriKind.RelativeSource), parameters);
        /// </example>
        public virtual Task NavigateAsync(Uri uri, NavigationParameters parameters = null, bool?useModalNavigation = null, bool animated = true)
        {
            var navigationSegments = UriParsingHelper.GetUriSegments(uri);

            if (uri.IsAbsoluteUri)
            {
                return(ProcessNavigationForAbsoulteUri(navigationSegments, parameters, useModalNavigation, animated));
            }
            else
            {
                return(ProcessNavigation(GetCurrentPage(), navigationSegments, parameters, useModalNavigation, animated));
            }
        }
Exemplo n.º 29
0
        public void ParametersParsedFromAbsoluteUri()
        {
            var uri        = new Uri(_absoluteUri, UriKind.Absolute);
            var parameters = UriParsingHelper.ParseQuery(uri);

            Assert.NotEmpty(parameters);

            Assert.Contains("id", parameters.Keys);
            Assert.Contains("name", parameters.Keys);

            Assert.Equal("3", parameters["id"]);
            Assert.Equal("brian", parameters["name"]);
        }
Exemplo n.º 30
0
        protected virtual async Task ProcessNavigation(Page currentPage, Queue <string> segments, INavigationParameters parameters, bool?useModalNavigation, bool animated)
        {
            if (segments.Count == 0)
            {
                return;
            }

            var nextSegment = segments.Dequeue();

            var pageParameters = UriParsingHelper.GetSegmentParameters(nextSegment);

            if (pageParameters.ContainsKey(KnownNavigationParameters.UseModalNavigation))
            {
                useModalNavigation = pageParameters.GetValue <bool>(KnownNavigationParameters.UseModalNavigation);
            }

            if (nextSegment == RemovePageSegment)
            {
                await ProcessNavigationForRemovePageSegments(currentPage, nextSegment, segments, parameters, useModalNavigation, animated);

                return;
            }

            if (currentPage == null)
            {
                await ProcessNavigationForRootPage(nextSegment, segments, parameters, useModalNavigation, animated);

                return;
            }

            if (currentPage is ContentPage)
            {
                await ProcessNavigationForContentPage(currentPage, nextSegment, segments, parameters, useModalNavigation, animated);
            }
            else if (currentPage is NavigationPage)
            {
                await ProcessNavigationForNavigationPage((NavigationPage)currentPage, nextSegment, segments, parameters, useModalNavigation, animated);
            }
            else if (currentPage is TabbedPage)
            {
                await ProcessNavigationForTabbedPage((TabbedPage)currentPage, nextSegment, segments, parameters, useModalNavigation, animated);
            }
            else if (currentPage is CarouselPage)
            {
                await ProcessNavigationForCarouselPage((CarouselPage)currentPage, nextSegment, segments, parameters, useModalNavigation, animated);
            }
            else if (currentPage is MasterDetailPage)
            {
                await ProcessNavigationForMasterDetailPage((MasterDetailPage)currentPage, nextSegment, segments, parameters, useModalNavigation, animated);
            }
        }