Skip to content

Commit f011a58

Browse files
Ahamed-AliPureWeen
authored andcommitted
Fixed the SafeArea branch test case failures issues (#30622)
* Fixed the SafeArea test case issues and 22417(mac) main issue * Removed the Fails condition on Mac
1 parent 2ca0b07 commit f011a58

File tree

5 files changed

+25
-27
lines changed

5 files changed

+25
-27
lines changed

src/Controls/src/Core/Handlers/Items/CarouselViewHandler.iOS.cs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public static void MapIsBounceEnabled(CarouselViewHandler handler, CarouselView
4747

4848
public static void MapPeekAreaInsets(CarouselViewHandler handler, CarouselView carouselView)
4949
{
50+
(handler.Controller.Layout as CarouselViewLayout)?.UpdateConstraints(handler.PlatformView.Frame.Size);
5051
handler.Controller.Layout.InvalidateLayout();
5152
}
5253

@@ -72,34 +73,30 @@ public static void MapLoop(CarouselViewHandler handler, CarouselView carouselVie
7273

7374
public override Size GetDesiredSize(double widthConstraint, double heightConstraint)
7475
{
75-
// I'm not sure if this solution is fully correct or if it properly accounts
76-
// for all the constraints checks that GetDesiredSizeFromHandler takes into account
77-
if (Primitives.Dimension.IsExplicitSet(widthConstraint) && Primitives.Dimension.IsExplicitSet(heightConstraint))
76+
var size = this.GetDesiredSizeFromHandler(widthConstraint, heightConstraint);
77+
78+
if (OperatingSystem.IsMacCatalystVersionAtLeast(11))
7879
{
79-
// If both width and height are explicitly set, we can use the base implementation
80-
return base.GetDesiredSize(widthConstraint, heightConstraint);
81-
}
80+
// Ensure size never exceeds constraints.
81+
// In the 22417 test sample on Mac, if widthConstraint is 1085, it becomes 1512 after the SizeThatFits call
82+
// inside ViewHandlerExtensions.iOS. This causes the view's width to appear larger on Mac.
83+
// On iOS, the value remains correct — for example, if widthConstraint is 375, SizeThatFits also returns 375.
84+
// This issue happened on Main also.
8285

83-
var result = this.GetDesiredSizeFromHandler(widthConstraint, heightConstraint);
86+
if (!double.IsInfinity(widthConstraint) && size.Width > widthConstraint)
87+
{
88+
size.Width = (float)widthConstraint;
89+
}
90+
91+
if (!double.IsInfinity(heightConstraint) && size.Height > heightConstraint)
92+
{
93+
size.Height = (float)heightConstraint;
94+
}
8495

85-
if (Primitives.Dimension.IsExplicitSet(widthConstraint))
86-
{
87-
// If width is explicitly set, we can use the width from the result
88-
result = new Size(widthConstraint, result.Height);
89-
}
90-
else if (Primitives.Dimension.IsExplicitSet(heightConstraint))
91-
{
92-
// If height is explicitly set, we can use the height from the result
93-
result = new Size(result.Width, heightConstraint);
9496
}
9597

96-
return result;
97-
}
98+
return size;
9899

99-
public override void PlatformArrange(Rect rect)
100-
{
101-
(Controller.Layout as CarouselViewLayout)?.UpdateConstraints(rect.Size);
102-
base.PlatformArrange(rect);
103100
}
104101
}
105102
}

src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#nullable enable
22
override Microsoft.Maui.Controls.ContentPresenter.OnSizeAllocated(double width, double height) -> void
3-
override Microsoft.Maui.Controls.Handlers.Items.CarouselViewHandler.PlatformArrange(Microsoft.Maui.Graphics.Rect rect) -> void
43
override Microsoft.Maui.Controls.ScrollView.OnSizeAllocated(double width, double height) -> void
54
override Microsoft.Maui.Controls.TemplatedView.OnSizeAllocated(double width, double height) -> void
65
virtual Microsoft.Maui.Controls.BindableProperty.CreateDefaultValueDelegate<TDeclarer, TPropertyType>.Invoke(TDeclarer bindable) -> TPropertyType

src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#nullable enable
22
override Microsoft.Maui.Controls.ContentPresenter.OnSizeAllocated(double width, double height) -> void
3-
override Microsoft.Maui.Controls.Handlers.Items.CarouselViewHandler.PlatformArrange(Microsoft.Maui.Graphics.Rect rect) -> void
43
override Microsoft.Maui.Controls.ScrollView.OnSizeAllocated(double width, double height) -> void
54
override Microsoft.Maui.Controls.TemplatedView.OnSizeAllocated(double width, double height) -> void
65
virtual Microsoft.Maui.Controls.BindableProperty.CreateDefaultValueDelegate<TDeclarer, TPropertyType>.Invoke(TDeclarer bindable) -> TPropertyType

src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue22417.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if TEST_FAILS_ON_WINDOWS && TEST_FAILS_ON_CATALYST //This test is failing, likely due to product issue, for more information: https://github.com/dotnet/maui/issues/27059
1+
#if TEST_FAILS_ON_WINDOWS //This test is failing, likely due to product issue, for more information: https://github.com/dotnet/maui/issues/27059
22
using NUnit.Framework;
33
using UITest.Appium;
44
using UITest.Core;

src/Core/src/Platform/iOS/MauiView.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public abstract class MauiView : UIView, ICrossPlatformLayoutBacking, IVisualTre
1919
SafeAreaPadding _safeArea = SafeAreaPadding.Empty;
2020
bool _safeAreaInvalidated = true;
2121
bool _appliesSafeAreaAdjustments;
22-
22+
2323

2424
WeakReference<IView>? _reference;
2525
WeakReference<ICrossPlatformLayout>? _crossPlatformLayoutReference;
@@ -163,6 +163,9 @@ public override void LayoutSubviews()
163163
// to let ancestors adjust to the measured size.
164164
if (this.IsFinalMeasureHandledBySuperView())
165165
{
166+
//This arrangement step is essential for communicating the correct coordinate space to native iOS views before scheduling the second layout pass.
167+
//This ensures the native view is aware of the correct bounds and can adjust its layout accordingly.
168+
CrossPlatformArrange(Bounds.ToRectangle());
166169
SetNeedsLayout();
167170
this.InvalidateAncestorsMeasures();
168171
return;
@@ -215,7 +218,7 @@ bool ValidateSafeArea()
215218

216219
// Return whether the way safe area interacts with our view has changed
217220
return oldApplyingSafeAreaAdjustments == _appliesSafeAreaAdjustments &&
218-
(oldSafeArea == _safeArea || !_appliesSafeAreaAdjustments);
221+
(oldSafeArea == _safeArea || !_appliesSafeAreaAdjustments);
219222
}
220223

221224
IVisualTreeElement? IVisualTreeElementProvidable.GetElement()

0 commit comments

Comments
 (0)