Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Shell] refactor of processing uris #5852

Merged
merged 19 commits into from
Apr 11, 2019
Merged

[Shell] refactor of processing uris #5852

merged 19 commits into from
Apr 11, 2019

Conversation

PureWeen
Copy link
Contributor

@PureWeen PureWeen commented Apr 9, 2019

Description of Change

  • Changed it so Uri's are processed before navigation occurs into a NavigationRequest class. This lets me throw more intelligent exceptions when Uri is wrong plus I can get fancier with decomposing the Uri
  • Added lots of behavior to just try as hard as I can to match a uri request to something
  • added relative matching that walks up the route hiearchy

Issues Resolved

API Changes

Added:

These classes need to still be fleshed out a bit but they are the beginnings of extracting a uri into a request.

  • public class NavigationRequest
  • public class RequestDefinition

Changed:

  • IShellItemController.GoToParts to take NavigationRequest
  • IShellSectionController.GoToParts to take NavigationRequest

None

Platforms Affected

  • Core/XAML (all platforms)
  • iOS
  • Android
  • UWP

Behavioral/Visual Changes

Review #5790 to see how uri's are interpreted

Testing Procedure

  • Navigate your little heart out
  • added lots of UI Tests

PR Checklist

  • Has automated tests
  • Rebased on top of the target branch at time of PR
  • Changes adhere to coding standard

Xamarin.Forms.Core/Shell/Shell.cs Outdated Show resolved Hide resolved
Xamarin.Forms.Core/Shell/Shell.cs Show resolved Hide resolved
Xamarin.Forms.Core/Shell/Shell.cs Show resolved Hide resolved
Xamarin.Forms.Core/Shell/BaseShellItem.cs Show resolved Hide resolved
Copy link
Contributor

@paymicro paymicro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks cool!

Xamarin.Forms.Core/Routing.cs Show resolved Hide resolved
@@ -6,7 +6,7 @@ namespace Xamarin.Forms
{
public interface IShellItemController : IElementController
{
Task GoToPart(List<string> parts, Dictionary<string, string> queryData);
Task GoToPart(NavigationRequest navigationRequest, Dictionary<string, string> queryData);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be better to allocate this in a new interface

IShellElementController : IElementController
{ 
   Task GoToPart(NavigationRequest navigationRequest, Dictionary<string, string> queryData);
}

Xamarin.Forms.Core/Shell/ShellItem.cs Outdated Show resolved Hide resolved
Xamarin.Forms.Core/Shell/ShellUriHandler.cs Outdated Show resolved Hide resolved
Xamarin.Forms.Core/Shell/ShellUriHandler.cs Show resolved Hide resolved

string MakeUriString(List<string> segments)
{
if(segments[0].StartsWith("/") || segments[0].StartsWith("\\"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this check needs to be extracted into some helper.

Assert.AreEqual(new Uri("app://host/shellroute/path"), ShellUriHandler.ConvertToStandardFormat(shell, CreateUri("app:/shellroute/path")));

Assert.AreEqual(new Uri("app://host/shellroute/path"), ShellUriHandler.ConvertToStandardFormat(shell, CreateUri("app://host/shellroute/path")));
Assert.AreEqual(new Uri("app://host/shellroute/path"), ShellUriHandler.ConvertToStandardFormat(shell, CreateUri("app:/host/shellroute/path")));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can make variable new Uri("app://host/shellroute/path") ?
Also need add CreateUri with backslash separator CreateUri("\\\\path")) and CreateUri("\\path"))

Xamarin.Forms.Core/Routing.cs Outdated Show resolved Hide resolved
Xamarin.Forms.Core/Routing.cs Outdated Show resolved Hide resolved
Xamarin.Forms.Core/Routing.cs Show resolved Hide resolved
@PureWeen PureWeen marked this pull request as ready for review April 10, 2019 19:02
@samhouts samhouts requested review from samhouts and removed request for StephaneDelcroix April 10, 2019 20:45
@samhouts samhouts assigned samhouts and unassigned rmarinho Apr 10, 2019
@samhouts samhouts requested a review from paymicro April 10, 2019 20:45
@samhouts samhouts added the API-change Heads-up to reviewers that this PR may contain an API change label Apr 10, 2019
{
get
{
var segments = _path.Split(_pathSeparator, StringSplitOptions.RemoveEmptyEntries).ToList().Skip(1).ToList();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a lot of expensive enumeration that is not strictly necessary.

Suggested change
var segments = _path.Split(_pathSeparator, StringSplitOptions.RemoveEmptyEntries).ToList().Skip(1).ToList();
var segments = _path.Split(_pathSeparator, StringSplitOptions.RemoveEmptyEntries).Skip(1);

{
get
{
var segments = _path.Split(_pathSeparator, StringSplitOptions.RemoveEmptyEntries).ToList().Skip(1).ToList();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var segments = _path.Split(_pathSeparator, StringSplitOptions.RemoveEmptyEntries).ToList().Skip(1).ToList();
var segmentsCount = _path.Split(_pathSeparator, StringSplitOptions.RemoveEmptyEntries).Skip(1).Count();

{
var segments = _path.Split(_pathSeparator, StringSplitOptions.RemoveEmptyEntries).ToList().Skip(1).ToList();

if (segments.Count == 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (segments.Count == 0)
if (segmentsCount == 0)

return $"{source}/";
}

public static string FormatRoute(List<string> segments)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static string FormatRoute(List<string> segments)
public static string FormatRoute(IEnumerable<string> segments)

{
var segments = _path.Split(_pathSeparator, StringSplitOptions.RemoveEmptyEntries).ToList().Skip(1).ToList();

if (segments.Count == 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (segments.Count == 0)
if (segments.Count() == 0)

@PureWeen
Copy link
Contributor Author

@samhouts

If it's alright my plan is to sweep through and get rid of everything using Linq for the next Pre, store a few more things locally, etc..

I'd apply a few now but I don't want the UI tests to quit out so we can get this merged and tested

@samhouts samhouts merged commit 58662a1 into 4.0.0 Apr 11, 2019
@samhouts samhouts changed the title refactor of processing uris [Shell] refactor of processing uris Apr 11, 2019
@samhouts samhouts deleted the shell_uri branch April 11, 2019 04:55
@samhouts samhouts added this to the 4.0.0 milestone Apr 11, 2019
AxelUser pushed a commit to AxelUser/Xamarin.Forms that referenced this pull request Jun 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/shell 🐚 API-change Heads-up to reviewers that this PR may contain an API change t/enhancement ➕
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants