Skip to content

Commit

Permalink
Reinstate IContentView and ILayout methods (#16411)
Browse files Browse the repository at this point in the history
* Reinstate IContentView and ILayout methods
Fixes #16166

* Limit fake methods to NET Standard 2.0

* Reverse the polarity

* Simplify

* Work around compatibility implementations of ICV/ICPL methods on ScrollView

* Use correct interface for Frame
  • Loading branch information
hartez authored Aug 1, 2023
1 parent ffa7240 commit 09df5c4
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ protected virtual void OnElementChanged(ElementChangedEventArgs<Frame> e)
protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
if (Element?.Handler is IPlatformViewHandler pvh &&
Element is IContentView cv &&
Element is ICrossPlatformLayout cpl &&
VirtualView is not null &&
Context is not null)
{
var measure = pvh.MeasureVirtualView(widthMeasureSpec, heightMeasureSpec, cv.CrossPlatformMeasure);
var measure = pvh.MeasureVirtualView(widthMeasureSpec, heightMeasureSpec, cpl.CrossPlatformMeasure);
SetMeasuredDimension((int)measure.Width, (int)measure.Height);
}
else
Expand Down
11 changes: 11 additions & 0 deletions src/Controls/src/Core/ContentPage/ContentPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@ void HotReload.IHotReloadableView.Reload()
//TODO: if reload handler is null, Do a manual reload?
});
}

#endregion

Size IContentView.CrossPlatformArrange(Rect bounds)
{
return (this as ICrossPlatformLayout).CrossPlatformArrange(bounds);
}

Size IContentView.CrossPlatformMeasure(double widthConstraint, double heightConstraint)
{
return (this as ICrossPlatformLayout).CrossPlatformMeasure(widthConstraint, heightConstraint);
}
}
}
17 changes: 17 additions & 0 deletions src/Core/src/Core/IContentView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,22 @@ public interface IContentView : IView, IPadding, ICrossPlatformLayout
/// Gets the content of this view as it will be rendered in the user interface, including any transformations or applied templates.
/// </summary>
IView? PresentedContent { get; }

/// <summary>
/// This interface method is provided for backward compatibility with previous versions.
/// Implementing classes should implement the ICrossPlatformLayout interface rather than directly implementing this method.
/// </summary>
new Size CrossPlatformMeasure(double widthConstraint, double heightConstraint);

/// <summary>
/// This interface method is provided for backward compatibility with previous versions.
/// Implementing classes should implement the ICrossPlatformLayout interface rather than directly implementing this method.
/// </summary>
new Size CrossPlatformArrange(Rect bounds);

#if !NETSTANDARD2_0
Size ICrossPlatformLayout.CrossPlatformArrange(Microsoft.Maui.Graphics.Rect bounds) => CrossPlatformArrange(bounds);
Size ICrossPlatformLayout.CrossPlatformMeasure(double widthConstraint, double heightConstraint) => CrossPlatformMeasure(widthConstraint, heightConstraint);
#endif
}
}
19 changes: 19 additions & 0 deletions src/Core/src/Core/ILayout.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Microsoft.Maui.Graphics;

namespace Microsoft.Maui
{
/// <summary>
Expand All @@ -10,5 +12,22 @@ public interface ILayout : IView, IContainer, ISafeAreaView, IPadding, ICrossPla
/// Specifies whether the ILayout clips its content to its boundaries.
/// </summary>
bool ClipsToBounds { get; }

/// <summary>
/// This interface method is provided for backward compatibility with previous versions.
/// Implementing classes should implement the ICrossPlatformLayout interface rather than directly implementing this method.
/// </summary>
new Size CrossPlatformArrange(Rect bounds);

/// <summary>
/// This interface method is provided for backward compatibility with previous versions.
/// Implementing classes should implement the ICrossPlatformLayout interface rather than directly implementing this method.
/// </summary>
new Size CrossPlatformMeasure(double widthConstraint, double heightConstraint);

#if !NETSTANDARD2_0
Size ICrossPlatformLayout.CrossPlatformArrange(Microsoft.Maui.Graphics.Rect bounds) => CrossPlatformArrange(bounds);
Size ICrossPlatformLayout.CrossPlatformMeasure(double widthConstraint, double heightConstraint) => CrossPlatformMeasure(widthConstraint, heightConstraint);
#endif
}
}
4 changes: 2 additions & 2 deletions src/Core/src/Handlers/ScrollView/ScrollViewHandler.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ Size ICrossPlatformLayout.CrossPlatformMeasure(double widthConstraint, double he
var measurementWidth = widthConstraint - padding.HorizontalThickness;
var measurementHeight = heightConstraint - padding.VerticalThickness;

var result = scrollView.CrossPlatformMeasure(measurementWidth, measurementHeight);
var result = (scrollView as ICrossPlatformLayout).CrossPlatformMeasure(measurementWidth, measurementHeight);

// ... and add the padding back in to the final result
var fullSize = new Size(result.Width + padding.HorizontalThickness, result.Height + padding.VerticalThickness);
Expand All @@ -246,7 +246,7 @@ Size ICrossPlatformLayout.CrossPlatformMeasure(double widthConstraint, double he

Size ICrossPlatformLayout.CrossPlatformArrange(Rect bounds)
{
return VirtualView.CrossPlatformArrange(bounds);
return (VirtualView as ICrossPlatformLayout).CrossPlatformArrange(bounds);
}
}
}
4 changes: 2 additions & 2 deletions src/Core/src/Handlers/ScrollView/ScrollViewHandler.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ Size ICrossPlatformLayout.CrossPlatformMeasure(double widthConstraint, double he
var measurementWidth = widthConstraint - padding.HorizontalThickness;
var measurementHeight = heightConstraint - padding.VerticalThickness;

var result = scrollView.CrossPlatformMeasure(measurementWidth, measurementHeight);
var result = (scrollView as ICrossPlatformLayout).CrossPlatformMeasure(measurementWidth, measurementHeight);

// ... and add the padding back in to the final result
var fullSize = new Size(result.Width + padding.HorizontalThickness, result.Height + padding.VerticalThickness);
Expand All @@ -189,7 +189,7 @@ Size ICrossPlatformLayout.CrossPlatformMeasure(double widthConstraint, double he

Size ICrossPlatformLayout.CrossPlatformArrange(Rect bounds)
{
return VirtualView.CrossPlatformArrange(bounds);
return (VirtualView as ICrossPlatformLayout).CrossPlatformArrange(bounds);
}
}
}
9 changes: 6 additions & 3 deletions src/Core/src/Handlers/ScrollView/ScrollViewHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ static void InsertContentView(UIScrollView platformScrollView, IScrollView scrol
public override Size GetDesiredSize(double widthConstraint, double heightConstraint)
{
var virtualView = VirtualView;
var crossPlatformLayout = virtualView as ICrossPlatformLayout;
var platformView = PlatformView;

if (platformView == null || virtualView == null)
Expand All @@ -204,7 +205,7 @@ public override Size GetDesiredSize(double widthConstraint, double heightConstra
widthConstraint = AccountForPadding(widthConstraint, padding.HorizontalThickness);
heightConstraint = AccountForPadding(heightConstraint, padding.VerticalThickness);

var crossPlatformContentSize = virtualView.CrossPlatformMeasure(widthConstraint, heightConstraint);
var crossPlatformContentSize = crossPlatformLayout.CrossPlatformMeasure(widthConstraint, heightConstraint);

// Add the padding back in for the final size
crossPlatformContentSize.Width += padding.HorizontalThickness;
Expand Down Expand Up @@ -273,6 +274,7 @@ static void SetContentSizeForOrientation(UIScrollView uiScrollView, double viewp
Size ICrossPlatformLayout.CrossPlatformMeasure(double widthConstraint, double heightConstraint)
{
var scrollView = VirtualView;
var crossPlatformLayout = scrollView as ICrossPlatformLayout;
var platformScrollView = PlatformView;

var presentedContent = scrollView.PresentedContent;
Expand All @@ -299,17 +301,18 @@ Size ICrossPlatformLayout.CrossPlatformMeasure(double widthConstraint, double he
heightConstraint = AccountForPadding(heightConstraint, padding.VerticalThickness);

// Now handle the actual cross-platform measurement of the ScrollView's content
var result = scrollView.CrossPlatformMeasure(widthConstraint, heightConstraint);
var result = crossPlatformLayout.CrossPlatformMeasure(widthConstraint, heightConstraint);

return result.AdjustForFill(new Rect(0, 0, widthConstraint, heightConstraint), presentedContent);
}

Size ICrossPlatformLayout.CrossPlatformArrange(Rect bounds)
{
var scrollView = VirtualView;
var crossPlatformLayout = scrollView as ICrossPlatformLayout;
var platformScrollView = PlatformView;

var contentSize = scrollView.CrossPlatformArrange(bounds);
var contentSize = crossPlatformLayout.CrossPlatformArrange(bounds);

// The UIScrollView's bounds are available, so we can use them to make sure the ContentSize makes sense
// for the ScrollView orientation
Expand Down
6 changes: 1 addition & 5 deletions src/Core/src/PublicAPI/net-android/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,4 @@ static Microsoft.Maui.SizeRequest.operator ==(Microsoft.Maui.SizeRequest left, M
override Microsoft.Maui.Platform.WrapperView.Visibility.get -> Android.Views.ViewStates
override Microsoft.Maui.Platform.WrapperView.Visibility.set -> void
~override Microsoft.Maui.Platform.WrapperView.DrawShadow(Android.Graphics.Canvas canvas, int viewWidth, int viewHeight) -> void
~override Microsoft.Maui.Platform.WrapperView.GetClipPath(int width, int height) -> Android.Graphics.Path
*REMOVED*Microsoft.Maui.IContentView.CrossPlatformArrange(Microsoft.Maui.Graphics.Rect bounds) -> Microsoft.Maui.Graphics.Size
*REMOVED*Microsoft.Maui.IContentView.CrossPlatformMeasure(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
*REMOVED*Microsoft.Maui.ILayout.CrossPlatformArrange(Microsoft.Maui.Graphics.Rect bounds) -> Microsoft.Maui.Graphics.Size
*REMOVED*Microsoft.Maui.ILayout.CrossPlatformMeasure(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
~override Microsoft.Maui.Platform.WrapperView.GetClipPath(int width, int height) -> Android.Graphics.Path
4 changes: 0 additions & 4 deletions src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ virtual Microsoft.Maui.MauiUIApplicationDelegate.PerformFetch(UIKit.UIApplicatio
Microsoft.Maui.Platform.MauiView.CacheMeasureConstraints(double widthConstraint, double heightConstraint) -> void
Microsoft.Maui.Platform.MauiView.InvalidateConstraintsCache() -> void
Microsoft.Maui.Platform.MauiView.IsMeasureValid(double widthConstraint, double heightConstraint) -> bool
*REMOVED*Microsoft.Maui.IContentView.CrossPlatformArrange(Microsoft.Maui.Graphics.Rect bounds) -> Microsoft.Maui.Graphics.Size
*REMOVED*Microsoft.Maui.IContentView.CrossPlatformMeasure(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
*REMOVED*Microsoft.Maui.ILayout.CrossPlatformArrange(Microsoft.Maui.Graphics.Rect bounds) -> Microsoft.Maui.Graphics.Size
*REMOVED*Microsoft.Maui.ILayout.CrossPlatformMeasure(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
*REMOVED*override Microsoft.Maui.Platform.ContentView.SetNeedsLayout() -> void
*REMOVED*override Microsoft.Maui.Platform.ContentView.SizeThatFits(CoreGraphics.CGSize size) -> CoreGraphics.CGSize
*REMOVED*override Microsoft.Maui.Platform.LayoutView.LayoutSubviews() -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ static Microsoft.Maui.SizeRequest.operator !=(Microsoft.Maui.SizeRequest left, M
static Microsoft.Maui.SizeRequest.operator ==(Microsoft.Maui.SizeRequest left, Microsoft.Maui.SizeRequest right) -> bool
Microsoft.Maui.LifecycleEvents.iOSLifecycle.PerformFetch
virtual Microsoft.Maui.MauiUIApplicationDelegate.PerformFetch(UIKit.UIApplication! application, System.Action<UIKit.UIBackgroundFetchResult>! completionHandler) -> void
*REMOVED*Microsoft.Maui.IContentView.CrossPlatformArrange(Microsoft.Maui.Graphics.Rect bounds) -> Microsoft.Maui.Graphics.Size
*REMOVED*Microsoft.Maui.IContentView.CrossPlatformMeasure(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
*REMOVED*Microsoft.Maui.ILayout.CrossPlatformArrange(Microsoft.Maui.Graphics.Rect bounds) -> Microsoft.Maui.Graphics.Size
*REMOVED*Microsoft.Maui.ILayout.CrossPlatformMeasure(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
*REMOVED*override Microsoft.Maui.Platform.ContentView.SetNeedsLayout() -> void
*REMOVED*override Microsoft.Maui.Platform.ContentView.SizeThatFits(CoreGraphics.CGSize size) -> CoreGraphics.CGSize
*REMOVED*override Microsoft.Maui.Platform.LayoutView.LayoutSubviews() -> void
Expand Down
4 changes: 0 additions & 4 deletions src/Core/src/PublicAPI/net-tizen/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,3 @@ Microsoft.Maui.IAccelerator
Microsoft.Maui.IAccelerator.Key.get -> string!
Microsoft.Maui.IAccelerator.Modifiers.get -> System.Collections.Generic.IReadOnlyList<string!>!
Microsoft.Maui.IMenuElement.Accelerators.get -> System.Collections.Generic.IReadOnlyList<Microsoft.Maui.IAccelerator!>?
*REMOVED*Microsoft.Maui.IContentView.CrossPlatformArrange(Microsoft.Maui.Graphics.Rect bounds) -> Microsoft.Maui.Graphics.Size
*REMOVED*Microsoft.Maui.IContentView.CrossPlatformMeasure(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
*REMOVED*Microsoft.Maui.ILayout.CrossPlatformArrange(Microsoft.Maui.Graphics.Rect bounds) -> Microsoft.Maui.Graphics.Size
*REMOVED*Microsoft.Maui.ILayout.CrossPlatformMeasure(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
4 changes: 0 additions & 4 deletions src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ static Microsoft.Maui.SizeRequest.operator !=(Microsoft.Maui.SizeRequest left, M
static Microsoft.Maui.SizeRequest.operator ==(Microsoft.Maui.SizeRequest left, Microsoft.Maui.SizeRequest right) -> bool
static Microsoft.Maui.Handlers.MenuFlyoutItemHandler.MapAccelerator(Microsoft.Maui.Handlers.IMenuFlyoutItemHandler! handler, Microsoft.Maui.IMenuFlyoutItem! view) -> void
static Microsoft.Maui.Handlers.MenuFlyoutSubItemHandler.MapAccelerator(Microsoft.Maui.Handlers.IMenuFlyoutSubItemHandler! handler, Microsoft.Maui.IMenuFlyoutSubItem! view) -> void
*REMOVED*Microsoft.Maui.IContentView.CrossPlatformArrange(Microsoft.Maui.Graphics.Rect bounds) -> Microsoft.Maui.Graphics.Size
*REMOVED*Microsoft.Maui.IContentView.CrossPlatformMeasure(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
*REMOVED*Microsoft.Maui.ILayout.CrossPlatformArrange(Microsoft.Maui.Graphics.Rect bounds) -> Microsoft.Maui.Graphics.Size
*REMOVED*Microsoft.Maui.ILayout.CrossPlatformMeasure(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
*REMOVED*override Microsoft.Maui.Platform.ContentPanel.MeasureOverride(Windows.Foundation.Size availableSize) -> Windows.Foundation.Size
*REMOVED*override Microsoft.Maui.Platform.LayoutPanel.MeasureOverride(Windows.Foundation.Size availableSize) -> Windows.Foundation.Size
static Microsoft.Maui.Handlers.DatePickerHandler.MapBackground(Microsoft.Maui.Handlers.IDatePickerHandler! handler, Microsoft.Maui.IDatePicker! datePicker) -> void
6 changes: 1 addition & 5 deletions src/Core/src/PublicAPI/net/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,4 @@ static Microsoft.Maui.PropertyMapperExtensions.ModifyMapping<TVirtualView, TView
static Microsoft.Maui.PropertyMapperExtensions.PrependToMapping<TVirtualView, TViewHandler>(this Microsoft.Maui.IPropertyMapper<Microsoft.Maui.IElement!, Microsoft.Maui.IElementHandler!>! propertyMapper, string! key, System.Action<TViewHandler, TVirtualView>! method) -> void
static Microsoft.Maui.PropertyMapperExtensions.ReplaceMapping<TVirtualView, TViewHandler>(this Microsoft.Maui.IPropertyMapper<Microsoft.Maui.IElement!, Microsoft.Maui.IElementHandler!>! propertyMapper, string! key, System.Action<TViewHandler, TVirtualView>! method) -> void
static Microsoft.Maui.SizeRequest.operator !=(Microsoft.Maui.SizeRequest left, Microsoft.Maui.SizeRequest right) -> bool
static Microsoft.Maui.SizeRequest.operator ==(Microsoft.Maui.SizeRequest left, Microsoft.Maui.SizeRequest right) -> bool
*REMOVED*Microsoft.Maui.IContentView.CrossPlatformArrange(Microsoft.Maui.Graphics.Rect bounds) -> Microsoft.Maui.Graphics.Size
*REMOVED*Microsoft.Maui.IContentView.CrossPlatformMeasure(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
*REMOVED*Microsoft.Maui.ILayout.CrossPlatformArrange(Microsoft.Maui.Graphics.Rect bounds) -> Microsoft.Maui.Graphics.Size
*REMOVED*Microsoft.Maui.ILayout.CrossPlatformMeasure(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
static Microsoft.Maui.SizeRequest.operator ==(Microsoft.Maui.SizeRequest left, Microsoft.Maui.SizeRequest right) -> bool
6 changes: 1 addition & 5 deletions src/Core/src/PublicAPI/netstandard/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,4 @@ static Microsoft.Maui.SizeRequest.operator !=(Microsoft.Maui.SizeRequest left, M
static Microsoft.Maui.SizeRequest.operator ==(Microsoft.Maui.SizeRequest left, Microsoft.Maui.SizeRequest right) -> bool
Microsoft.Maui.IAccelerator
Microsoft.Maui.IAccelerator.Key.get -> string!
Microsoft.Maui.IAccelerator.Modifiers.get -> System.Collections.Generic.IReadOnlyList<string!>!
*REMOVED*Microsoft.Maui.IContentView.CrossPlatformArrange(Microsoft.Maui.Graphics.Rect bounds) -> Microsoft.Maui.Graphics.Size
*REMOVED*Microsoft.Maui.IContentView.CrossPlatformMeasure(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
*REMOVED*Microsoft.Maui.ILayout.CrossPlatformArrange(Microsoft.Maui.Graphics.Rect bounds) -> Microsoft.Maui.Graphics.Size
*REMOVED*Microsoft.Maui.ILayout.CrossPlatformMeasure(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
Microsoft.Maui.IAccelerator.Modifiers.get -> System.Collections.Generic.IReadOnlyList<string!>!
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,4 @@ static Microsoft.Maui.PropertyMapperExtensions.ModifyMapping<TVirtualView, TView
static Microsoft.Maui.PropertyMapperExtensions.PrependToMapping<TVirtualView, TViewHandler>(this Microsoft.Maui.IPropertyMapper<Microsoft.Maui.IElement!, Microsoft.Maui.IElementHandler!>! propertyMapper, string! key, System.Action<TViewHandler, TVirtualView>! method) -> void
static Microsoft.Maui.PropertyMapperExtensions.ReplaceMapping<TVirtualView, TViewHandler>(this Microsoft.Maui.IPropertyMapper<Microsoft.Maui.IElement!, Microsoft.Maui.IElementHandler!>! propertyMapper, string! key, System.Action<TViewHandler, TVirtualView>! method) -> void
static Microsoft.Maui.SizeRequest.operator !=(Microsoft.Maui.SizeRequest left, Microsoft.Maui.SizeRequest right) -> bool
static Microsoft.Maui.SizeRequest.operator ==(Microsoft.Maui.SizeRequest left, Microsoft.Maui.SizeRequest right) -> bool
*REMOVED*Microsoft.Maui.IContentView.CrossPlatformArrange(Microsoft.Maui.Graphics.Rect bounds) -> Microsoft.Maui.Graphics.Size
*REMOVED*Microsoft.Maui.IContentView.CrossPlatformMeasure(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
*REMOVED*Microsoft.Maui.ILayout.CrossPlatformArrange(Microsoft.Maui.Graphics.Rect bounds) -> Microsoft.Maui.Graphics.Size
*REMOVED*Microsoft.Maui.ILayout.CrossPlatformMeasure(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
static Microsoft.Maui.SizeRequest.operator ==(Microsoft.Maui.SizeRequest left, Microsoft.Maui.SizeRequest right) -> bool

0 comments on commit 09df5c4

Please sign in to comment.