Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
TimLariviere committed Sep 1, 2022
1 parent 2a365ff commit 6184339
Show file tree
Hide file tree
Showing 14 changed files with 241 additions and 76 deletions.
7 changes: 5 additions & 2 deletions samples/Maui/Playground/App.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ module App =
let view model =
Application() {
Window(
Grid(coldefs = [ GridLength.Star ], rowdefs = [ GridLength.Star; GridLength.Star ]) {
Grid(coldefs = [ GridLength.Star ], rowdefs = [ GridLength.Auto; GridLength.Auto; GridLength.Star ]) {
Label("Playground")

TextButton("Start navigation", GoToB)
.gridRow(1)

(NavigationView() {
VStack() {
Label("A")
Expand All @@ -44,7 +47,7 @@ module App =
}
})
.background(SolidPaint(Colors.Red))
.gridRow(1)
.gridRow(2)
}
)
}
Expand Down
4 changes: 0 additions & 4 deletions src/Fabulous.Maui/Attributes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,6 @@ module Attributes =
let struct (_, view) = Helpers.createViewForWidget node widget
targetColl.Add(view)

let handler = node.Target :?> IStackNavigation
let stack = targetColl |> Seq.map unbox<IView> |> List<_>
handler.RequestNavigation(NavigationRequest(stack.AsReadOnly(), true))

let key =
AttributeDefinitionStore.registerWidgetCollection
{ ApplyDiff = applyDiff
Expand Down
8 changes: 2 additions & 6 deletions src/Fabulous.Maui/Views/Controls/NavigationView.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@ type FabNavigationView(handler: IViewHandler) =
static let _widgetKey = Widgets.register<FabNavigationView>()
static member WidgetKey = _widgetKey

new() = FabNavigationView(NavigationViewHandler())

interface IStackNavigation with
member this.NavigationFinished(newStack) = ()
member this.RequestNavigation(eventArgs) = this.Handler.Invoke("RequestNavigation", eventArgs)
new() = FabNavigationView(NavigationViewExHandler())

interface IStackNavigationView
interface INavigationViewEx

[<AutoOpen>]
module NavigationViewBuilders =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Microsoft.Maui;

public interface INavigationViewEx : IView
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#if __IOS__ || MACCATALYST
using PlatformView = UIKit.UIView;
#elif ANDROID
using PlatformView = Android.Views.View;
#elif WINDOWS
using PlatformView = Microsoft.UI.Xaml.Controls.Frame;
#elif TIZEN
using PlatformView = Microsoft.Maui.Platform.StackNavigationManager;
#elif (NETSTANDARD || !PLATFORM) || (NET6_0_OR_GREATER && !IOS && !ANDROID && !TIZEN)
using PlatformView = System.Object;
#endif

namespace Microsoft.Maui.Handlers;

public interface INavigationViewExHandler : IViewHandler
{
new INavigationViewEx VirtualView { get; }
new PlatformView PlatformView { get; }

void Push(IView view, bool animated);
void Pop(bool animated);
void InsertAt(int index, IView view);
void RemoveAt(int index);
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using Android.Runtime;
using Android.Views;
using AndroidX.Fragment.App;

namespace Microsoft.Maui.Handlers;

public partial class NavigationViewExHandler : ViewHandler<INavigationViewEx, View>
{
protected override View CreatePlatformView()
{
throw new NotImplementedException();
}

public void Push(IView view, bool animated)
{
throw new NotImplementedException();
}

public void Pop(bool animated)
{
throw new NotImplementedException();
}

public void InsertAt(int index, IView view)
{
throw new NotImplementedException();
}

public void RemoveAt(int index)
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace Microsoft.Maui.Handlers;

public partial class NavigationViewExHandler : ViewHandler<INavigationViewEx, object>
{
protected override object CreatePlatformView() => throw new NotImplementedException();

public void Push(IView view, bool animated)
{
throw new NotImplementedException();
}

public void Pop(bool animated)
{
throw new NotImplementedException();
}

public void InsertAt(int index, IView view)
{
throw new NotImplementedException();
}

public void RemoveAt(int index)
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#if __IOS__ || MACCATALYST
using PlatformView = UIKit.UIView;
#elif ANDROID
using PlatformView = Android.Views.View;
#elif WINDOWS
using PlatformView = Microsoft.UI.Xaml.Controls.Frame;
#elif TIZEN
using PlatformView = Microsoft.Maui.Platform.StackNavigationManager;
#elif (NETSTANDARD || !PLATFORM) || (NET6_0_OR_GREATER && !IOS && !ANDROID && !TIZEN)
using PlatformView = System.Object;
#endif

namespace Microsoft.Maui.Handlers;

public record NavigationHandlerPushUpdate(IView View, bool Animated);
public record NavigationHandlerPopUpdate(bool Animated);
public record NavigationHandlerInsertUpdate(int Index, IView View);
public record NavigationHandlerRemoveUpdate(int Index);

public partial class NavigationViewExHandler: INavigationViewExHandler
{
public static IPropertyMapper<INavigationViewEx, INavigationViewExHandler> Mapper = new PropertyMapper<INavigationViewEx, INavigationViewExHandler>(ViewHandler.ViewMapper)
{
};

public static CommandMapper<INavigationViewEx, INavigationViewExHandler> CommandMapper = new(ViewHandler.ViewCommandMapper)
{
[nameof(INavigationViewExHandler.Push)] = MapPush,
[nameof(INavigationViewExHandler.Pop)] = MapPop,
[nameof(INavigationViewExHandler.InsertAt)] = MapInsertAt,
[nameof(INavigationViewExHandler.RemoveAt)] = MapRemoveAt
};

public NavigationViewExHandler() : base(Mapper, CommandMapper)
{
}

public NavigationViewExHandler(IPropertyMapper? mapper = null) : base(mapper ?? Mapper, CommandMapper)
{
}

public NavigationViewExHandler(IPropertyMapper? mapper = null, CommandMapper? commandMapper = null) : base(mapper ?? Mapper, commandMapper ?? CommandMapper)
{
}

INavigationViewEx INavigationViewExHandler.VirtualView => VirtualView;

PlatformView INavigationViewExHandler.PlatformView => PlatformView;

private static void MapPush(INavigationViewExHandler handler, INavigationViewEx view, object? arg)
{
if (arg is NavigationHandlerPushUpdate args)
{
handler.Push(args.View, args.Animated);
}
}

private static void MapPop(INavigationViewExHandler handler, INavigationViewEx view, object? arg)
{
if (arg is NavigationHandlerPopUpdate args)
{
handler.Pop(args.Animated);
}
}

private static void MapInsertAt(INavigationViewExHandler handler, INavigationViewEx view, object? arg)
{
if (arg is NavigationHandlerInsertUpdate args)
{
handler.InsertAt(args.Index, args.View);
}
}

private static void MapRemoveAt(INavigationViewExHandler handler, INavigationViewEx view, object? arg)
{
if (arg is NavigationHandlerRemoveUpdate args)
{
handler.RemoveAt(args.Index);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using Microsoft.Maui.Platform;

namespace Microsoft.Maui.Handlers;

public partial class NavigationViewExHandler : ViewHandler<INavigationViewEx, UIView>
{
private UINavigationController? _navigationController;

protected override UIView CreatePlatformView()
{
_navigationController = new UINavigationController();
return _navigationController?.View;
}

public void Push(IView view, bool animated)
{
_navigationController?.PushViewController(view.ToThemeEnabledUIViewController(this.MauiContext), animated);
}

public void Pop(bool animated)
{
_navigationController?.PopViewController(animated);
}

public void InsertAt(int index, IView view)
{
var temp = new List<UIViewController>();

for(var i = index; i < _navigationController?.ViewControllers.Length; i++)
{
var popped = _navigationController?.PopViewController(false);
temp.Add(popped);
}

_navigationController?.PushViewController(view.ToThemeEnabledUIViewController(this.MauiContext), false);

foreach(var item in temp)
{
_navigationController?.PushViewController(item, false);
}
}

public void RemoveAt(int index)
{
var temp = new List<UIViewController>();

for(var i = index + 1; i < _navigationController?.ViewControllers.Length; i++)
{
var popped = _navigationController?.PopViewController(false);
temp.Add(popped);
}

_navigationController?.PopViewController(false);

foreach(var item in temp)
{
_navigationController?.PushViewController(item, false);
}
}
}

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions src/Microsoft.Maui.FabCompat/Window/WindowHandlerEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ namespace Microsoft.Maui.Handlers;

public partial class WindowHandlerEx: WindowHandler
{
public static IPropertyMapper<IWindow, IWindowHandler> Mapper = new PropertyMapper<IWindow, IWindowHandler>(WindowHandler.Mapper)
public new static IPropertyMapper<IWindow, IWindowHandler> Mapper = new PropertyMapper<IWindow, IWindowHandler>(WindowHandler.Mapper)
{
[nameof(IWindow.Content)] = MapContent
};

public static CommandMapper<IWindow, IWindowHandler> CommandMapper = new(WindowHandler.CommandMapper);
public new static CommandMapper<IWindow, IWindowHandler> CommandMapper = new(WindowHandler.CommandMapper);

public WindowHandlerEx()
: base(Mapper, CommandMapper)
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Maui.FabCompat/Window/WindowHandlerEx.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public partial class WindowHandlerEx
{
/// Do exactly the same than Microsoft.Maui.WindowHandler.MapContent
/// but use a ThemeEnabledContainerViewController instead of ContainerViewController
public static void MapContent(IWindowHandler handler, IWindow window)
public new static void MapContent(IWindowHandler handler, IWindow window)
{
_ = handler.MauiContext ??
throw new InvalidOperationException($"{nameof(MauiContext)} should have been set by base class.");
Expand Down

0 comments on commit 6184339

Please sign in to comment.