diff --git a/src/Controls/src/Core/Compatibility/Android/PlatformSizeService.cs b/src/Controls/src/Core/Compatibility/Android/PlatformSizeService.cs deleted file mode 100644 index 53dae264a0ec..000000000000 --- a/src/Controls/src/Core/Compatibility/Android/PlatformSizeService.cs +++ /dev/null @@ -1,21 +0,0 @@ -#nullable disable -using Microsoft.Maui.Controls.Internals; - -[assembly: Microsoft.Maui.Controls.Dependency(typeof(Microsoft.Maui.Controls.Compatibility.Platform.Android.PlatformSizeService))] - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Android -{ - class PlatformSizeService : IPlatformSizeService - { - public SizeRequest GetPlatformSize(VisualElement view, double widthConstraint, double heightConstraint) - { - if (widthConstraint > 0 && heightConstraint > 0) - { - return view.Handler?.GetDesiredSize(widthConstraint, heightConstraint) ?? - new SizeRequest(); - } - - return new SizeRequest(); - } - } -} \ No newline at end of file diff --git a/src/Controls/src/Core/Compatibility/Tizen/PlatformSizeService.cs b/src/Controls/src/Core/Compatibility/Tizen/PlatformSizeService.cs deleted file mode 100644 index b50b2f06654b..000000000000 --- a/src/Controls/src/Core/Compatibility/Tizen/PlatformSizeService.cs +++ /dev/null @@ -1,21 +0,0 @@ -#nullable disable -using Microsoft.Maui.Controls.Internals; - -[assembly: Microsoft.Maui.Controls.Dependency(typeof(Microsoft.Maui.Controls.Compatibility.Platform.Tizen.PlatformSizeService))] - -namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen -{ - class PlatformSizeService : IPlatformSizeService - { - public SizeRequest GetPlatformSize(VisualElement view, double widthConstraint, double heightConstraint) - { - if (widthConstraint > 0 && heightConstraint > 0) - { - return view.Handler?.GetDesiredSize(widthConstraint, heightConstraint) ?? - new SizeRequest(); - } - - return new SizeRequest(); - } - } -} \ No newline at end of file diff --git a/src/Controls/src/Core/Compatibility/Windows/PlatformSizeService.cs b/src/Controls/src/Core/Compatibility/Windows/PlatformSizeService.cs deleted file mode 100644 index a1374d080b8d..000000000000 --- a/src/Controls/src/Core/Compatibility/Windows/PlatformSizeService.cs +++ /dev/null @@ -1,21 +0,0 @@ -#nullable disable -using Microsoft.Maui.Controls.Internals; - -[assembly: Microsoft.Maui.Controls.Dependency(typeof(Microsoft.Maui.Controls.Compatibility.Platform.UWP.PlatformSizeService))] - -namespace Microsoft.Maui.Controls.Compatibility.Platform.UWP -{ - class PlatformSizeService : IPlatformSizeService - { - public SizeRequest GetPlatformSize(VisualElement view, double widthConstraint, double heightConstraint) - { - if (widthConstraint > 0 && heightConstraint > 0) - { - return view.Handler?.GetDesiredSize(widthConstraint, heightConstraint) ?? - new SizeRequest(); - } - - return new SizeRequest(); - } - } -} \ No newline at end of file diff --git a/src/Controls/src/Core/Compatibility/iOS/PlatformSizeService.cs b/src/Controls/src/Core/Compatibility/iOS/PlatformSizeService.cs deleted file mode 100644 index 843fabab8353..000000000000 --- a/src/Controls/src/Core/Compatibility/iOS/PlatformSizeService.cs +++ /dev/null @@ -1,21 +0,0 @@ -#nullable disable -using Microsoft.Maui.Controls.Internals; - -[assembly: Microsoft.Maui.Controls.Dependency(typeof(Microsoft.Maui.Controls.Compatibility.Platform.iOS.PlatformSizeService))] - -namespace Microsoft.Maui.Controls.Compatibility.Platform.iOS -{ - class PlatformSizeService : IPlatformSizeService - { - public SizeRequest GetPlatformSize(VisualElement view, double widthConstraint, double heightConstraint) - { - if (widthConstraint > 0 && heightConstraint > 0) - { - return view.Handler?.GetDesiredSize(widthConstraint, heightConstraint) ?? - new SizeRequest(); - } - - return new SizeRequest(); - } - } -} \ No newline at end of file diff --git a/src/Controls/src/Core/IPlatformSizeService.cs b/src/Controls/src/Core/IPlatformSizeService.cs index d59f630e30ea..5fc8ae50f139 100644 --- a/src/Controls/src/Core/IPlatformSizeService.cs +++ b/src/Controls/src/Core/IPlatformSizeService.cs @@ -1,8 +1,10 @@ #nullable disable +using System; namespace Microsoft.Maui.Controls.Internals { + [Obsolete("No .NET MAUI code makes use of IPlatformSizeService and this interface will be removed in a future .NET MAUI release.")] public interface IPlatformSizeService { SizeRequest GetPlatformSize(VisualElement view, double widthConstraint, double heightConstraint); } -} \ No newline at end of file +} diff --git a/src/Controls/src/Core/IndicatorView/IndicatorView.cs b/src/Controls/src/Core/IndicatorView/IndicatorView.cs index 5071ca48a1a7..c5ae0226cf3c 100644 --- a/src/Controls/src/Core/IndicatorView/IndicatorView.cs +++ b/src/Controls/src/Core/IndicatorView/IndicatorView.cs @@ -130,20 +130,14 @@ public IEnumerable ItemsSource set => SetValue(ItemsSourceProperty, value); } - IPlatformSizeService _platformSizeService; - protected override SizeRequest OnMeasure(double widthConstraint, double heightConstraint) { if (IndicatorTemplate == null) { - if (Handler != null) - return new SizeRequest(Handler.GetDesiredSize(widthConstraint, heightConstraint)); - - _platformSizeService ??= DependencyService.Get(); - return _platformSizeService.GetPlatformSize(this, widthConstraint, heightConstraint); + return Handler?.GetDesiredSize(widthConstraint, heightConstraint) ?? new(); } - else - return base.OnMeasure(widthConstraint, heightConstraint); + + return base.OnMeasure(widthConstraint, heightConstraint); } static void UpdateIndicatorLayout(IndicatorView indicatorView, object newValue) diff --git a/src/Controls/src/Core/RadioButton/RadioButton.cs b/src/Controls/src/Core/RadioButton/RadioButton.cs index 92d692960e17..802996550801 100644 --- a/src/Controls/src/Core/RadioButton/RadioButton.cs +++ b/src/Controls/src/Core/RadioButton/RadioButton.cs @@ -289,17 +289,11 @@ protected internal override void ChangeVisualState() base.ChangeVisualState(); } - IPlatformSizeService _platformSizeService; - protected override SizeRequest OnMeasure(double widthConstraint, double heightConstraint) { if (ControlTemplate == null) { - if (Handler != null) - return new SizeRequest(Handler.GetDesiredSize(widthConstraint, heightConstraint)); - - _platformSizeService ??= DependencyService.Get(); - return _platformSizeService.GetPlatformSize(this, widthConstraint, heightConstraint); + return Handler?.GetDesiredSize(widthConstraint, heightConstraint) ?? new(); } return base.OnMeasure(widthConstraint, heightConstraint); diff --git a/src/Controls/src/Core/VisualElement/VisualElement.cs b/src/Controls/src/Core/VisualElement/VisualElement.cs index 38f9eabf7fec..fa3ff12f1e2b 100644 --- a/src/Controls/src/Core/VisualElement/VisualElement.cs +++ b/src/Controls/src/Core/VisualElement/VisualElement.cs @@ -1281,8 +1281,6 @@ protected override void OnChildRemoved(Element child, int oldLogicalIndex) protected void OnChildrenReordered() => ChildrenReordered?.Invoke(this, EventArgs.Empty); - IPlatformSizeService _platformSizeService; - /// /// Method that is called when a layout measurement happens. /// @@ -1294,11 +1292,7 @@ protected virtual SizeRequest OnMeasure(double widthConstraint, double heightCon if (!IsPlatformEnabled) return new SizeRequest(new Size(-1, -1)); - if (Handler != null) - return new SizeRequest(Handler.GetDesiredSize(widthConstraint, heightConstraint)); - - _platformSizeService ??= DependencyService.Get(); - return _platformSizeService.GetPlatformSize(this, widthConstraint, heightConstraint); + return Handler?.GetDesiredSize(widthConstraint, heightConstraint) ?? new(); } /// diff --git a/src/Controls/src/Xaml/Hosting/AppHostBuilderExtensions.cs b/src/Controls/src/Xaml/Hosting/AppHostBuilderExtensions.cs index ebbd595dffa2..be19ae126e28 100644 --- a/src/Controls/src/Xaml/Hosting/AppHostBuilderExtensions.cs +++ b/src/Controls/src/Xaml/Hosting/AppHostBuilderExtensions.cs @@ -170,7 +170,6 @@ static MauiAppBuilder SetupDefaults(this MauiAppBuilder builder) // initialize compatibility DependencyService DependencyService.SetToInitialized(); DependencyService.Register(); - DependencyService.Register(); #pragma warning disable CS0612, CA1416 // Type or member is obsolete, 'ResourcesProvider' is unsupported on: 'iOS' 14.0 and later DependencyService.Register(); diff --git a/src/Controls/tests/Core.UnitTests/AbsoluteLayoutTests.cs b/src/Controls/tests/Core.UnitTests/AbsoluteLayoutTests.cs index 669b24d58edf..50c2aa2c2af6 100644 --- a/src/Controls/tests/Core.UnitTests/AbsoluteLayoutTests.cs +++ b/src/Controls/tests/Core.UnitTests/AbsoluteLayoutTests.cs @@ -38,7 +38,7 @@ public void AbsolutePositionAndSizeUsingRectangle() IsPlatformEnabled = true }; - var child = new View { IsPlatformEnabled = true }; + var child = MockPlatformSizeService.Sub(); abs.Children.Add(child, new Rect(10, 20, 30, 40)); @@ -56,8 +56,7 @@ public void AbsolutePositionRelativeSize() IsPlatformEnabled = true }; - var child = new View { IsPlatformEnabled = true }; - + var child = MockPlatformSizeService.Sub(); abs.Children.Add(child, new Rect(10, 20, 0.4, 0.5), AbsoluteLayoutFlags.SizeProportional); @@ -81,7 +80,7 @@ public void RelativePositionAbsoluteSize(double width, double height, double rel IsPlatformEnabled = true }; - var child = new View { IsPlatformEnabled = true }; + var child = MockPlatformSizeService.Sub(); abs.Children.Add(child, new Rect(relX, relY, width, height), AbsoluteLayoutFlags.PositionProportional); @@ -109,10 +108,7 @@ public void RelativePositionRelativeSize(double relX, double relY, double relHei IsPlatformEnabled = true }; - var child = new View - { - IsPlatformEnabled = true - }; + var child = MockPlatformSizeService.Sub(); abs.Children.Add(child, new Rect(relX, relY, relWidth, relHeight), AbsoluteLayoutFlags.All); abs.Layout(new Rect(0, 0, 100, 100)); @@ -135,7 +131,7 @@ public void SizeRequestWithNormalChild() IsPlatformEnabled = true }; - var child = new View(); + var child = MockPlatformSizeService.Sub(); // ChildSizeReq == 100x20 abs.Children.Add(child, new Rect(10, 20, 30, 40)); @@ -154,7 +150,7 @@ public void SizeRequestWithRelativePositionChild() IsPlatformEnabled = true }; - var child = new View(); + var child = MockPlatformSizeService.Sub(); // ChildSizeReq == 100x20 abs.Children.Add(child, new Rect(0.5, 0.5, 30, 40), AbsoluteLayoutFlags.PositionProportional); @@ -173,10 +169,7 @@ public void SizeRequestWithRelativeChild() IsPlatformEnabled = true }; - var child = new View - { - IsPlatformEnabled = true - }; + var child = MockPlatformSizeService.Sub(); // ChildSizeReq == 100x20 abs.Children.Add(child, new Rect(0.5, 0.5, 0.5, 0.5), AbsoluteLayoutFlags.All); @@ -195,10 +188,7 @@ public void SizeRequestWithRelativeSizeChild() IsPlatformEnabled = true }; - var child = new View - { - IsPlatformEnabled = true - }; + var child = MockPlatformSizeService.Sub(); // ChildSizeReq == 100x20 abs.Children.Add(child, new Rect(10, 20, 0.5, 0.5), AbsoluteLayoutFlags.SizeProportional); @@ -217,10 +207,7 @@ public void MeasureInvalidatedFiresWhenFlagsChanged() IsPlatformEnabled = true }; - var child = new View - { - IsPlatformEnabled = true - }; + var child = MockPlatformSizeService.Sub(); abs.Children.Add(child, new Rect(1, 1, 100, 100)); @@ -240,10 +227,7 @@ public void MeasureInvalidatedFiresWhenBoundsChanged() IsPlatformEnabled = true }; - var child = new View - { - IsPlatformEnabled = true - }; + var child = MockPlatformSizeService.Sub(); abs.Children.Add(child, new Rect(1, 1, 100, 100)); diff --git a/src/Controls/tests/Core.UnitTests/BaseTestFixture.cs b/src/Controls/tests/Core.UnitTests/BaseTestFixture.cs index 95367db7a3f3..6df23fa7410e 100644 --- a/src/Controls/tests/Core.UnitTests/BaseTestFixture.cs +++ b/src/Controls/tests/Core.UnitTests/BaseTestFixture.cs @@ -29,7 +29,6 @@ public BaseTestFixture() Microsoft.Maui.Controls.Hosting.CompatibilityCheck.UseCompatibility(); _defaultCulture = System.Threading.Thread.CurrentThread.CurrentCulture; _defaultUICulture = System.Threading.Thread.CurrentThread.CurrentUICulture; - MockPlatformSizeService.Current?.Reset(); DispatcherProvider.SetCurrent(new DispatcherProviderStub()); DeviceDisplay.SetCurrent(null); DeviceInfo.SetCurrent(null); @@ -53,7 +52,6 @@ protected virtual void Dispose(bool disposing) if (disposing) { - MockPlatformSizeService.Current?.Reset(); AppInfo.SetCurrent(null); DeviceDisplay.SetCurrent(null); DeviceInfo.SetCurrent(null); diff --git a/src/Controls/tests/Core.UnitTests/FlexLayoutAlignContentTests.cs b/src/Controls/tests/Core.UnitTests/FlexLayoutAlignContentTests.cs index 66aa292d46b4..556ae6265fbb 100644 --- a/src/Controls/tests/Core.UnitTests/FlexLayoutAlignContentTests.cs +++ b/src/Controls/tests/Core.UnitTests/FlexLayoutAlignContentTests.cs @@ -13,7 +13,7 @@ public class FlexLayoutAlignContentTests : BaseTestFixture [Fact] public void TestAlignContentFlexStart() { - MockPlatformSizeService.Current.GetPlatformSizeFunc = (visual, width, height) => new SizeRequest(new Size(50, 10)); + static SizeRequest GetPlatformSize(VisualElement v, double w, double h) => new(new Size(50, 10)); var layout = new FlexLayout { @@ -27,19 +27,19 @@ public void TestAlignContentFlexStart() Wrap = FlexWrap.Wrap, }; - var view0 = new View { IsPlatformEnabled = true, WidthRequest = 50, HeightRequest = 10, }; + var view0 = MockPlatformSizeService.Sub(GetPlatformSize, width: 50, height: 10); layout.Children.Add(view0); - var view1 = new View { IsPlatformEnabled = true, WidthRequest = 50, HeightRequest = 10, }; + var view1 = MockPlatformSizeService.Sub(GetPlatformSize, width: 50, height: 10); layout.Children.Add(view1); - var view2 = new View { IsPlatformEnabled = true, WidthRequest = 50, HeightRequest = 10, }; + var view2 = MockPlatformSizeService.Sub(GetPlatformSize, width: 50, height: 10); layout.Children.Add(view2); - var view3 = new View { IsPlatformEnabled = true, WidthRequest = 50, HeightRequest = 10, }; + var view3 = MockPlatformSizeService.Sub(GetPlatformSize, width: 50, height: 10); layout.Children.Add(view3); - var view4 = new View { IsPlatformEnabled = true, WidthRequest = 50, HeightRequest = 10, }; + var view4 = MockPlatformSizeService.Sub(GetPlatformSize, width: 50, height: 10); layout.Children.Add(view4); layout.Layout(new Rect(0, 0, 130, 100)); @@ -55,7 +55,7 @@ public void TestAlignContentFlexStart() [Fact] public void TestAlignContentFlexStartWithoutHeightOnChildren() { - MockPlatformSizeService.Current.GetPlatformSizeFunc = (visual, width, height) => new SizeRequest(new Size(50, 10)); + static SizeRequest GetPlatformSize(VisualElement v, double w, double h) => new(new Size(50, 10)); var layout = new FlexLayout { @@ -67,19 +67,19 @@ public void TestAlignContentFlexStartWithoutHeightOnChildren() Direction = FlexDirection.Column, Wrap = FlexWrap.Wrap, }; - var view0 = new View { IsPlatformEnabled = true, WidthRequest = 50, }; + var view0 = MockPlatformSizeService.Sub(GetPlatformSize, width: 50); layout.Children.Add(view0); - var view1 = new View { IsPlatformEnabled = true, WidthRequest = 50, HeightRequest = 10, }; + var view1 = MockPlatformSizeService.Sub(GetPlatformSize, width: 50, height: 10); layout.Children.Add(view1); - var view2 = new View { IsPlatformEnabled = true, WidthRequest = 50, }; + var view2 = MockPlatformSizeService.Sub(GetPlatformSize, width: 50); layout.Children.Add(view2); - var view3 = new View { IsPlatformEnabled = true, WidthRequest = 50, HeightRequest = 10, }; + var view3 = MockPlatformSizeService.Sub(GetPlatformSize, width: 50, height: 10); layout.Children.Add(view3); - var view4 = new View { IsPlatformEnabled = true, WidthRequest = 50, HeightRequest = 10, }; + var view4 = MockPlatformSizeService.Sub(GetPlatformSize, width: 50, height: 10); layout.Children.Add(view4); layout.Layout(new Rect(0, 0, 100, 100)); @@ -94,7 +94,7 @@ public void TestAlignContentFlexStartWithoutHeightOnChildren() [Fact] public void TestAlignContentFlexStartWithFlex() { - MockPlatformSizeService.Current.GetPlatformSizeFunc = (visual, width, height) => new SizeRequest(new Size(0, 0)); + static SizeRequest GetPlatformSize(VisualElement v, double w, double h) => new(new Size(0, 0)); var layout = new FlexLayout { @@ -107,31 +107,31 @@ public void TestAlignContentFlexStartWithFlex() AlignItems = FlexAlignItems.Start, }; - var view0 = new View { IsPlatformEnabled = true }; + var view0 = MockPlatformSizeService.Sub(GetPlatformSize); FlexLayout.SetGrow(view0, 1); FlexLayout.SetBasis(view0, 0); view0.WidthRequest = 50; layout.Children.Add(view0); - var view1 = new View { IsPlatformEnabled = true }; + var view1 = MockPlatformSizeService.Sub(GetPlatformSize); FlexLayout.SetGrow(view1, 1); FlexLayout.SetBasis(view1, 0); view1.WidthRequest = 50; view1.HeightRequest = 10; layout.Children.Add(view1); - var view2 = new View { IsPlatformEnabled = true }; + var view2 = MockPlatformSizeService.Sub(GetPlatformSize); view2.WidthRequest = 50; layout.Children.Add(view2); - var view3 = new View { IsPlatformEnabled = true }; + var view3 = MockPlatformSizeService.Sub(GetPlatformSize); FlexLayout.SetGrow(view3, 1); FlexLayout.SetShrink(view3, 1); FlexLayout.SetBasis(view3, 0); view3.WidthRequest = 50; layout.Children.Add(view3); - var view4 = new View { IsPlatformEnabled = true }; + var view4 = MockPlatformSizeService.Sub(GetPlatformSize); view4.WidthRequest = 50; layout.Children.Add(view4); @@ -148,7 +148,7 @@ public void TestAlignContentFlexStartWithFlex() [Fact] public void TestAlignContentFlexEnd() { - MockPlatformSizeService.Current.GetPlatformSizeFunc = (visual, width, height) => new SizeRequest(new Size(50, 10)); + static SizeRequest GetPlatformSize(VisualElement v, double w, double h) => new(new Size(50, 10)); var layout = new FlexLayout { @@ -162,12 +162,7 @@ public void TestAlignContentFlexEnd() Wrap = FlexWrap.Wrap, }; - Func createView = () => new View - { - IsPlatformEnabled = true, - WidthRequest = 50, - HeightRequest = 10, - }; + Func createView = () => MockPlatformSizeService.Sub(GetPlatformSize, width: 50, height: 10); var view0 = createView(); layout.Children.Add(view0); @@ -198,7 +193,7 @@ public void TestAlignContentFlexEnd() [Fact] public void TestAlignContentStretch() { - MockPlatformSizeService.Current.GetPlatformSizeFunc = (visual, width, height) => new SizeRequest(new Size(0, 0)); + static SizeRequest GetPlatformSize(VisualElement v, double w, double h) => new(new Size(0, 0)); var layout = new FlexLayout { @@ -210,23 +205,23 @@ public void TestAlignContentStretch() WidthRequest = 150, HeightRequest = 100 }; - var view0 = new View { IsPlatformEnabled = true }; + var view0 = MockPlatformSizeService.Sub(GetPlatformSize); view0.WidthRequest = 50; layout.Children.Add(view0); - var view1 = new View { IsPlatformEnabled = true }; + var view1 = MockPlatformSizeService.Sub(GetPlatformSize); view1.WidthRequest = 50; layout.Children.Add(view1); - var view2 = new View { IsPlatformEnabled = true }; + var view2 = MockPlatformSizeService.Sub(GetPlatformSize); view2.WidthRequest = 50; layout.Children.Add(view2); - var view3 = new View { IsPlatformEnabled = true }; + var view3 = MockPlatformSizeService.Sub(GetPlatformSize); view3.WidthRequest = 50; layout.Children.Add(view3); - var view4 = new View { IsPlatformEnabled = true }; + var view4 = MockPlatformSizeService.Sub(GetPlatformSize); view4.WidthRequest = 50; layout.Children.Add(view4); @@ -266,7 +261,7 @@ public void TestAlignContentStretch() [Fact] public void TestAlignContentSpaceBetween() { - MockPlatformSizeService.Current.GetPlatformSizeFunc = (visual, width, height) => new SizeRequest(new Size(50, 10)); + static SizeRequest GetPlatformSize(VisualElement v, double w, double h) => new(new Size(50, 10)); var layout = new FlexLayout { @@ -279,19 +274,19 @@ public void TestAlignContentSpaceBetween() Wrap = FlexWrap.Wrap, }; - var view0 = new View { IsPlatformEnabled = true, WidthRequest = 50, HeightRequest = 10 }; + var view0 = MockPlatformSizeService.Sub(GetPlatformSize, width: 50, height: 10); layout.Children.Add(view0); - var view1 = new View { IsPlatformEnabled = true, WidthRequest = 50, HeightRequest = 10 }; + var view1 = MockPlatformSizeService.Sub(GetPlatformSize, width: 50, height: 10); layout.Children.Add(view1); - var view2 = new View { IsPlatformEnabled = true, WidthRequest = 50, HeightRequest = 10 }; + var view2 = MockPlatformSizeService.Sub(GetPlatformSize, width: 50, height: 10); layout.Children.Add(view2); - var view3 = new View { IsPlatformEnabled = true, WidthRequest = 50, HeightRequest = 10 }; + var view3 = MockPlatformSizeService.Sub(GetPlatformSize, width: 50, height: 10); layout.Children.Add(view3); - var view4 = new View { IsPlatformEnabled = true, WidthRequest = 50, HeightRequest = 10 }; + var view4 = MockPlatformSizeService.Sub(GetPlatformSize, width: 50, height: 10); layout.Children.Add(view4); layout.Layout(new Rect(0, 0, 130, 100)); @@ -307,7 +302,7 @@ public void TestAlignContentSpaceBetween() [Fact] public void TestAlignContentSpaceAround() { - MockPlatformSizeService.Current.GetPlatformSizeFunc = (visual, width, height) => new SizeRequest(new Size(50, 10)); + static SizeRequest GetPlatformSize(VisualElement v, double w, double h) => new(new Size(50, 10)); var layout = new FlexLayout { @@ -319,19 +314,19 @@ public void TestAlignContentSpaceAround() AlignContent = FlexAlignContent.SpaceAround, Wrap = FlexWrap.Wrap, }; - var view0 = new View { IsPlatformEnabled = true, WidthRequest = 50, HeightRequest = 10, }; + var view0 = MockPlatformSizeService.Sub(GetPlatformSize, width: 50, height: 10); layout.Children.Add(view0); - var view1 = new View { IsPlatformEnabled = true, WidthRequest = 50, HeightRequest = 10, }; + var view1 = MockPlatformSizeService.Sub(GetPlatformSize, width: 50, height: 10); layout.Children.Add(view1); - var view2 = new View { IsPlatformEnabled = true, WidthRequest = 50, HeightRequest = 10, }; + var view2 = MockPlatformSizeService.Sub(GetPlatformSize, width: 50, height: 10); layout.Children.Add(view2); - var view3 = new View { IsPlatformEnabled = true, WidthRequest = 50, HeightRequest = 10, }; + var view3 = MockPlatformSizeService.Sub(GetPlatformSize, width: 50, height: 10); layout.Children.Add(view3); - var view4 = new View { IsPlatformEnabled = true, WidthRequest = 50, HeightRequest = 10, }; + var view4 = MockPlatformSizeService.Sub(GetPlatformSize, width: 50, height: 10); layout.Children.Add(view4); layout.Layout(new Rect(0, 0, 140, 120)); @@ -357,23 +352,23 @@ public void TestAlignContentStretchRow() WidthRequest = 150, HeightRequest = 100 }; - var view0 = new View { IsPlatformEnabled = true }; + var view0 = MockPlatformSizeService.Sub(); view0.WidthRequest = 50; layout.Children.Add(view0); - var view1 = new View { IsPlatformEnabled = true }; + var view1 = MockPlatformSizeService.Sub(); view1.WidthRequest = 50; layout.Children.Add(view1); - var view2 = new View { IsPlatformEnabled = true }; + var view2 = MockPlatformSizeService.Sub(); view2.WidthRequest = 50; layout.Children.Add(view2); - var view3 = new View { IsPlatformEnabled = true }; + var view3 = MockPlatformSizeService.Sub(); view3.WidthRequest = 50; layout.Children.Add(view3); - var view4 = new View { IsPlatformEnabled = true }; + var view4 = MockPlatformSizeService.Sub(); view4.WidthRequest = 50; layout.Children.Add(view4); @@ -426,22 +421,22 @@ public void TestAlignContentStretchRowWithChildren() var view0 = new FlexLayout { IsPlatformEnabled = true, WidthRequest = 50, }; layout.Children.Add(view0); - //var view0_child0 = new View { IsPlatformEnabled = true }; + //var view0_child0 = MockPlatformSizeService.Sub(); //FlexLayout.SetGrow(view0_child0, 1); //FlexLayout.SetShrink(view0_child0, 1); //FlexLayout.SetBasis(view0_child0, 0); //view0.Children.Add(view0_child0); - var view1 = new View { IsPlatformEnabled = true, WidthRequest = 50, }; + var view1 = MockPlatformSizeService.Sub(width: 50); layout.Children.Add(view1); - var view2 = new View { IsPlatformEnabled = true, WidthRequest = 50, }; + var view2 = MockPlatformSizeService.Sub(width: 50); layout.Children.Add(view2); - var view3 = new View { IsPlatformEnabled = true, WidthRequest = 50, }; + var view3 = MockPlatformSizeService.Sub(width: 50); layout.Children.Add(view3); - var view4 = new View { IsPlatformEnabled = true, WidthRequest = 50, }; + var view4 = MockPlatformSizeService.Sub(width: 50); layout.Children.Add(view4); layout.Layout(new Rect(0, 0, 150, 100)); @@ -490,25 +485,25 @@ public void TestAlignContentStretchRowWithFlex() Direction = FlexDirection.Row, Wrap = FlexWrap.Wrap, }; - var view0 = new View { IsPlatformEnabled = true, WidthRequest = 50 }; + var view0 = MockPlatformSizeService.Sub(width: 50); layout.Children.Add(view0); - var view1 = new View { IsPlatformEnabled = true, WidthRequest = 50 }; + var view1 = MockPlatformSizeService.Sub(width: 50); FlexLayout.SetGrow(view1, 1); FlexLayout.SetShrink(view1, 1); FlexLayout.SetBasis(view1, 0); layout.Children.Add(view1); - var view2 = new View { IsPlatformEnabled = true, WidthRequest = 50 }; + var view2 = MockPlatformSizeService.Sub(width: 50); layout.Children.Add(view2); - var view3 = new View { IsPlatformEnabled = true, WidthRequest = 50 }; + var view3 = MockPlatformSizeService.Sub(width: 50); FlexLayout.SetGrow(view3, 1); FlexLayout.SetShrink(view3, 1); FlexLayout.SetBasis(view3, 0); layout.Children.Add(view3); - var view4 = new View { IsPlatformEnabled = true, WidthRequest = 50 }; + var view4 = MockPlatformSizeService.Sub(width: 50); layout.Children.Add(view4); layout.Layout(new Rect(0, 0, 150, 100)); @@ -533,24 +528,24 @@ public void TestAlignContentStretchRowWithFlexNoShrink() WidthRequest = 150, HeightRequest = 100 }; - var view0 = new View { IsPlatformEnabled = true, WidthRequest = 50 }; + var view0 = MockPlatformSizeService.Sub(width: 50); layout.Children.Add(view0); - var view1 = new View { IsPlatformEnabled = true, WidthRequest = 50 }; + var view1 = MockPlatformSizeService.Sub(width: 50); FlexLayout.SetGrow(view1, 1); FlexLayout.SetShrink(view1, 1); FlexLayout.SetBasis(view1, 0); layout.Children.Add(view1); - var view2 = new View { IsPlatformEnabled = true, WidthRequest = 50 }; + var view2 = MockPlatformSizeService.Sub(width: 50); layout.Children.Add(view2); - var view3 = new View { IsPlatformEnabled = true, WidthRequest = 50 }; + var view3 = MockPlatformSizeService.Sub(width: 50); FlexLayout.SetGrow(view3, 1); FlexLayout.SetBasis(view3, 0); layout.Children.Add(view3); - var view4 = new View { IsPlatformEnabled = true, WidthRequest = 50 }; + var view4 = MockPlatformSizeService.Sub(width: 50); layout.Children.Add(view4); layout.Layout(new Rect(0, 0, 150, 100)); @@ -608,38 +603,16 @@ public void TestAlignContentStretchRowWithMargin() layout.Children.Add(view0); - var view1 = new View - { - IsPlatformEnabled = true, - Margin = 10, - WidthRequest = 50, - HeightRequest = 20, - }; + var view1 = MockPlatformSizeService.Sub(width: 50, height: 20, margin: 10); layout.Children.Add(view1); - var view2 = new View - { - IsPlatformEnabled = true, - WidthRequest = 50, - HeightRequest = 20, - }; + var view2 = MockPlatformSizeService.Sub(width: 50, height: 20); layout.Children.Add(view2); - var view3 = new View - { - IsPlatformEnabled = true, - Margin = new Thickness(10), - WidthRequest = 50, - HeightRequest = 20, - }; + var view3 = MockPlatformSizeService.Sub(width: 50, height: 20, margin: 10); layout.Children.Add(view3); - var view4 = new View - { - IsPlatformEnabled = true, - WidthRequest = 50, - HeightRequest = 20, - }; + var view4 = MockPlatformSizeService.Sub(width: 50, height: 20); layout.Children.Add(view4); layout.Layout(new Rect(0, 0, 150, 100)); @@ -664,11 +637,11 @@ public void TestAlignContentStretchRowWithSingleRow() WidthRequest = 150, HeightRequest = 100 }; - var view0 = new View { IsPlatformEnabled = true }; + var view0 = MockPlatformSizeService.Sub(); view0.WidthRequest = 50; layout.Children.Add(view0); - var view1 = new View { IsPlatformEnabled = true }; + var view1 = MockPlatformSizeService.Sub(); view1.WidthRequest = 50; layout.Children.Add(view1); @@ -693,7 +666,7 @@ public void TestAlignContentStretchRowWithSingleRow() [Fact] public void TestAlignContentStretchRowWithFixedHeight() { - MockPlatformSizeService.Current.GetPlatformSizeFunc = (visual, width, height) => new SizeRequest(new Size(0, 0)); + static SizeRequest GetPlatformSize(VisualElement v, double w, double h) => new(new Size(0, 0)); var layout = new FlexLayout { @@ -705,24 +678,24 @@ public void TestAlignContentStretchRowWithFixedHeight() WidthRequest = 150, HeightRequest = 100 }; - var view0 = new View { IsPlatformEnabled = true }; + var view0 = MockPlatformSizeService.Sub(GetPlatformSize); view0.WidthRequest = 50; layout.Children.Add(view0); - var view1 = new View { IsPlatformEnabled = true }; + var view1 = MockPlatformSizeService.Sub(GetPlatformSize); view1.WidthRequest = 50; view1.HeightRequest = 60; layout.Children.Add(view1); - var view2 = new View { IsPlatformEnabled = true }; + var view2 = MockPlatformSizeService.Sub(GetPlatformSize); view2.WidthRequest = 50; layout.Children.Add(view2); - var view3 = new View { IsPlatformEnabled = true }; + var view3 = MockPlatformSizeService.Sub(GetPlatformSize); view3.WidthRequest = 50; layout.Children.Add(view3); - var view4 = new View { IsPlatformEnabled = true }; + var view4 = MockPlatformSizeService.Sub(GetPlatformSize); view4.WidthRequest = 50; layout.Children.Add(view4); diff --git a/src/Controls/tests/Core.UnitTests/FlexLayoutMarginTests.cs b/src/Controls/tests/Core.UnitTests/FlexLayoutMarginTests.cs index a10644457b5c..7ad5f49b3621 100644 --- a/src/Controls/tests/Core.UnitTests/FlexLayoutMarginTests.cs +++ b/src/Controls/tests/Core.UnitTests/FlexLayoutMarginTests.cs @@ -16,7 +16,7 @@ public class FlexLayoutMarginTests : BaseTestFixture [Fact] public void TestMarginLeft() { - var view0 = new View { IsPlatformEnabled = true, WidthRequest = 10, Margin = new Thickness(10, 0, 0, 0), }; + var view0 = MockPlatformSizeService.Sub(width: 10, margin: new(10, 0, 0, 0)); var layout = new FlexLayout { IsPlatformEnabled = true, @@ -34,7 +34,7 @@ public void TestMarginLeft() [Fact] public void TestMarginTop() { - var view0 = new View { IsPlatformEnabled = true, HeightRequest = 10, Margin = new Thickness(0, 10, 0, 0), }; + var view0 = MockPlatformSizeService.Sub(height: 10, margin: new(0, 10, 0, 0)); var layout = new FlexLayout { IsPlatformEnabled = true, @@ -53,7 +53,7 @@ public void TestMarginTop() [Fact] public void TestMarginRight() { - var view0 = new View { IsPlatformEnabled = true, WidthRequest = 10, Margin = new Thickness(0, 0, 10, 0), }; + var view0 = MockPlatformSizeService.Sub(width: 10, margin: new(0, 0, 10, 0)); var layout = new FlexLayout { IsPlatformEnabled = true, @@ -73,7 +73,7 @@ public void TestMarginRight() [Fact] public void TestMarginBottom() { - var view0 = new View { IsPlatformEnabled = true, HeightRequest = 10, Margin = new Thickness(0, 0, 0, 10), }; + var view0 = MockPlatformSizeService.Sub(height: 10, margin: new(0, 0, 0, 10)); var layout = new FlexLayout { IsPlatformEnabled = true, @@ -93,7 +93,7 @@ public void TestMarginBottom() [Fact] public void TestMarginAndFlexRow() { - var view0 = new View { IsPlatformEnabled = true, Margin = new Thickness(10, 0, 10, 0), }; + var view0 = MockPlatformSizeService.Sub(margin: new(10, 0, 10, 0)); FlexLayout.SetGrow(view0, 1); var layout = new FlexLayout { @@ -112,7 +112,7 @@ public void TestMarginAndFlexRow() [Fact] public void TestMarginAndFlexColumn() { - var view0 = new View { IsPlatformEnabled = true, Margin = new Thickness(0, 10, 0, 10), }; + var view0 = MockPlatformSizeService.Sub(margin: new(0, 10, 0, 10)); FlexLayout.SetGrow(view0, 1); var layout = new FlexLayout { @@ -131,7 +131,7 @@ public void TestMarginAndFlexColumn() [Fact] public void TestMarginAndStretchRow() { - var view0 = new View { IsPlatformEnabled = true, Margin = new Thickness(0, 10, 0, 10), }; + var view0 = MockPlatformSizeService.Sub(margin: new(0, 10, 0, 10)); FlexLayout.SetGrow(view0, 1); var layout = new FlexLayout { @@ -151,8 +151,7 @@ public void TestMarginAndStretchRow() [Fact] public void TestMarginAndStretchColumn() { - - var view0 = new View { IsPlatformEnabled = true, Margin = new Thickness(10, 0, 10, 0) }; + var view0 = MockPlatformSizeService.Sub(margin: new(10, 0, 10, 0)); FlexLayout.SetGrow(view0, 1); var layout = new FlexLayout { @@ -171,11 +170,11 @@ public void TestMarginAndStretchColumn() [Fact] public void TestMarginWithSiblingRow() { - MockPlatformSizeService.Current.GetPlatformSizeFunc = (visual, width, height) => new SizeRequest(new Size(0, 0)); + static SizeRequest GetSize(VisualElement _, double w, double h) => new(new(0, 0)); - var view0 = new View { IsPlatformEnabled = true, Margin = new Thickness(0, 0, 10, 0) }; + var view0 = MockPlatformSizeService.Sub(GetSize, margin: new(0, 0, 10, 0)); FlexLayout.SetGrow(view0, 1); - var view1 = new View { IsPlatformEnabled = true }; + var view1 = MockPlatformSizeService.Sub(GetSize); FlexLayout.SetGrow(view1, 1); var layout = new FlexLayout { @@ -197,9 +196,9 @@ public void TestMarginWithSiblingRow() [Fact] public void TestMarginWithSiblingColumn() { - var view0 = new View { IsPlatformEnabled = true, Margin = new Thickness(0, 0, 0, 10) }; + var view0 = MockPlatformSizeService.Sub(margin: new(0, 0, 0, 10)); FlexLayout.SetGrow(view0, 1); - var view1 = new View { IsPlatformEnabled = true }; + var view1 = MockPlatformSizeService.Sub(); FlexLayout.SetGrow(view1, 1); var layout = new FlexLayout diff --git a/src/Controls/tests/Core.UnitTests/FlexLayoutTests.cs b/src/Controls/tests/Core.UnitTests/FlexLayoutTests.cs index be2584e2750f..f832139a7647 100644 --- a/src/Controls/tests/Core.UnitTests/FlexLayoutTests.cs +++ b/src/Controls/tests/Core.UnitTests/FlexLayoutTests.cs @@ -16,8 +16,8 @@ public class FlexLayoutTests : BaseTestFixture [Fact] public void TestBasicLayout() { - var label1 = new Label { IsPlatformEnabled = true }; - var label2 = new Label { IsPlatformEnabled = true }; + var label1 = MockPlatformSizeService.Sub