From 7b62235e0edf8be719afc78e1d95b644ccc43b37 Mon Sep 17 00:00:00 2001 From: Shane Neuville Date: Wed, 4 Sep 2024 15:37:11 -0500 Subject: [PATCH] Revert "Fix SafeArea adjustments (#23729)" This reverts commit 14b29b04afaf121281cde1325ba5673556dd6c80. --- .../Controls.TestCases.HostApp.csproj | 1 - .../TestCases.HostApp/Issues/Issue24246.xaml | 11 ------ .../Issues/Issue24246.xaml.cs | 11 ------ .../Tests/Issues/Issue24246.cs | 26 -------------- src/Core/src/Platform/iOS/MauiView.cs | 34 +------------------ 5 files changed, 1 insertion(+), 82 deletions(-) delete mode 100644 src/Controls/tests/TestCases.HostApp/Issues/Issue24246.xaml delete mode 100644 src/Controls/tests/TestCases.HostApp/Issues/Issue24246.xaml.cs delete mode 100644 src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24246.cs diff --git a/src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj b/src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj index 20c0851af1e5..91157419d2ca 100644 --- a/src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj +++ b/src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj @@ -10,7 +10,6 @@ maccatalyst-x64 maccatalyst-arm64 true - Maui.Controls.Sample diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue24246.xaml b/src/Controls/tests/TestCases.HostApp/Issues/Issue24246.xaml deleted file mode 100644 index 400553f8c34b..000000000000 --- a/src/Controls/tests/TestCases.HostApp/Issues/Issue24246.xaml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue24246.xaml.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue24246.xaml.cs deleted file mode 100644 index 6a2fa194133a..000000000000 --- a/src/Controls/tests/TestCases.HostApp/Issues/Issue24246.xaml.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Maui.Controls.Sample.Issues; - - -[Issue(IssueTracker.Github, 24246, "SafeArea arrange insets are currently insetting based on an incorrect Bounds", PlatformAffected.iOS)] -public partial class Issue24246 : ContentPage -{ - public Issue24246() - { - InitializeComponent(); - } -} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24246.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24246.cs deleted file mode 100644 index d23493671acd..000000000000 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24246.cs +++ /dev/null @@ -1,26 +0,0 @@ -using NUnit.Framework; -using UITest.Appium; -using UITest.Core; - -namespace Microsoft.Maui.TestCases.Tests.Issues -{ - public class Issue24246 : _IssuesUITest - { - public Issue24246(TestDevice testDevice) : base(testDevice) - { - } - - public override string Issue => "SafeArea arrange insets are currently insetting based on an incorrect Bounds"; - - [Test] - [Category(UITestCategories.Layout)] - public void TapThenDoubleTap() - { - App.WaitForElement("entry"); - App.EnterText("entry", "Hello, World!"); - - var result = App.WaitForElement("entry").GetText(); - Assert.That(result, Is.EqualTo("Hello, World!")); - } - } -} \ No newline at end of file diff --git a/src/Core/src/Platform/iOS/MauiView.cs b/src/Core/src/Platform/iOS/MauiView.cs index 347a9b5caf49..c3e0db4349fa 100644 --- a/src/Core/src/Platform/iOS/MauiView.cs +++ b/src/Core/src/Platform/iOS/MauiView.cs @@ -25,16 +25,9 @@ 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) @@ -42,7 +35,7 @@ protected CGRect AdjustForSafeArea(CGRect bounds) if (KeyboardAutoManagerScroll.ShouldIgnoreSafeAreaAdjustment) KeyboardAutoManagerScroll.ShouldScrollAgain = true; - if (!RespondsToSafeArea()) + if (View is not ISafeAreaView sav || sav.IgnoreSafeArea || !RespondsToSafeArea()) { return bounds; } @@ -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) @@ -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(); }