Skip to content

Commit

Permalink
docs: Updating navigation docs to match latest template
Browse files Browse the repository at this point in the history
  • Loading branch information
eriklimakc committed Jun 24, 2024
1 parent 44e1018 commit ed0d0c4
Show file tree
Hide file tree
Showing 11 changed files with 198 additions and 148 deletions.
2 changes: 1 addition & 1 deletion doc/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This tutorial will walk you through how to create an Uno application with Uno.Ex

![Visual Studio - Configure project name and location](./Learn/images/configure-new-unoplatform-app.png)

* Choose a template preset to build your application
* Choose the **Recommended** preset to build your application

![Visual Studio - Configure your new project](./Learn/images/intro.png)

Expand Down
2 changes: 1 addition & 1 deletion doc/Learn/Authentication/HowTo-Authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ uid: Uno.Extensions.Authentication.HowToAuthentication
}
```

- Update the "Second" route in `App.xaml.host.cs` to specify that it depends on the "Main" route. This will make sure that even if the app navigates directly to the SecondPage, the MainPage will be added to the backstack.
- Update the "Second" route in `App.xaml.cs` to specify that it depends on the "Main" route. This will make sure that even if the app navigates directly to the SecondPage, the MainPage will be added to the back stack.

```csharp
routes
Expand Down
16 changes: 12 additions & 4 deletions doc/Learn/Navigation/Advanced/HowTo-AdvancedPageNavigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ When using navigation, you may not want to allow the current page to remain in t

Using backward/forward navigation in your app requires a degree of extra consideration. Users always expect the back/forward button to take them to a page that is still relevant, yet logically related to the current page and direction. This page contains several concise tutorials about how to implement navigation techniques that address these more advanced problems.

> [!NOTE]
> This guide uses predefined code created by the Uno Template using the `Recommended` preset, however, it uses the `MVVM` approach for the examples instead of `MVUX` defined in the `Recommended` preset.
## Step-by-steps

> [!IMPORTANT]
> This guide assumes you used the template wizard or `dotnet new unoapp` to create your solution. If not, it is recommended that you follow the [Creating an application with Uno.Extensions article](xref:Uno.Extensions.HowToGettingStarted) for creating an application from the template.
## Techniques

### Navigating to a Page and Clearing Back Stack
Expand Down Expand Up @@ -58,7 +66,7 @@ It is possible to navigate to a page and clear the back stack from code behind u
```csharp
public async Task GoToSecondPage()
{
await _navigator.NavigateViewModelAsync<SecondViewModel>(this, qualifier: Qualifiers.ClearBackStack);
await _navigator.NavigateViewModelAsync<SecondViewModel>(this, qualifier: Qualifiers.ClearBackStack);
}
```

Expand All @@ -70,7 +78,7 @@ Another common scenario is to navigate to a page and then remove the current pag

#### From XAML

- Add a new `Page` to navigate to, `SamplePage.xaml`, in the UI (shared) project
- Add a new `Page` to navigate to, `SamplePage.xaml`

- In `SecondPage.xaml` add a `Button` with the following XAML, which does _not_ include a handler for the Click event

Expand All @@ -91,8 +99,8 @@ Another common scenario is to navigate to a page and then remove the current pag

#### From code behind

- Add a new `Page` to navigate to, `SamplePage.xaml`, in the UI (shared) project
- In `SecondPage.xaml` add a `Button` with the following XAML, which includes a handler for the Click event
- Add a new `Page` to navigate to, `SamplePage.xaml`
- In `SecondPage.xaml` add a `Button` with the following XAML, which includes a handler for the Click event

```xml
<Button HorizontalAlignment="Center"
Expand Down
22 changes: 14 additions & 8 deletions doc/Learn/Navigation/Advanced/HowTo-UseNavigationView.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ uid: Uno.Extensions.Navigation.Advanced.NavigationView

Choosing the right control for your navigation needs is important, and one common choice is `NavigationView`. This control adapts to different screen sizes and offers a uniform top-level navigation experience. `NavigationView` is a great option for adaptive, customizable, and mobile-friendly navigation. The Uno Platform extensions for navigation provide built-in support for using `NavigationView` and `NavigationViewItem` to switch between views. This tutorial will show you how to configure a `NavigationView` for use with the navigation extensions.

> [!NOTE]
> This guide uses predefined code created by the Uno Template using the `Recommended` preset, however, it uses the `MVVM` approach for the examples instead of `MVUX` defined in the `Recommended` preset.
## Step-by-steps

> [!IMPORTANT]
Expand Down Expand Up @@ -212,21 +215,24 @@ Choosing the right control for your navigation needs is important, and one commo
private static void RegisterRoutes(IViewRegistry views, IRouteRegistry routes)
{
views.Register(
new ViewMap<ShellControl, ShellViewModel>(),
new ViewMap(ViewModel: typeof(ShellViewModel)),
new ViewMap<ProductsPage, ProductsViewModel>(),
new ViewMap<MainPage, MainViewModel>()
);

routes.Register(
new RouteMap("", View: views.FindByViewModel<ShellViewModel>(),
Nested: new RouteMap[]
{
Nested:
[
new RouteMap("Main", View: views.FindByViewModel<MainViewModel>(),
Nested: new RouteMap[]
{
new RouteMap("Products", View: views.FindByViewModel<ProductsViewModel>())
})
}));
Nested:
[
new RouteMap("Products", View: views.FindByViewModel<ProductsViewModel>())
]
)
]
)
);
}
```

Expand Down
23 changes: 16 additions & 7 deletions doc/Learn/Navigation/Advanced/HowTo-UseTabBar.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ var builder = this.CreateBuilder(args)
.Configure(host => host....);
```

> [!NOTE]
> This guide uses predefined code created by the Uno Template using the `Recommended` preset, however, it uses the `MVVM` approach for the examples instead of `MVUX` defined in the `Recommended` preset.
## Step-by-steps

> [!IMPORTANT]
> This guide assumes you used the template wizard or `dotnet new unoapp` to create your solution. If not, it is recommended that you follow the [Creating an application with Uno.Extensions article](xref:Uno.Extensions.HowToGettingStarted) for creating an application from the template.
### 1. Add necessary XAML namespaces

* Update the `Page` element in `MainPage.xaml` to include XAML namespace mappings for Navigation and Uno Toolkit:
Expand Down Expand Up @@ -281,21 +287,24 @@ var builder = this.CreateBuilder(args)
private static void RegisterRoutes(IViewRegistry views, IRouteRegistry routes)
{
views.Register(
new ViewMap<ShellControl, ShellViewModel>(),
new ViewMap(ViewModel: typeof(ShellViewModel)),
new ViewMap<LoginPage, LoginViewModel>(),
new ViewMap<MainPage, MainViewModel>()
);
routes.Register(
new RouteMap("", View: views.FindByViewModel<ShellViewModel>(),
Nested: new RouteMap[]
{
Nested:
[
new RouteMap("Main", View: views.FindByViewModel<MainViewModel>(),
Nested: new RouteMap[]
{
Nested:
[
new RouteMap("Login", View: views.FindByViewModel<LoginViewModel>())
})
}));
]
)
]
)
);
}
```
Expand Down
60 changes: 32 additions & 28 deletions doc/Learn/Navigation/HowTo-DisplayItem.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ uid: Uno.Extensions.Navigation.HowToDisplayItem

This topic walks through how to use Navigation to display the details of an item selected from a list. This demonstrates an important aspect of Navigation which is the ability to pass data as part of a navigation request.

> [!NOTE]
> This guide uses predefined code created by the Uno Template using the `Recommended` preset, however, it uses the `MVVM` approach for the examples instead of `MVUX` defined in the `Recommended` preset.
## Step-by-steps

> [!IMPORTANT]
Expand All @@ -20,10 +23,10 @@ Often it is necessary to pass a data item from one page to another. This scenari
public record Widget(string Name, double Weight);
```

- Change the `ViewMap` in `App.xaml.host.cs` that associates the `SecondPage` and `SecondViewModel`, to include a `DataMap` that references the `Widget` type.
- Change the `ViewMap` in `App.xaml.cs` that associates the `SecondPage` and `SecondViewModel`, to be a `DataViewMap` object that allows you to specify the `Widget` type.

```csharp
new ViewMap<SecondPage, SecondViewModel>(Data: new DataMap<Widget>())
new DataViewMap<SecondPage, SecondViewModel, Widget>()
```

### 2. Pass data when navigating
Expand All @@ -33,9 +36,9 @@ Often it is necessary to pass a data item from one page to another. This scenari
```csharp
public async Task GoToSecondPage()
{
var widget = new Widget("CrazySpinner", 34.0);
var widget = new Widget("CrazySpinner", 34.0);

await _navigator.NavigateViewModelAsync<SecondViewModel>(this, data: widget);
await _navigator.NavigateViewModelAsync<SecondViewModel>(this, data: widget);
}
```

Expand Down Expand Up @@ -67,7 +70,7 @@ Often it is necessary to pass a data item from one page to another. This scenari

### 4. Navigating with data

- Because there's a mapping between the `Widget` and the `SecondViewModel` (in the `ViewMap` defined in `App.xaml.host.cs`), an alternative way to navigate is by calling the `NavigateDataAsync` and specifying the data object to pass in the navigation request. The type of the data object will be used to revolve which route to navigate to
- Because there's a mapping between the `Widget` and the `SecondViewModel` (in the `ViewMap` defined in `App.xaml.cs`), an alternative way to navigate is by calling the `NavigateDataAsync` and specifying the data object to pass in the navigation request. The type of the data object will be used to resolve which route to navigate to.

```csharp
await _navigator.NavigateDataAsync(this, data: widget);
Expand All @@ -80,11 +83,11 @@ A common application scenario is to present a list of items, for example present
- Add a `Widgets` property to your `MainViewModel`

```csharp
public Widget[] Widgets { get; } = new[]
{
public Widget[] Widgets { get; } =
[
new Widget("NormalSpinner", 5.0),
new Widget("HeavySpinner",50.0)
};
new Widget("HeavySpinner", 50.0)
];
```

- Update `MainPage.xaml` to replace the `Button` with a `ListView` which has the `ItemsSource` property data bound to the `Widgets` property. The `Navigation.Request` property defines the route that will be navigated to when an item in the `ListView` is selected.
Expand Down Expand Up @@ -126,11 +129,11 @@ If you have a `ListView` that has items of different types, the navigation route
- Change the `Widgets` property in `MainViewModel` to include an array of different types of widgets.

```csharp
public Widget[] Widgets { get; } = new Widget[]
{
public Widget[] Widgets { get; } =
[
new BasicWidget("NormalSpinner", 5.0),
new AdvancedWidget("HeavySpinner",50.0)
};
new AdvancedWidget("HeavySpinner", 50.0)
];
```

- Clone the `SecondPage.xaml` and `SecondPage.xaml.cs` files, and rename the files to `ThirdPage.xaml` and `ThirdPage.xaml.cs` respectively. Make sure you also change the class name in both files from `SecondPage` to `ThirdPage`, as well as the `Content` property of the `NavigationBar` to read "Third Page".
Expand Down Expand Up @@ -159,27 +162,28 @@ If you have a `ListView` that has items of different types, the navigation route
}
```

- Add a `ViewMap` and `RouteMap` for `ThirdPage` and `ThirdViewModel`, specifying the `AdvancedWidget` in the `DataMap`. Also update DataMap for `SecondViewModel` to be `BasicWidget` instead of `Widget`
- Add a `DataViewMap` and `RouteMap` for `ThirdPage` and `ThirdViewModel`, specifying the `AdvancedWidget`. Also, update `DataViewMap` for `SecondViewModel` to be `BasicWidget` instead of `Widget`

```csharp
private static void RegisterRoutes(IViewRegistry views, IRouteRegistry routes)
{
views.Register(
new ViewMap<ShellControl, ShellViewModel>(),
new ViewMap(ViewModel: typeof(ShellViewModel)),
new ViewMap<MainPage, MainViewModel>(),
new ViewMap<SecondPage, SecondViewModel>(Data: new DataMap<BasicWidget>()),
new ViewMap<ThirdPage, ThirdViewModel>(Data: new DataMap<AdvancedWidget>())
);

routes
.Register(
new RouteMap("", View: views.FindByViewModel<ShellViewModel>(),
Nested: new RouteMap[]
{
new RouteMap("Main", View: views.FindByViewModel<MainViewModel>()),
new RouteMap("Second", View: views.FindByViewModel<SecondViewModel>()),
new RouteMap("Third", View: views.FindByViewModel<ThirdViewModel>()),
}));
new DataViewMap<SecondPage, SecondViewModel, BasicWidget>(),
new DataViewMap<ThirdPage, ThirdViewModel, AdvancedWidget>()
);

routes.Register(
new RouteMap("", View: views.FindByViewModel<ShellViewModel>(),
Nested:
[
new ("Main", View: views.FindByViewModel<MainViewModel>()),
new ("Second", View: views.FindByViewModel<SecondViewModel>()),
new ("Third", View: views.FindByViewModel<ThirdViewModel>()),
]
)
);
}
```

Expand Down
Loading

0 comments on commit ed0d0c4

Please sign in to comment.