From 1108b8887503570412189b643f6a3c02b9ff6a68 Mon Sep 17 00:00:00 2001 From: Subhiksha Chandrasekaran Date: Thu, 11 Jun 2026 10:47:03 +0530 Subject: [PATCH] [Revert] Fix iOS ProgressBar bounding box --- .../ProgressBar/ProgressBarHandler.iOS.cs | 5 +- src/Core/src/Platform/iOS/MauiProgressView.cs | 128 ------------------ .../PublicAPI/net-ios/PublicAPI.Unshipped.txt | 1 - .../net-maccatalyst/PublicAPI.Unshipped.txt | 1 - .../HandlerTests/HandlerTestBaseOfT.Tests.cs | 9 +- .../ProgressBarHandlerTests.iOS.cs | 19 --- 6 files changed, 6 insertions(+), 157 deletions(-) delete mode 100644 src/Core/src/Platform/iOS/MauiProgressView.cs diff --git a/src/Core/src/Handlers/ProgressBar/ProgressBarHandler.iOS.cs b/src/Core/src/Handlers/ProgressBar/ProgressBarHandler.iOS.cs index 95518cb96734..4f15afc6ffde 100644 --- a/src/Core/src/Handlers/ProgressBar/ProgressBarHandler.iOS.cs +++ b/src/Core/src/Handlers/ProgressBar/ProgressBarHandler.iOS.cs @@ -1,5 +1,4 @@ using System; -using Microsoft.Maui.Platform; using ObjCRuntime; using UIKit; @@ -7,11 +6,9 @@ namespace Microsoft.Maui.Handlers { public partial class ProgressBarHandler : ViewHandler { - public override bool NeedsContainer => true; - protected override UIProgressView CreatePlatformView() { - return new MauiProgressView(UIProgressViewStyle.Default); + return new UIProgressView(UIProgressViewStyle.Default); } public static void MapProgress(IProgressBarHandler handler, IProgress progress) diff --git a/src/Core/src/Platform/iOS/MauiProgressView.cs b/src/Core/src/Platform/iOS/MauiProgressView.cs deleted file mode 100644 index afab3d696712..000000000000 --- a/src/Core/src/Platform/iOS/MauiProgressView.cs +++ /dev/null @@ -1,128 +0,0 @@ -using System; -using CoreGraphics; -using UIKit; - -namespace Microsoft.Maui.Platform -{ - internal sealed class MauiProgressView : UIProgressView - { - nfloat _arrangedHeight; - bool _isLayingOutSubviews; - - public MauiProgressView(UIProgressViewStyle style) - : base(style) - { - } - - public override CGRect Frame - { - get => base.Frame; - set - { - if (_isLayingOutSubviews) - { - base.Frame = value; - return; - } - - LayoutToFrame(value); - } - } - - public override CGRect Bounds - { - get => base.Bounds; - set - { - if (_isLayingOutSubviews) - { - base.Bounds = value; - return; - } - - LayoutToBounds(value, Center); - } - } - - public override void LayoutSubviews() - { - var arrangedHeight = _arrangedHeight; - - Transform = CGAffineTransform.MakeIdentity(); - - _isLayingOutSubviews = true; - try - { - base.LayoutSubviews(); - } - finally - { - _isLayingOutSubviews = false; - _arrangedHeight = arrangedHeight; - } - - ApplyVerticalScale(); - } - - void LayoutToFrame(CGRect frame) - { - LayoutToBounds(new CGRect(0, 0, frame.Width, frame.Height), new CGPoint(frame.GetMidX(), frame.GetMidY())); - } - - void LayoutToBounds(CGRect bounds, CGPoint center) - { - Transform = CGAffineTransform.MakeIdentity(); - - var targetWidth = bounds.Width < 0 ? 0 : bounds.Width; - _arrangedHeight = bounds.Height < 0 ? 0 : bounds.Height; - var naturalHeight = GetNaturalHeight(new CGSize(targetWidth, _arrangedHeight)); - - if (!IsPositiveFinite(naturalHeight) || !IsPositiveFinite(_arrangedHeight)) - { - base.Bounds = new CGRect(bounds.X, bounds.Y, targetWidth, 0); - base.Center = center; - return; - } - - base.Bounds = new CGRect(bounds.X, bounds.Y, targetWidth, naturalHeight); - base.Center = center; - ApplyVerticalScale(); - } - - void ApplyVerticalScale() - { - var naturalHeight = base.Bounds.Height; - - if (!IsPositiveFinite(naturalHeight) || !IsPositiveFinite(_arrangedHeight)) - { - Transform = CGAffineTransform.MakeIdentity(); - return; - } - - Transform = CGAffineTransform.MakeScale(1, _arrangedHeight / naturalHeight); - } - - nfloat GetNaturalHeight(CGSize size) - { - var naturalHeight = SizeThatFits(size).Height; - - if (!IsPositiveFinite(naturalHeight)) - { - naturalHeight = IntrinsicContentSize.Height; - } - - if (!IsPositiveFinite(naturalHeight)) - { - naturalHeight = base.Bounds.Height; - } - - return naturalHeight; - } - - static bool IsPositiveFinite(nfloat value) - { - var doubleValue = (double)value; - return doubleValue > 0 && !double.IsNaN(doubleValue) && !double.IsInfinity(doubleValue); - } - } -} diff --git a/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt b/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt index 4bb0baed4f75..e7f9aa0efff8 100644 --- a/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt +++ b/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt @@ -1,6 +1,5 @@ #nullable enable override Microsoft.Maui.Handlers.LabelHandler.GetDesiredSize(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size -override Microsoft.Maui.Handlers.ProgressBarHandler.NeedsContainer.get -> bool override Microsoft.Maui.Handlers.ShapeViewHandler.GetDesiredSize(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size override Microsoft.Maui.Handlers.StepperHandler.GetDesiredSize(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size override Microsoft.Maui.MauiUIApplicationDelegate.ValidateCommand(UIKit.UICommand! command) -> void diff --git a/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt b/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt index a3bff64e206c..263c596c2ca3 100644 --- a/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt +++ b/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt @@ -1,6 +1,5 @@ #nullable enable override Microsoft.Maui.Handlers.LabelHandler.GetDesiredSize(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size -override Microsoft.Maui.Handlers.ProgressBarHandler.NeedsContainer.get -> bool override Microsoft.Maui.Handlers.ShapeViewHandler.GetDesiredSize(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size override Microsoft.Maui.Handlers.StepperHandler.GetDesiredSize(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size override Microsoft.Maui.MauiUIApplicationDelegate.ValidateCommand(UIKit.UICommand! command) -> void diff --git a/src/Core/tests/DeviceTests.Shared/HandlerTests/HandlerTestBaseOfT.Tests.cs b/src/Core/tests/DeviceTests.Shared/HandlerTests/HandlerTestBaseOfT.Tests.cs index 21ea764e24c7..dd31953997f8 100644 --- a/src/Core/tests/DeviceTests.Shared/HandlerTests/HandlerTestBaseOfT.Tests.cs +++ b/src/Core/tests/DeviceTests.Shared/HandlerTests/HandlerTestBaseOfT.Tests.cs @@ -306,10 +306,12 @@ public virtual async Task ReturnsNonEmptyNativeBoundingBox(int size) var nativeBoundingBox = await GetValueAsync(view, handler => GetBoundingBox(handler)); Assert.NotEqual(nativeBoundingBox, Graphics.Rect.Zero); + // Currently there's an issue with label/progress where they don't set the frame size to + // the explicit Width and Height values set + // https://github.com/dotnet/maui/issues/7935 if (view is ILabel) { - var expectedSize = new Size(size, size); - AssertWithinTolerance(expectedSize, nativeBoundingBox.Size); + // TODO: } else if (view is IBorderView) { @@ -336,8 +338,7 @@ public virtual async Task ReturnsNonEmptyNativeBoundingBox(int size) #endif else if (view is IProgress) { - var expectedSize = new Size(size, size); - AssertWithinTolerance(expectedSize, nativeBoundingBox.Size); + AssertWithinTolerance(size, nativeBoundingBox.Size.Width); } else { diff --git a/src/Core/tests/DeviceTests/Handlers/ProgressBar/ProgressBarHandlerTests.iOS.cs b/src/Core/tests/DeviceTests/Handlers/ProgressBar/ProgressBarHandlerTests.iOS.cs index 42b6b445123a..7d463cf859f6 100644 --- a/src/Core/tests/DeviceTests/Handlers/ProgressBar/ProgressBarHandlerTests.iOS.cs +++ b/src/Core/tests/DeviceTests/Handlers/ProgressBar/ProgressBarHandlerTests.iOS.cs @@ -1,6 +1,5 @@ using System; using System.Threading.Tasks; -using Microsoft.Maui.DeviceTests.Stubs; using Microsoft.Maui.Graphics; using Microsoft.Maui.Handlers; using ObjCRuntime; @@ -17,24 +16,6 @@ UIProgressView GetNativeProgressBar(ProgressBarHandler progressBarHandler) => double GetNativeProgress(ProgressBarHandler progressBarHandler) => GetNativeProgressBar(progressBarHandler).Progress; - [Theory(DisplayName = "Native ProgressBar Bounding Box Honors Explicit Size")] - [InlineData(1)] - [InlineData(100)] - [InlineData(1000)] - public async Task NativeProgressBarBoundingBoxHonorsExplicitSize(int size) - { - var progressBar = new ProgressBarStub - { - Height = size, - Width = size, - Progress = 0.5, - }; - - var nativeBoundingBox = await GetValueAsync(progressBar, handler => GetNativeProgressBar(handler).GetBoundingBox()); - - AssertWithinTolerance(new Size(size, size), nativeBoundingBox.Size); - } - async Task ValidateNativeProgressColor(IProgress progressBar, Color color, Action action = null) { var expected = await GetValueAsync(progressBar, handler =>