Skip to content

Commit

Permalink
iOS NavigationPageHandler (#852)
Browse files Browse the repository at this point in the history
* iOS Navigation

* - wire up iOS Navigation

* - remove VET

* - rework with HR

* - fix namespace

* - fix HR

* - fix hr

* - fix SO exception

* - maybe?

* - nullabel fix
  • Loading branch information
PureWeen authored Apr 27, 2021
1 parent 4f4fb9d commit 65a4499
Show file tree
Hide file tree
Showing 29 changed files with 1,472 additions and 38 deletions.
21 changes: 21 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
<Project>
<Import Project="eng\Versions.props" />

<PropertyGroup>

<BuildForWinUI Condition="'$(SolutionFileName)' == 'Microsoft.Maui.WinUI.sln'">true</BuildForWinUI>
<BuildForNet6 Condition="'$(SolutionFileName)' == 'Microsoft.Maui-net6.sln' or '$(BuildForWinUI)' == 'true'">true</BuildForNet6>
<MauiPlatforms>net6.0-ios;net6.0-maccatalyst;net6.0-android</MauiPlatforms>
<WindowsTargetFramework Condition="'$(WindowsTargetFramework)' == ''">net6.0-windows10.0.18362</WindowsTargetFramework>
<MauiPlatforms Condition="'$(Packing)' == 'true'">$(MauiPlatforms);$(WindowsTargetFramework)</MauiPlatforms>
<MauiPlatforms Condition="'$(BuildForWinUI)' == 'true'">$(WindowsTargetFramework)</MauiPlatforms>

<!-- This is used to easily build for a specific target to make the IDE work a bit better -->
<NonNet6Platforms>Xamarin.iOS10;MonoAndroid10.0</NonNet6Platforms>
<NonNet6EssentialsPlatforms>netstandard2.0;netstandard2.1;Xamarin.iOS10;MonoAndroid90;MonoAndroid10.0;tizen40;Xamarin.Mac20;</NonNet6EssentialsPlatforms>
<NonNet6EssentialsPlatforms Condition=" '$(OS)' == 'Windows_NT'">$(NonNet6EssentialsPlatforms);uap10.0.16299;</NonNet6EssentialsPlatforms>

<BuildNonNet6ForiOS>false</BuildNonNet6ForiOS>
<BuildNonNet6ForiOS Condition="'$(SolutionFileName)' == 'Microsoft.Maui.iOS.sln'">true</BuildNonNet6ForiOS>
<NonNet6Platforms Condition="'$(BuildNonNet6ForiOS)' == 'true'">Xamarin.iOS10</NonNet6Platforms>
<NonNet6EssentialsPlatforms Condition="'$(BuildNonNet6ForiOS)' == 'true'">netstandard2.0;netstandard2.1;Xamarin.iOS10</NonNet6EssentialsPlatforms>

<BuildNonNet6ForAndroid>false</BuildNonNet6ForAndroid>
<NonNet6Platforms Condition="'$(BuildNonNet6ForAndroid)' == 'true'">MonoAndroid10.0</NonNet6Platforms>
<NonNet6EssentialsPlatforms Condition="'$(BuildNonNet6ForAndroid)' == 'true'">netstandard2.0;netstandard2.1;MonoAndroid10.0</NonNet6EssentialsPlatforms>

</PropertyGroup>

<PropertyGroup>

<_MauiBuildTasksLocation>$(_MauiBuildTasksLocation)</_MauiBuildTasksLocation>
<_MauiBuildTasksLocation Condition="'$(_MauiBuildTasksLocation)' == ''">$(MSBuildThisFileDirectory).nuspec\</_MauiBuildTasksLocation>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand Down
979 changes: 979 additions & 0 deletions Microsoft.Maui.iOS.sln

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors" />
</ItemGroup>
<ItemGroup>
<InterfaceDefinition Include="LaunchScreen.storyboard" />
</ItemGroup>
<ItemGroup>
<None Include="Info.plist" />
<None Include="Entitlements.plist" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="MSBuild.Sdk.Extras">

<PropertyGroup>
<TargetFrameworks>MonoAndroid10.0;Xamarin.iOS10</TargetFrameworks>
<TargetFrameworks>$(NonNet6Platforms)</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/Controls/samples/Controls.Sample/Pages/MainPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class MainPage : BasePage

public MainPage(IServiceProvider services, MainPageViewModel viewModel)
{
BackgroundColor = Colors.White;
ToolbarItems.Add(new ToolbarItem()
{
Text = "Page"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<controls:BasePage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="clr-namespace:Maui.Controls.Sample.Controls"
x:Class="Maui.Controls.Sample.Pages.SemanticsPage">
x:Class="Maui.Controls.Sample.Pages.SemanticsPage"
BackgroundColor="White">

<ScrollView Margin="15,20">
<VerticalStackLayout>
Expand Down
39 changes: 39 additions & 0 deletions src/Controls/src/Core/ArrayExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using Microsoft.Maui.Controls.Internals;

namespace Microsoft.Maui.Controls.Platform
{
internal static class ArrayExtensions
{
public static T[] Insert<T>(this T[] self, int index, T item)
{
var result = new T[self.Length + 1];
if (index > 0)
Array.Copy(self, result, index);

result[index] = item;

if (index < self.Length)
Array.Copy(self, index, result, index + 1, result.Length - index - 1);

return result;
}

public static T[] Remove<T>(this T[] self, T item)
{
return self.RemoveAt(self.IndexOf(item));
}

public static T[] RemoveAt<T>(this T[] self, int index)
{
var result = new T[self.Length - 1];
if (index > 0)
Array.Copy(self, result, index);

if (index < self.Length - 1)
Array.Copy(self, index + 1, result, index, self.Length - index - 1);

return result;
}
}
}
2 changes: 1 addition & 1 deletion src/Controls/src/Core/Controls.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="MSBuild.Sdk.Extras">
<PropertyGroup>
<TargetFrameworks>netstandard2.1;netstandard2.0;$(AndroidTargetFrameworks)</TargetFrameworks>
<TargetFrameworks>netstandard2.1;netstandard2.0;$(NonNet6Platforms)</TargetFrameworks>
<AssemblyName>Microsoft.Maui.Controls</AssemblyName>
</PropertyGroup>
<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static PropertyMapper<NavigationPage, NavigationPageHandler> NavigationPa
[nameof(ToolbarPlacementProperty.PropertyName)] = MapToolbarPlacement,
[nameof(ToolbarDynamicOverflowEnabledProperty.PropertyName)] = MapToolbarDynamicOverflowEnabled,
#endif
};
};

public NavigationPageHandler() : base(NavigationPageMapper)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
using System;
#nullable enable

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.Handlers;
using UIKit;

namespace Microsoft.Maui.Controls.Handlers
{
public partial class NavigationPageHandler :
ViewHandler<NavigationPage, UIView>
ViewHandler<NavigationPage, UIView>, INativeViewHandler
{
ControlsNavigationController _controlsNavigationController;
UIViewController? INativeViewHandler.ViewController => _controlsNavigationController;

protected override UIView CreateNativeView()
{
throw new NotImplementedException();
_controlsNavigationController = new ControlsNavigationController(this);

if (_controlsNavigationController.View == null)
throw new NullReferenceException("ControlsNavigationController.View is null");

return _controlsNavigationController.View;
}

public static void MapPadding(NavigationPageHandler handler, NavigationPage view) { }
Expand All @@ -23,5 +37,58 @@ public static void MapNavigationBarBackground(NavigationPageHandler handler, Nav
public static void MapTitleIcon(NavigationPageHandler handler, NavigationPage view) { }

public static void MapTitleView(NavigationPageHandler handler, NavigationPage view) { }


protected override void ConnectHandler(UIView nativeView)
{
base.ConnectHandler(nativeView);

if (VirtualView == null)
return;

VirtualView.PushRequested += OnPushRequested;
VirtualView.PopRequested += OnPopRequested;
_controlsNavigationController.LoadPages(this.MauiContext);

//VirtualView.PopToRootRequested += OnPopToRootRequested;
//VirtualView.RemovePageRequested += OnRemovedPageRequested;
//VirtualView.InsertPageBeforeRequested += OnInsertPageBeforeRequested;
}

protected override void DisconnectHandler(UIView nativeView)
{
base.DisconnectHandler(nativeView);

if (VirtualView == null)
return;

VirtualView.PushRequested -= OnPushRequested;
VirtualView.PopRequested -= OnPopRequested;
//VirtualView.PopToRootRequested -= OnPopToRootRequested;
//VirtualView.RemovePageRequested -= OnRemovedPageRequested;
//VirtualView.InsertPageBeforeRequested -= OnInsertPageBeforeRequested;
}

void OnPopRequested(object? sender, NavigationRequestedEventArgs e)
{
_controlsNavigationController?
.OnPopRequestedAsync(e)
.FireAndForget((exc) => Log.Warning(nameof(NavigationPage), $"{exc}"));
}

void OnPushRequested(object? sender, NavigationRequestedEventArgs e)
{
_controlsNavigationController?
.OnPushRequested(e, this.MauiContext);
}

internal void SendPopping(Task popTask)
{
if (VirtualView == null)
return;

(VirtualView as INavigationPageController)?.PopAsyncInner(false, true)
.FireAndForget((exc) => Log.Warning(nameof(NavigationPage), $"{exc}"));
}
}
}
5 changes: 2 additions & 3 deletions src/Controls/src/Core/NavigationPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public async Task<Page> PopAsync(bool animated)
else
CurrentNavigationTask = tcs.Task;

var result = await PopAsyncInner(animated, false);
var result = await (this as INavigationPageController).PopAsyncInner(animated, false);
tcs.SetResult(true);
return result;
}
Expand Down Expand Up @@ -291,8 +291,7 @@ protected override bool OnBackButtonPressed()
[EditorBrowsable(EditorBrowsableState.Never)]
public event EventHandler<NavigationRequestedEventArgs> InsertPageBeforeRequested;

[EditorBrowsable(EditorBrowsableState.Never)]
public async Task<Page> PopAsyncInner(bool animated, bool fast)
async Task<Page> INavigationPageController.PopAsyncInner(bool animated, bool fast)
{
if (StackDepth == 1)
{
Expand Down
Loading

0 comments on commit 65a4499

Please sign in to comment.