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

Stop using IPlatformSizeService #23725

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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

This file was deleted.

21 changes: 0 additions & 21 deletions src/Controls/src/Core/Compatibility/Tizen/PlatformSizeService.cs

This file was deleted.

This file was deleted.

21 changes: 0 additions & 21 deletions src/Controls/src/Core/Compatibility/iOS/PlatformSizeService.cs

This file was deleted.

4 changes: 3 additions & 1 deletion src/Controls/src/Core/IPlatformSizeService.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
12 changes: 3 additions & 9 deletions src/Controls/src/Core/IndicatorView/IndicatorView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IPlatformSizeService>();
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)
Expand Down
8 changes: 1 addition & 7 deletions src/Controls/src/Core/RadioButton/RadioButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IPlatformSizeService>();
return _platformSizeService.GetPlatformSize(this, widthConstraint, heightConstraint);
return Handler?.GetDesiredSize(widthConstraint, heightConstraint) ?? new();
}

return base.OnMeasure(widthConstraint, heightConstraint);
Expand Down
8 changes: 1 addition & 7 deletions src/Controls/src/Core/VisualElement/VisualElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1281,8 +1281,6 @@ protected override void OnChildRemoved(Element child, int oldLogicalIndex)
protected void OnChildrenReordered()
=> ChildrenReordered?.Invoke(this, EventArgs.Empty);

IPlatformSizeService _platformSizeService;

/// <summary>
/// Method that is called when a layout measurement happens.
/// </summary>
Expand All @@ -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<IPlatformSizeService>();
return _platformSizeService.GetPlatformSize(this, widthConstraint, heightConstraint);
return Handler?.GetDesiredSize(widthConstraint, heightConstraint) ?? new();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ static MauiAppBuilder SetupDefaults(this MauiAppBuilder builder)
// initialize compatibility DependencyService
DependencyService.SetToInitialized();
DependencyService.Register<Xaml.ValueConverterProvider>();
DependencyService.Register<PlatformSizeService>();

#pragma warning disable CS0612, CA1416 // Type or member is obsolete, 'ResourcesProvider' is unsupported on: 'iOS' 14.0 and later
DependencyService.Register<ResourcesProvider>();
Expand Down
36 changes: 10 additions & 26 deletions src/Controls/tests/Core.UnitTests/AbsoluteLayoutTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void AbsolutePositionAndSizeUsingRectangle()
IsPlatformEnabled = true
};

var child = new View { IsPlatformEnabled = true };
var child = MockPlatformSizeService.Sub<View>();

abs.Children.Add(child, new Rect(10, 20, 30, 40));

Expand All @@ -56,8 +56,7 @@ public void AbsolutePositionRelativeSize()
IsPlatformEnabled = true
};

var child = new View { IsPlatformEnabled = true };

var child = MockPlatformSizeService.Sub<View>();

abs.Children.Add(child, new Rect(10, 20, 0.4, 0.5), AbsoluteLayoutFlags.SizeProportional);

Expand All @@ -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<View>();

abs.Children.Add(child, new Rect(relX, relY, width, height), AbsoluteLayoutFlags.PositionProportional);

Expand Down Expand Up @@ -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<View>();
abs.Children.Add(child, new Rect(relX, relY, relWidth, relHeight), AbsoluteLayoutFlags.All);
abs.Layout(new Rect(0, 0, 100, 100));

Expand All @@ -135,7 +131,7 @@ public void SizeRequestWithNormalChild()
IsPlatformEnabled = true
};

var child = new View();
var child = MockPlatformSizeService.Sub<View>();

// ChildSizeReq == 100x20
abs.Children.Add(child, new Rect(10, 20, 30, 40));
Expand All @@ -154,7 +150,7 @@ public void SizeRequestWithRelativePositionChild()
IsPlatformEnabled = true
};

var child = new View();
var child = MockPlatformSizeService.Sub<View>();

// ChildSizeReq == 100x20
abs.Children.Add(child, new Rect(0.5, 0.5, 30, 40), AbsoluteLayoutFlags.PositionProportional);
Expand All @@ -173,10 +169,7 @@ public void SizeRequestWithRelativeChild()
IsPlatformEnabled = true
};

var child = new View
{
IsPlatformEnabled = true
};
var child = MockPlatformSizeService.Sub<View>();

// ChildSizeReq == 100x20
abs.Children.Add(child, new Rect(0.5, 0.5, 0.5, 0.5), AbsoluteLayoutFlags.All);
Expand All @@ -195,10 +188,7 @@ public void SizeRequestWithRelativeSizeChild()
IsPlatformEnabled = true
};

var child = new View
{
IsPlatformEnabled = true
};
var child = MockPlatformSizeService.Sub<View>();

// ChildSizeReq == 100x20
abs.Children.Add(child, new Rect(10, 20, 0.5, 0.5), AbsoluteLayoutFlags.SizeProportional);
Expand All @@ -217,10 +207,7 @@ public void MeasureInvalidatedFiresWhenFlagsChanged()
IsPlatformEnabled = true
};

var child = new View
{
IsPlatformEnabled = true
};
var child = MockPlatformSizeService.Sub<View>();

abs.Children.Add(child, new Rect(1, 1, 100, 100));

Expand All @@ -240,10 +227,7 @@ public void MeasureInvalidatedFiresWhenBoundsChanged()
IsPlatformEnabled = true
};

var child = new View
{
IsPlatformEnabled = true
};
var child = MockPlatformSizeService.Sub<View>();

abs.Children.Add(child, new Rect(1, 1, 100, 100));

Expand Down
2 changes: 0 additions & 2 deletions src/Controls/tests/Core.UnitTests/BaseTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -53,7 +52,6 @@ protected virtual void Dispose(bool disposing)

if (disposing)
{
MockPlatformSizeService.Current?.Reset();
AppInfo.SetCurrent(null);
DeviceDisplay.SetCurrent(null);
DeviceInfo.SetCurrent(null);
Expand Down
Loading
Loading