Skip to content

Commit f43e5cc

Browse files
praveenkumarkarunanithiPureWeenAhamed-Ali
authored
Fix for SafeArea management on iOS Failing test case - LabelShouldSizeProperlyOnCollectionView (#30682)
* Fix SafeArea management on iOS * 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 * Enhance CrossPlatformArrange method to support safe area adjustments and improve RTL layout handling * - add images and fix naming * - additional image updates * - add comments * fix update. --------- Co-authored-by: Shane Neuville <[email protected]> Co-authored-by: Ahamed-Ali <[email protected]>
1 parent 570efb0 commit f43e5cc

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/Core/src/Platform/iOS/SafeAreaPadding.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using CoreGraphics;
22
using UIKit;
3+
using System;
34

45
namespace Microsoft.Maui.Platform;
56

@@ -28,6 +29,18 @@ public CGRect InsetRect(CGRect bounds)
2829

2930
internal static class SafeAreaInsetsExtensions
3031
{
31-
public static SafeAreaPadding ToSafeAreaInsets(this UIEdgeInsets insets) =>
32-
new(insets.Left, insets.Right, insets.Top, insets.Bottom);
32+
public static SafeAreaPadding ToSafeAreaInsets(this UIEdgeInsets insets)
33+
{
34+
// Filters out negligible floating-point values from UIKit that may cause layout issues (e.g., 3.5527136788005009e-15).
35+
const double tolerance = 1e-14;
36+
37+
static double ApplyTolerance(double value) => Math.Abs(value) < tolerance ? 0 : value;
38+
39+
return new(
40+
ApplyTolerance(insets.Left),
41+
ApplyTolerance(insets.Right),
42+
ApplyTolerance(insets.Top),
43+
ApplyTolerance(insets.Bottom)
44+
);
45+
}
3346
}

0 commit comments

Comments
 (0)