コード例 #1
0
ファイル: ShellUriHandler.cs プロジェクト: redjaguar/maui
        internal static NavigationRequest GetNavigationRequest(Shell shell, Uri uri, bool enableRelativeShellRoutes = false, bool throwNavigationErrorAsException = true, ShellNavigationParameters shellNavigationParameters = null)
        {
            uri = FormatUri(uri, shell);

            // figure out the intent of the Uri
            NavigationRequest.WhatToDoWithTheStack whatDoIDo = CalculateStackRequest(uri);

            Uri request = ConvertToStandardFormat(shell, uri);


            var possibleRouteMatches = GenerateRoutePaths(shell, request, uri, enableRelativeShellRoutes);


            if (possibleRouteMatches.Count == 0)
            {
                if (throwNavigationErrorAsException)
                {
                    throw new ArgumentException($"unable to figure out route for: {uri}", nameof(uri));
                }

                return(null);
            }
            else if (possibleRouteMatches.Count > 1)
            {
                string[] matches = new string[possibleRouteMatches.Count];
                int      i       = 0;
                foreach (var match in possibleRouteMatches)
                {
                    matches[i] = match.PathFull;
                    i++;
                }

                string matchesFound = String.Join(",", matches);

                if (throwNavigationErrorAsException)
                {
                    throw new ArgumentException($"Ambiguous routes matched for: {uri} matches found: {matchesFound}", nameof(uri));
                }

                return(null);
            }

            var theWinningRoute = possibleRouteMatches[0];

            RequestDefinition definition =
                new RequestDefinition(theWinningRoute, shell);

            NavigationRequest navigationRequest = new NavigationRequest(definition, whatDoIDo, request.Query, request.Fragment);

            return(navigationRequest);
        }
コード例 #2
0
ファイル: ShellItem.cs プロジェクト: yan2oo7/Xamarin.Forms
		internal Task GoToPart(NavigationRequest request, Dictionary<string, string> queryData)
		{
			var shellSection = request.Request.Section;

			if (shellSection == null)
				shellSection = ShellItemController.GetItems()[0];

			Shell.ApplyQueryAttributes(shellSection, queryData, request.Request.Content == null);

			if (CurrentItem != shellSection)
				SetValueFromRenderer(CurrentItemProperty, shellSection);

			return shellSection.GoToPart(request, queryData);
		}
コード例 #3
0
		internal static NavigationRequest GetNavigationRequest(Shell shell, Uri uri, bool enableRelativeShellRoutes = false)
		{
			uri = FormatUri(uri, shell);
			// figure out the intent of the Uri
			NavigationRequest.WhatToDoWithTheStack whatDoIDo = NavigationRequest.WhatToDoWithTheStack.PushToIt;
			if (uri.IsAbsoluteUri)
				whatDoIDo = NavigationRequest.WhatToDoWithTheStack.ReplaceIt;
			else if (uri.OriginalString.StartsWith("//", StringComparison.Ordinal) || uri.OriginalString.StartsWith("\\\\", StringComparison.Ordinal))
				whatDoIDo = NavigationRequest.WhatToDoWithTheStack.ReplaceIt;
			else
				whatDoIDo = NavigationRequest.WhatToDoWithTheStack.PushToIt;

			Uri request = ConvertToStandardFormat(shell, uri);

			var possibleRouteMatches = GenerateRoutePaths(shell, request, uri, enableRelativeShellRoutes);


			if (possibleRouteMatches.Count == 0)
				throw new ArgumentException($"unable to figure out route for: {uri}", nameof(uri));
			else if (possibleRouteMatches.Count > 1)
			{
				string[] matches = new string[possibleRouteMatches.Count];
				int i = 0;
				foreach (var match in possibleRouteMatches)
				{
					matches[i] = match.PathFull;
					i++;
				}

				string matchesFound = String.Join(",", matches);
				throw new ArgumentException($"Ambiguous routes matched for: {uri} matches found: {matchesFound}", nameof(uri));

			}

			var theWinningRoute = possibleRouteMatches[0];
			RequestDefinition definition =
				new RequestDefinition(
					ConvertToStandardFormat(shell, CreateUri(theWinningRoute.PathFull)),
					theWinningRoute.Item,
					theWinningRoute.Section,
					theWinningRoute.Content,
					theWinningRoute.GlobalRouteMatches);

			NavigationRequest navigationRequest = new NavigationRequest(definition, whatDoIDo, request.Query, request.Fragment);

			return navigationRequest;
		}
コード例 #4
0
        internal Task GoToPart(NavigationRequest request, Dictionary <string, string> queryData)
        {
            var shellSection = request.Request.Section;

            if (shellSection == null)
            {
                return(Task.FromResult(true));
            }

            Shell.ApplyQueryAttributes(shellSection, queryData, request.Request.Content == null);

            if (CurrentItem != shellSection)
            {
                SetValueFromRenderer(CurrentItemProperty, shellSection);
            }

            return(shellSection.GoToPart(request, queryData));
        }
コード例 #5
0
ファイル: ShellNavigationManager.cs プロジェクト: gywerd/CPUI
        public static ShellNavigationSource CalculateNavigationSource(Shell shell, ShellNavigationState current, NavigationRequest request)
        {
            if (request.StackRequest == NavigationRequest.WhatToDoWithTheStack.PushToIt)
            {
                return(ShellNavigationSource.Push);
            }

            if (current == null)
            {
                return(ShellNavigationSource.ShellItemChanged);
            }

            var targetUri  = ShellUriHandler.ConvertToStandardFormat(shell, request.Request.FullUri);
            var currentUri = ShellUriHandler.ConvertToStandardFormat(shell, current.FullLocation);

            var targetPaths  = ShellUriHandler.RetrievePaths(targetUri.PathAndQuery);
            var currentPaths = ShellUriHandler.RetrievePaths(currentUri.PathAndQuery);

            var targetPathsLength  = targetPaths.Length;
            var currentPathsLength = currentPaths.Length;

            if (targetPathsLength < 4 || currentPathsLength < 4)
            {
                return(ShellNavigationSource.Unknown);
            }

            if (targetPaths[1] != currentPaths[1])
            {
                return(ShellNavigationSource.ShellItemChanged);
            }
            if (targetPaths[2] != currentPaths[2])
            {
                return(ShellNavigationSource.ShellSectionChanged);
            }
            if (targetPaths[3] != currentPaths[3])
            {
                return(ShellNavigationSource.ShellContentChanged);
            }

            if (targetPathsLength == currentPathsLength)
            {
                return(ShellNavigationSource.Unknown);
            }

            if (targetPathsLength < currentPathsLength)
            {
                for (var i = 0; i < targetPathsLength; i++)
                {
                    var targetPath = targetPaths[i];
                    if (targetPath != currentPaths[i])
                    {
                        break;
                    }

                    if (i == targetPathsLength - 1)
                    {
                        if (targetPathsLength == 4)
                        {
                            return(ShellNavigationSource.PopToRoot);
                        }

                        return(ShellNavigationSource.Pop);
                    }
                }

                if (targetPaths[targetPathsLength - 1] == currentPaths[currentPathsLength - 1])
                {
                    return(ShellNavigationSource.Remove);
                }

                if (targetPathsLength == 4)
                {
                    return(ShellNavigationSource.PopToRoot);
                }

                return(ShellNavigationSource.Pop);
            }
            else if (targetPathsLength > currentPathsLength)
            {
                for (var i = 0; i < currentPathsLength; i++)
                {
                    if (targetPaths[i] != currentPaths[i])
                    {
                        break;
                    }

                    if (i == targetPathsLength - 1)
                    {
                        return(ShellNavigationSource.Push);
                    }
                }
            }

            if (targetPaths[targetPathsLength - 1] == currentPaths[currentPathsLength - 1])
            {
                return(ShellNavigationSource.Insert);
            }

            return(ShellNavigationSource.Push);
        }