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 4 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 @@ -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
11 changes: 4 additions & 7 deletions src/Controls/src/Core/HandlerImpl/ContentPage.Impl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ namespace Microsoft.Maui.Controls
{
public partial class ContentPage : IPage, 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;

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 @@ -30,9 +27,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
6 changes: 3 additions & 3 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 Down Expand Up @@ -92,7 +92,7 @@ void INavigationView.RemovePage(IView page)
throw new NotImplementedException();
}

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

IReadOnlyList<IView> INavigationView.ModalStack => throw new NotImplementedException();
Expand Down
3 changes: 0 additions & 3 deletions src/Controls/src/Core/HandlerImpl/Page.Impl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ public partial class Page : IPage
{
IView IPage.Content => null;

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

internal void SendNavigatedTo(NavigatedToEventArgs args)
{
NavigatedTo?.Invoke(this, args);
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.

}
}
10 changes: 5 additions & 5 deletions src/Controls/src/Core/Layout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Size ILayoutManager.ArrangeChildren(Rectangle childBounds)
}
}

public abstract class Layout : View, ILayout, ILayoutController, IPaddingElement, IFrameworkElement, IVisualTreeElement
public abstract class Layout : View, ILayout, ILayoutController, IPaddingElement, IView, IVisualTreeElement
{
public static readonly BindableProperty IsClippedToBoundsProperty =
BindableProperty.Create(nameof(IsClippedToBounds), typeof(bool), typeof(Layout), false);
Expand Down Expand Up @@ -139,7 +139,7 @@ public static void LayoutChildIntoBoundingRegion(VisualElement child, Rectangle
if (child.Parent is IFlowDirectionController parent && (isRightToLeft = parent.ApplyEffectiveFlowDirectionToChildContainer && parent.EffectiveFlowDirection.IsRightToLeft()))
region = new Rectangle(parent.Width - region.Right, region.Y, region.Width, region.Height);

if (child is IFrameworkElement fe && fe.Handler != null)
if (child is IView fe && fe.Handler != null)
{
// The new arrange methods will take care of all the alignment and margins and such
fe.Arrange(region);
Expand Down Expand Up @@ -221,7 +221,7 @@ protected virtual void OnChildMeasureInvalidated()
{
}

Size IFrameworkElement.Measure(double widthConstraint, double heightConstraint)
Size IView.Measure(double widthConstraint, double heightConstraint)
{
return MeasureOverride(widthConstraint, heightConstraint);
}
Expand Down Expand Up @@ -292,7 +292,7 @@ internal static void LayoutChildIntoBoundingRegion(View child, Rectangle region,
if (child.Parent is IFlowDirectionController parent && (isRightToLeft = parent.ApplyEffectiveFlowDirectionToChildContainer && parent.EffectiveFlowDirection.IsRightToLeft()))
region = new Rectangle(parent.Width - region.Right, region.Y, region.Width, region.Height);

if (child is IFrameworkElement fe && fe.Handler != null)
if (child is IView fe && fe.Handler != null)
{
// The new arrange methods will take care of all the alignment and margins and such
fe.Arrange(region);
Expand Down Expand Up @@ -525,7 +525,7 @@ protected override void InvalidateMeasureOverride()

foreach (var child in LogicalChildren)
{
if (child is IFrameworkElement fe)
if (child is IView fe)
{
fe.InvalidateMeasure();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controls/src/Core/Layout/Layout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public Thickness Padding
public override SizeRequest GetSizeRequest(double widthConstraint, double heightConstraint)
#pragma warning restore CS0672 // Member overrides obsolete member
{
var size = (this as IFrameworkElement).Measure(widthConstraint, heightConstraint);
var size = (this as IView).Measure(widthConstraint, heightConstraint);
return new SizeRequest(size);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Controls/src/Core/Layout/StackLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Microsoft.Maui.Controls
public abstract class StackBase : Layout, IStackLayout
{
public static readonly BindableProperty SpacingProperty = BindableProperty.Create(nameof(Spacing), typeof(double), typeof(StackBase), 0d,
propertyChanged: (bindable, oldvalue, newvalue) => ((IFrameworkElement)bindable).InvalidateMeasure());
propertyChanged: (bindable, oldvalue, newvalue) => ((IView)bindable).InvalidateMeasure());

public double Spacing
{
Expand Down
2 changes: 1 addition & 1 deletion src/Controls/src/Core/LegacyLayouts/StackLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Microsoft.Maui.Controls.Compatibility
{
[ContentProperty(nameof(Children))]
public class StackLayout : Layout<View>, IElementConfiguration<StackLayout>, IFrameworkElement
public class StackLayout : Layout<View>, IElementConfiguration<StackLayout>, IView
{
public static readonly BindableProperty OrientationProperty = BindableProperty.Create(nameof(Orientation), typeof(StackOrientation), typeof(StackLayout), StackOrientation.Vertical,
propertyChanged: (bindable, oldvalue, newvalue) => ((StackLayout)bindable).InvalidateLayout());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)

var deviceIndependentWidth = widthMeasureSpec.ToDouble(Context);
var deviceIndependentHeight = heightMeasureSpec.ToDouble(Context);
var size = (_modal as IFrameworkElement).Measure(deviceIndependentWidth, deviceIndependentHeight);
var size = (_modal as IView).Measure(deviceIndependentWidth, deviceIndependentHeight);

var nativeWidth = Context.ToPixels(size.Width);
var nativeHeight = Context.ToPixels(size.Height);
Expand All @@ -251,7 +251,7 @@ protected override void OnLayout(bool changed, int l, int t, int r, int b)
var destination = Rectangle.FromLTRB(deviceIndependentLeft, deviceIndependentTop,
deviceIndependentRight, deviceIndependentBottom);

(_modal as IFrameworkElement).Arrange(destination);
(_modal as IView).Arrange(destination);
(_modal.Handler as INativeViewHandler)?.NativeArrange(_modal.Frame);
_backgroundView.Layout(0, 0, r - l, b - t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ void AddPage(Page page)
else if (!Container.Children.Contains(pageHandler.NativeView))
Container.Children.Add(pageHandler.NativeView);

(page as IFrameworkElement).Measure(Container.ActualWidth, Container.ActualHeight);
(page as IFrameworkElement).Arrange(ContainerBounds);
(page as IView).Measure(Container.ActualWidth, Container.ActualHeight);
(page as IView).Arrange(ContainerBounds);

page.Layout(ContainerBounds);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public static UIElement SetAutomationPropertiesLabeledBy(
return _defaultAutomationPropertiesLabeledBy;

// TODO Maui: this is a bit of a hack because Elements
// currently don't implement IFrameworkElement but they should
mauiContext ??= (Element as IFrameworkElement)?.Handler?.MauiContext;
// currently don't implement IView but they should
mauiContext ??= (Element as IView)?.Handler?.MauiContext;

if (_defaultAutomationPropertiesLabeledBy == null)
_defaultAutomationPropertiesLabeledBy = (UIElement)Control.GetValue(NativeAutomationProperties.LabeledByProperty);
Expand Down
2 changes: 1 addition & 1 deletion src/Controls/src/Core/ScrollView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ protected override SizeRequest OnSizeRequest(double widthConstraint, double heig

SizeRequest contentRequest;

if (Content is IFrameworkElement fe && fe.Handler != null)
if (Content is IView fe && fe.Handler != null)
{
contentRequest = fe.Measure(widthConstraint, heightConstraint);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controls/src/Core/SemanticProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static void OnHintPropertyChanged(BindableObject bindable, object oldValue, obje
static void UpdateSemanticsProperty(BindableObject bindable, Action<Semantics> action)
{
action.Invoke(((VisualElement)bindable).SetupSemantics());
if (bindable is IFrameworkElement fe)
if (bindable is IView fe)
fe.Handler?.UpdateValue(nameof(IView.Semantics));
}

Expand Down
Loading