Skip to content

Commit

Permalink
NavigationView Handler for Android (#2336)
Browse files Browse the repository at this point in the history
* NavigationHandler Android

* - code cleanup

* - cleanup

* - cleanup code

* - fix naming

* - fix comments

* - move toolbar code to controls

* - code cleanup

* - organized code into NavigationManager

* - cleanup

* - cleanup

* - add to gallery

* - update naming

* - fix winui
  • Loading branch information
PureWeen authored Sep 1, 2021
1 parent 40c3dfe commit 25c7c2c
Show file tree
Hide file tree
Showing 53 changed files with 2,261 additions and 1,222 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific;

namespace Microsoft.Maui.Controls.Compatibility.Platform.Android
Expand Down
19 changes: 12 additions & 7 deletions src/Compatibility/Core/src/Windows/NavigationPageRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ public void SetElement(VisualElement element)
throw new InvalidOperationException(
"NavigationPage must have a root Page before being used. Either call PushAsync with a valid Page, or pass a Page to the constructor before usage.");

if (oldElement != null)
if (oldElement is INavigationPageController navigationPageController)
{
oldElement.PushRequested -= OnPushRequested;
oldElement.PopRequested -= OnPopRequested;
oldElement.PopToRootRequested -= OnPopToRootRequested;
navigationPageController.PushRequested -= OnPushRequested;
navigationPageController.PopRequested -= OnPopRequested;
navigationPageController.PopToRootRequested -= OnPopToRootRequested;
oldElement.InternalChildren.CollectionChanged -= OnChildrenChanged;
oldElement.PropertyChanged -= OnElementPropertyChanged;
}
Expand Down Expand Up @@ -218,9 +218,14 @@ public void SetElement(VisualElement element)
Element.Appearing += OnElementAppearing;

Element.PropertyChanged += OnElementPropertyChanged;
Element.PushRequested += OnPushRequested;
Element.PopRequested += OnPopRequested;
Element.PopToRootRequested += OnPopToRootRequested;

if (Element is INavigationPageController newPageController)
{
newPageController.PushRequested += OnPushRequested;
newPageController.PopRequested += OnPopRequested;
newPageController.PopToRootRequested += OnPopToRootRequested;
}

Element.InternalChildren.CollectionChanged += OnChildrenChanged;

if (!string.IsNullOrEmpty(Element.AutomationId))
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific;

namespace Microsoft.Maui.Controls.Compatibility.Platform.UWP
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<views:BasePage
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Pages.NavigationGallery"
xmlns:views="clr-namespace:Maui.Controls.Sample.Pages.Base">
<views:BasePage.Content>
<StackLayout
Margin="12">
<Label Text="Page Count" x:Name="lblPageCount"></Label>
<Button Text="Insert Page Before Current" Clicked="InsertPage" />
<Button Text="Pop Page" Clicked="PopPage" />
<Button Text="Push Page" Clicked="PushPage" />
<Button Text="Remove Page Before Current" Clicked="RemovePage" />
<Button Text="Pop To Root" Clicked="PopToRoot" />
<Button Text="Swap Root" Clicked="SwapRoot" />
<Button Text="Toggle Navigation Bar" Clicked="ToggleNavigationBar" />
<Button Text="Toggle Back Button" Clicked="ToggleBackButton" />
</StackLayout>
</views:BasePage.Content>
</views:BasePage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Maui;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Graphics;

namespace Maui.Controls.Sample.Pages
{
public partial class NavigationGallery
{
static int pageCount = 0;

static List<Page> _currentNavStack;
public NavigationGallery()
{
InitializeComponent();
pageCount++;
lblPageCount.Text = $"{pageCount}";
this.Title = $"PAGE NUMBER {pageCount}";
}

void InsertPage(object sender, EventArgs e)
{
Navigation.InsertPageBefore(new NavigationGallery(), Navigation.NavigationStack.Last());
}

async void PopPage(object sender, EventArgs e)
{
await Navigation.PopAsync(true);
}

async void PushPage(object sender, EventArgs e)
{
await Navigation.PushAsync(new NavigationGallery(), true);
}

async void PopToRoot(object sender, EventArgs e)
{
await Navigation.PopToRootAsync(true);
}

void RemovePage(object sender, EventArgs e)
{
if (Navigation.NavigationStack.Count >= 2)
Navigation.RemovePage(Navigation.NavigationStack[Navigation.NavigationStack.Count - 2]);
}

void ToggleNavigationBar(object sender, EventArgs e)
{
NavigationPage.SetHasNavigationBar(this, !NavigationPage.GetHasNavigationBar(this));
}

void ToggleBackButton(object sender, EventArgs e)
{
NavigationPage.SetHasBackButton(this, !NavigationPage.GetHasBackButton(this));
}


void SwapRoot(object sender, EventArgs e)
{
if (_currentNavStack == null)
{
_currentNavStack = Navigation.NavigationStack.ToList();
(Parent as INavigationView).RequestNavigation(
new NavigationRequest(
new List<NavigationGallery>
{
new NavigationGallery()
}, false));
}
else
{
(Parent as INavigationView).RequestNavigation(
new NavigationRequest(_currentNavStack, true));

_currentNavStack = null;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ protected override IEnumerable<SectionModel> CreateItems() => new[]
new SectionModel(typeof(ModalPage), "Modal",
"Allows you to push and pop Modal Pages."),

new SectionModel(typeof(NavigationGallery), "Navigation Page",
"Play with the different Navigation APIs."),

new SectionModel(typeof(SemanticsPage), "Semantics",
".NET MAUI allows accessibility values to be set on user interface elements by using Semantics values."),

Expand Down
4 changes: 0 additions & 4 deletions src/Controls/src/Core/Controls.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@
<AndroidResource Include="$(AndroidRoot)Resources\Layout\flyoutcontent.axml" />
<AndroidResource Include="$(AndroidRoot)Resources\Layout\shellrootlayout.axml" />
<AndroidResource Include="$(AndroidRoot)Resources\Layout\shellcontent.axml" />


<AndroidResource Include="$(AndroidRoot)Resources\anim\enterfromleft.xml" />
<AndroidResource Include="$(AndroidRoot)Resources\anim\enterfromright.xml" />
<AndroidResource Include="$(AndroidRoot)Resources\anim\exittoleft.xml" />
<AndroidResource Include="$(AndroidRoot)Resources\anim\exittoright.xml" />


<AndroidResource Include="$(AndroidRoot)Resources\values\strings.xml" />
</ItemGroup>
<ItemGroup>
Expand Down
123 changes: 0 additions & 123 deletions src/Controls/src/Core/HandlerImpl/NavigationPage.Impl.cs

This file was deleted.

Loading

0 comments on commit 25c7c2c

Please sign in to comment.