Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge IFrameworkElement and IView and Remove IPage #1875

Merged
merged 18 commits into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ protected override void OnLayout(bool changed, int l, int t, int r, int b)
var destination = Rectangle.FromLTRB(deviceIndependentLeft, deviceIndependentTop,
deviceIndependentRight, deviceIndependentBottom);

(Element as IFrameworkElement)?.Arrange(destination);
(Element as IView)?.Arrange(destination);
base.OnLayout(changed, l, t, r, b);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static IMauiHandlersCollection AddCompatibilityRenderer(this IMauiHandler
}

public static IMauiHandlersCollection AddCompatibilityRenderer<TControlType, TMauiType, TRenderer>(this IMauiHandlersCollection handlersCollection)
where TMauiType : IFrameworkElement
where TMauiType : IView
{
Internals.Registrar.Registered.Register(typeof(TControlType), typeof(TRenderer));

Expand All @@ -40,7 +40,7 @@ public static IMauiHandlersCollection AddCompatibilityRenderer<TControlType, TMa
}

public static IMauiHandlersCollection AddCompatibilityRenderer<TControlType, TRenderer>(this IMauiHandlersCollection handlersCollection)
where TControlType : IFrameworkElement
where TControlType : IView
{
handlersCollection.AddCompatibilityRenderer<TControlType, TControlType, TRenderer>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Maui.Controls.Sample.SingleProject
{
public class BlazorPage : ContentPage, IPage
public class BlazorPage : ContentPage
{
public BlazorPage()
{
Expand All @@ -27,7 +27,5 @@ public BlazorPage()
bwv.RootComponents.Add(new RootComponent { Selector = "#app", ComponentType = typeof(Main) });
Content = bwv;
}

public IView View { get => (IView)Content; set => Content = (View)value; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Maui.Controls.Sample.SingleProject
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MainPage : ContentPage, IPage
public partial class MainPage : ContentPage
{
public MainPage()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class BordelessEntryServiceBuilder : IMauiServiceBuilder
static readonly Dictionary<Type, Type> PendingHandlers = new();

public static void TryAddHandler<TType, TTypeRender>()
where TType : IFrameworkElement
where TType : IView
where TTypeRender : IViewHandler
{
if (HandlersCollection == null)
Expand Down
3 changes: 1 addition & 2 deletions src/Controls/samples/Controls.Sample/Pages/Base/BasePage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
using System.Diagnostics;
using System.Windows.Input;
using Maui.Controls.Sample.Models;
using Microsoft.Maui;
using Microsoft.Maui.Controls;

namespace Maui.Controls.Sample.Pages.Base
{
public class BasePage : ContentPage, IPage
public class BasePage : ContentPage
{
SectionModel _selectedItem;

Expand Down
19 changes: 8 additions & 11 deletions src/Controls/src/Core/HandlerImpl/ContentPage.Impl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@

namespace Microsoft.Maui.Controls
{
public partial class ContentPage : IPage, HotReload.IHotReloadableView
public partial class ContentPage : IContentView, HotReload.IHotReloadableView
{
// TODO ezhart That there's a layout alignment here tells us this hierarchy needs work :)
public Primitives.LayoutAlignment HorizontalLayoutAlignment => Primitives.LayoutAlignment.Fill;

IView IPage.Content => Content;
IView IContentView.Content => Content;

protected override Size MeasureOverride(double widthConstraint, double heightConstraint)
{
if (Content is IFrameworkElement frameworkElement)
if (Content is IView view)
{
_ = frameworkElement.Measure(widthConstraint, heightConstraint);
_ = view.Measure(widthConstraint, heightConstraint);
}

return new Size(widthConstraint, heightConstraint);
Expand All @@ -25,9 +22,9 @@ protected override Size ArrangeOverride(Rectangle bounds)
{
Frame = this.ComputeFrame(bounds);

if (Content is IFrameworkElement frameworkElement)
if (Content is IView view)
{
_ = frameworkElement.Arrange(Frame);
_ = view.Arrange(Frame);
}

return Frame.Size;
Expand All @@ -36,9 +33,9 @@ protected override Size ArrangeOverride(Rectangle bounds)
protected override void InvalidateMeasureOverride()
{
base.InvalidateMeasureOverride();
if (Content is IFrameworkElement frameworkElement)
if (Content is IView view)
{
frameworkElement.InvalidateMeasure();
view.InvalidateMeasure();
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/Controls/src/Core/HandlerImpl/NavigationPage.Impl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ partial void Init()

protected override Size MeasureOverride(double widthConstraint, double heightConstraint)
{
if (Content is IFrameworkElement frameworkElement)
if (Content is IView view)
{
frameworkElement.Measure(widthConstraint, heightConstraint);
view.Measure(widthConstraint, heightConstraint);
}

return new Size(widthConstraint, heightConstraint);
Expand All @@ -42,9 +42,9 @@ protected override Size ArrangeOverride(Rectangle bounds)
{
Frame = this.ComputeFrame(bounds);

if (Content is IFrameworkElement frameworkElement)
if (Content is IView view)
{
_ = frameworkElement.Arrange(Frame);
_ = view.Arrange(Frame);
}

return Frame.Size;
Expand Down Expand Up @@ -97,7 +97,7 @@ void INavigationView.RemovePage(IView page)
throw new NotImplementedException();
}

IFrameworkElement Content =>
IView Content =>
this.CurrentPage;

IReadOnlyList<IView> INavigationView.ModalStack => throw new NotImplementedException();
Expand Down
7 changes: 1 addition & 6 deletions src/Controls/src/Core/HandlerImpl/Page.Impl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@

namespace Microsoft.Maui.Controls
{
public partial class Page : IPage
public partial class Page : IView, ITitledElement
{
IView IPage.Content => null;

// TODO ezhart super sus
public Thickness Margin => Thickness.Zero;

internal void SendNavigatedTo(NavigatedToEventArgs args)
{
NavigatedTo?.Invoke(this, args);
Expand Down
8 changes: 4 additions & 4 deletions src/Controls/src/Core/HandlerImpl/ScrollView.Impl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace Microsoft.Maui.Controls
{
public partial class ScrollView : IScrollView
public partial class ScrollView : IScrollView, IContentView
{
IView IScrollView.Content => Content;
IView IContentView.Content => Content;

double IScrollView.HorizontalOffset
{
Expand Down Expand Up @@ -43,9 +43,9 @@ protected override Size MeasureOverride(double widthConstraint, double heightCon
{
DesiredSize = this.ComputeDesiredSize(widthConstraint, heightConstraint);

if (Content is IFrameworkElement frameworkElement)
if (Content is IView view)
{
_ = frameworkElement.Measure(widthConstraint, heightConstraint);
_ = view.Measure(widthConstraint, heightConstraint);
}

return DesiredSize;
Expand Down
49 changes: 43 additions & 6 deletions src/Controls/src/Core/HandlerImpl/View.Impl.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#nullable enable

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.HotReload;

namespace Microsoft.Maui.Controls
{
public partial class View
public partial class View : IView, IPropertyMapperView, IHotReloadableView
{
Thickness IView.Margin => Margin;

GestureManager? _gestureManager;
private protected override void OnHandlerChangedCore()
{
Expand All @@ -26,5 +25,43 @@ private protected override void OnHandlerChangingCore(HandlerChangingEventArgs a

base.OnHandlerChangingCore(args);
}

protected PropertyMapper propertyMapper;

protected PropertyMapper<T> GetRendererOverrides<T>() where T : IView =>
(PropertyMapper<T>)(propertyMapper as PropertyMapper<T> ?? (propertyMapper = new PropertyMapper<T>()));

PropertyMapper IPropertyMapperView.GetPropertyMapperOverrides() => propertyMapper;

Primitives.LayoutAlignment IView.HorizontalLayoutAlignment => HorizontalOptions.ToCore();
Primitives.LayoutAlignment IView.VerticalLayoutAlignment => VerticalOptions.ToCore();

#region HotReload

IView IReplaceableView.ReplacedView =>
MauiHotReloadHelper.GetReplacedView(this) ?? this;

IReloadHandler IHotReloadableView.ReloadHandler { get; set; }

void IHotReloadableView.TransferState(IView newView)
{
//TODO: LEt you hot reload the the ViewModel
if (newView is View v)
v.BindingContext = BindingContext;
}

void IHotReloadableView.Reload()
{
Device.BeginInvokeOnMainThread(() =>
{
this.CheckHandlers();
//Handler = null;
var reloadHandler = ((IHotReloadableView)this).ReloadHandler;
reloadHandler?.Reload();
//TODO: if reload handler is null, Do a manual reload?
});
}

#endregion
}
}
}
34 changes: 18 additions & 16 deletions src/Controls/src/Core/HandlerImpl/VisualElement.Impl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Microsoft.Maui.Controls
{
public partial class VisualElement : IFrameworkElement
public partial class VisualElement : IView
{
Semantics _semantics;

Expand Down Expand Up @@ -32,7 +32,7 @@ private protected override void OnHandlerChangedCore()
IsPlatformEnabled = Handler != null;
}

Paint IFrameworkElement.Background
Paint IView.Background
{
get
{
Expand All @@ -44,9 +44,9 @@ Paint IFrameworkElement.Background
}
}

IShape IFrameworkElement.Clip => Clip;
IShape IView.Clip => Clip;

IFrameworkElement IFrameworkElement.Parent => Parent as IFrameworkElement;
IView IView.Parent => Parent as IView;

public Size DesiredSize { get; protected set; }

Expand All @@ -55,7 +55,7 @@ public void Arrange(Rectangle bounds)
Layout(bounds);
}

Size IFrameworkElement.Arrange(Rectangle bounds)
Size IView.Arrange(Rectangle bounds)
{
return ArrangeOverride(bounds);
}
Expand All @@ -74,20 +74,20 @@ public void Layout(Rectangle bounds)
Bounds = bounds;
}

void IFrameworkElement.InvalidateMeasure()
void IView.InvalidateMeasure()
{
InvalidateMeasureOverride();
}

// InvalidateMeasureOverride provides a way to allow subclasses (e.g., Layout) to override InvalidateMeasure even though
// the interface has to be explicitly implemented to avoid conflict with the VisualElement.InvalidateMeasure method
protected virtual void InvalidateMeasureOverride() => Handler?.Invoke(nameof(IFrameworkElement.InvalidateMeasure));
protected virtual void InvalidateMeasureOverride() => Handler?.Invoke(nameof(IView.InvalidateMeasure));

void IFrameworkElement.InvalidateArrange()
void IView.InvalidateArrange()
{
}

Size IFrameworkElement.Measure(double widthConstraint, double heightConstraint)
Size IView.Measure(double widthConstraint, double heightConstraint)
{
return MeasureOverride(widthConstraint, heightConstraint);
}
Expand All @@ -100,13 +100,13 @@ protected virtual Size MeasureOverride(double widthConstraint, double heightCons
return DesiredSize;
}

Maui.FlowDirection IFrameworkElement.FlowDirection => FlowDirection.ToPlatformFlowDirection();
Primitives.LayoutAlignment IFrameworkElement.HorizontalLayoutAlignment => default;
Primitives.LayoutAlignment IFrameworkElement.VerticalLayoutAlignment => default;
Maui.FlowDirection IView.FlowDirection => FlowDirection.ToPlatformFlowDirection();
Primitives.LayoutAlignment IView.HorizontalLayoutAlignment => default;
Primitives.LayoutAlignment IView.VerticalLayoutAlignment => default;

Visibility IFrameworkElement.Visibility => IsVisible.ToVisibility();
Visibility IView.Visibility => IsVisible.ToVisibility();

Semantics IFrameworkElement.Semantics
Semantics IView.Semantics
{
get => _semantics;
}
Expand All @@ -116,7 +116,9 @@ Semantics IFrameworkElement.Semantics
internal Semantics SetupSemantics() =>
_semantics ??= new Semantics();

double IFrameworkElement.Width => WidthRequest;
double IFrameworkElement.Height => HeightRequest;
double IView.Width => WidthRequest;
double IView.Height => HeightRequest;

Thickness IView.Margin => Thickness.Zero;
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the only addition. We override it on View and we had this value on Page.

}
}
Loading