Skip to content

Commit

Permalink
Revert "Fix SafeArea adjustments (#23729)"
Browse files Browse the repository at this point in the history
This reverts commit 14b29b0.
  • Loading branch information
PureWeen authored Sep 4, 2024
1 parent 5c0e6d6 commit 7b62235
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<RuntimeIdentifier Condition="$(TargetFramework.Contains('-maccatalyst'))">maccatalyst-x64</RuntimeIdentifier>
<RuntimeIdentifier Condition="$(TargetFramework.Contains('-maccatalyst')) and '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'arm64'">maccatalyst-arm64</RuntimeIdentifier>
<ExcludeMicrosoftNetTestSdk>true</ExcludeMicrosoftNetTestSdk>
<RootNamespace>Maui.Controls.Sample</RootNamespace>
</PropertyGroup>

<PropertyGroup>
Expand Down
11 changes: 0 additions & 11 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue24246.xaml

This file was deleted.

11 changes: 0 additions & 11 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue24246.xaml.cs

This file was deleted.

This file was deleted.

34 changes: 1 addition & 33 deletions src/Core/src/Platform/iOS/MauiView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,17 @@ public IView? View

bool RespondsToSafeArea()
{
if (View is not ISafeAreaView sav || sav.IgnoreSafeArea)
{
return false;
}

if (_respondsToSafeArea.HasValue)
return _respondsToSafeArea.Value;

return (bool)(_respondsToSafeArea = RespondsToSelector(new Selector("safeAreaInsets")));

}

protected CGRect AdjustForSafeArea(CGRect bounds)
{
if (KeyboardAutoManagerScroll.ShouldIgnoreSafeAreaAdjustment)
KeyboardAutoManagerScroll.ShouldScrollAgain = true;

if (!RespondsToSafeArea())
if (View is not ISafeAreaView sav || sav.IgnoreSafeArea || !RespondsToSafeArea())
{
return bounds;
}
Expand Down Expand Up @@ -95,12 +88,6 @@ Size CrossPlatformArrange(Rect bounds)
return CrossPlatformLayout?.CrossPlatformArrange(bounds) ?? Size.Zero;
}

// SizeThatFits does not take into account the constraints set on the view.
// For example, if the user has set a width and height on this view, those constraints
// will not be reflected in the value returned from this method. This method purely returns
// a measure based on the size that is passed in.
// The constraints are all applied by ViewHandlerExtensions.GetDesiredSizeFromHandler
// after it calls this method.
public override CGSize SizeThatFits(CGSize size)
{
if (_crossPlatformLayoutReference == null)
Expand All @@ -115,25 +102,6 @@ public override CGSize SizeThatFits(CGSize size)

CacheMeasureConstraints(widthConstraint, heightConstraint);

// If for some reason the upstream measure passes in a negative contraint
// Lets just bypass this code
if (RespondsToSafeArea() && widthConstraint >= 0 && heightConstraint >= 0)
{
// During the LayoutSubViews pass, we adjust the Bounds of this view for the safe area and then pass the adjusted result to CrossPlatformArrange.
// The CrossPlatformMeasure call does not include the safe area, so we need to add it here to ensure the returned size is correct.
//
// For example, if this is a layout with an Entry of height 20, CrossPlatformMeasure will return a height of 20.
// This means the bounds will be set to a height of 20, causing AdjustForSafeArea(Bounds) to return a negative bounds once it has
// subtracted the safe area insets. Therefore, we need to add the safe area insets to the CrossPlatformMeasure result to ensure correct arrangement.
var widthSafeAreaOffset = SafeAreaInsets.Left + SafeAreaInsets.Right;
var heightSafeAreaOffset = SafeAreaInsets.Top + SafeAreaInsets.Bottom;

var width = double.Clamp(crossPlatformSize.Width + widthSafeAreaOffset, 0, widthConstraint);
var height = double.Clamp(crossPlatformSize.Height + heightSafeAreaOffset, 0, heightConstraint);

return new CGSize(width, height);
}

return crossPlatformSize.ToCGSize();
}

Expand Down

0 comments on commit 7b62235

Please sign in to comment.