diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/BoxViewInAbsoluteLayoutReturnsToDefaultAutoSize.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/BoxViewInAbsoluteLayoutReturnsToDefaultAutoSize.png new file mode 100644 index 000000000000..e5c579f38df2 Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/BoxViewInAbsoluteLayoutReturnsToDefaultAutoSize.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue31496.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue31496.cs new file mode 100644 index 000000000000..252a675afa0f --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue31496.cs @@ -0,0 +1,68 @@ +using Microsoft.Maui.Layouts; + +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 31496, "BoxView in AbsoluteLayout does not return to default AutoSize", PlatformAffected.iOS | PlatformAffected.macOS)] +public class Issue31496 : ContentPage +{ + AbsoluteLayout absoluteLayout; + BoxView boxView; + readonly Rect defaultBounds = new Rect(0, 0, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize); + + public Issue31496() + { + absoluteLayout = new AbsoluteLayout + { + BackgroundColor = Colors.LightGray + }; + + var label = new Label + { + Text = "The test passes if a BoxView is not visible in view.", + }; + AbsoluteLayout.SetLayoutBounds(label, new Rect(0.5, 0.80, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize)); + AbsoluteLayout.SetLayoutFlags(label, AbsoluteLayoutFlags.PositionProportional); + + boxView = new BoxView + { + Color = Colors.Green + }; + AbsoluteLayout.SetLayoutBounds(boxView, new Rect(0, 0, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize)); + AbsoluteLayout.SetLayoutFlags(boxView, AbsoluteLayoutFlags.None); + + var changeBoundsButton = new Button + { + Text = "Change Bounds", + AutomationId = "Issue31496ChangeBoundsButton" + }; + AbsoluteLayout.SetLayoutBounds(changeBoundsButton, new Rect(0.5, 0.90, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize)); + AbsoluteLayout.SetLayoutFlags(changeBoundsButton, AbsoluteLayoutFlags.PositionProportional); + changeBoundsButton.Clicked += OnChangeBoundsClicked; + + var resetBoundsButton = new Button + { + Text = "Reset Bounds", + AutomationId = "Issue31496ResetButton" + }; + AbsoluteLayout.SetLayoutBounds(resetBoundsButton, new Rect(0.5, 0.99, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize)); + AbsoluteLayout.SetLayoutFlags(resetBoundsButton, AbsoluteLayoutFlags.PositionProportional); + resetBoundsButton.Clicked += OnResetBoundsClicked; + + absoluteLayout.Children.Add(boxView); + absoluteLayout.Children.Add(label); + absoluteLayout.Children.Add(changeBoundsButton); + absoluteLayout.Children.Add(resetBoundsButton); + + Content = absoluteLayout; + } + + void OnChangeBoundsClicked(object sender, EventArgs e) + { + AbsoluteLayout.SetLayoutBounds(boxView, new Rect(50, 50, 100, 100)); + } + + void OnResetBoundsClicked(object sender, EventArgs e) + { + AbsoluteLayout.SetLayoutBounds(boxView, defaultBounds); + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/BoxViewInAbsoluteLayoutReturnsToDefaultAutoSize.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/BoxViewInAbsoluteLayoutReturnsToDefaultAutoSize.png new file mode 100644 index 000000000000..772fa518c415 Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/BoxViewInAbsoluteLayoutReturnsToDefaultAutoSize.png differ diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue31496.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue31496.cs new file mode 100644 index 000000000000..d777d869ec92 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue31496.cs @@ -0,0 +1,25 @@ +using System; +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue31496 : _IssuesUITest +{ + public Issue31496(TestDevice testDevice) : base(testDevice) + { + } + public override string Issue => "BoxView in AbsoluteLayout does not return to default AutoSize"; + + [Test] + [Category(UITestCategories.Layout)] + public void BoxViewInAbsoluteLayoutReturnsToDefaultAutoSize() + { + App.WaitForElement("Issue31496ChangeBoundsButton"); + App.Tap("Issue31496ChangeBoundsButton"); + App.WaitForElement("Issue31496ResetButton"); + App.Tap("Issue31496ResetButton"); + VerifyScreenshot(); + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/BoxViewInAbsoluteLayoutReturnsToDefaultAutoSize.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/BoxViewInAbsoluteLayoutReturnsToDefaultAutoSize.png new file mode 100644 index 000000000000..1482ca585f86 Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/BoxViewInAbsoluteLayoutReturnsToDefaultAutoSize.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/BoxViewInAbsoluteLayoutReturnsToDefaultAutoSize.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/BoxViewInAbsoluteLayoutReturnsToDefaultAutoSize.png new file mode 100644 index 000000000000..68e2aa97f57c Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/BoxViewInAbsoluteLayoutReturnsToDefaultAutoSize.png differ diff --git a/src/Core/src/Handlers/ShapeView/ShapeViewHandler.iOS.cs b/src/Core/src/Handlers/ShapeView/ShapeViewHandler.iOS.cs index 5059b937e484..7b9b56296373 100644 --- a/src/Core/src/Handlers/ShapeView/ShapeViewHandler.iOS.cs +++ b/src/Core/src/Handlers/ShapeView/ShapeViewHandler.iOS.cs @@ -60,5 +60,22 @@ public static void MapStrokeMiterLimit(IShapeViewHandler handler, IShapeView sha { handler.PlatformView?.InvalidateShape(shapeView); } + + public override Size GetDesiredSize(double widthConstraint, double heightConstraint) + { + var result = base.GetDesiredSize(widthConstraint, heightConstraint); + + if (double.IsNaN(VirtualView.Width)) + { + result.Width = 0; + } + + if (double.IsNaN(VirtualView.Height)) + { + result.Height = 0; + } + + return result; + } } } \ No newline at end of file diff --git a/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt b/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt index 7869f46fee56..455d0b46cdb7 100644 --- a/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt +++ b/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt @@ -157,3 +157,4 @@ virtual Microsoft.Maui.SwipeViewSwipeStarted.$() -> Microsoft.Maui.SwipeV virtual Microsoft.Maui.SwipeViewSwipeStarted.EqualityContract.get -> System.Type! virtual Microsoft.Maui.SwipeViewSwipeStarted.Equals(Microsoft.Maui.SwipeViewSwipeStarted? other) -> bool virtual Microsoft.Maui.SwipeViewSwipeStarted.PrintMembers(System.Text.StringBuilder! builder) -> bool +override Microsoft.Maui.Handlers.ShapeViewHandler.GetDesiredSize(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size \ No newline at end of file diff --git a/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt b/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt index 7869f46fee56..455d0b46cdb7 100644 --- a/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt +++ b/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt @@ -157,3 +157,4 @@ virtual Microsoft.Maui.SwipeViewSwipeStarted.$() -> Microsoft.Maui.SwipeV virtual Microsoft.Maui.SwipeViewSwipeStarted.EqualityContract.get -> System.Type! virtual Microsoft.Maui.SwipeViewSwipeStarted.Equals(Microsoft.Maui.SwipeViewSwipeStarted? other) -> bool virtual Microsoft.Maui.SwipeViewSwipeStarted.PrintMembers(System.Text.StringBuilder! builder) -> bool +override Microsoft.Maui.Handlers.ShapeViewHandler.GetDesiredSize(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size \ No newline at end of file