diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/Bugzilla44461Test.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/Bugzilla44461Test.png new file mode 100644 index 000000000000..aef61d1793a7 Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/Bugzilla44461Test.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Bugzilla/Bugzilla44461.cs b/src/Controls/tests/TestCases.HostApp/Issues/Bugzilla/Bugzilla44461.cs index b067013f8406..0ad9d3f24f0e 100644 --- a/src/Controls/tests/TestCases.HostApp/Issues/Bugzilla/Bugzilla44461.cs +++ b/src/Controls/tests/TestCases.HostApp/Issues/Bugzilla/Bugzilla44461.cs @@ -7,10 +7,8 @@ public class Bugzilla44461 : ContentPage public Bugzilla44461() { - var grid = new Grid - { - RowSpacing = 0, - }; + var stackLayout = new StackLayout(); + var instructions = new Label { @@ -18,7 +16,7 @@ public Bugzilla44461() + "and should not move. If it's not, the test failed." }; - grid.Children.Add(instructions); + stackLayout.Add(instructions); var scrollView = new ScrollView { @@ -27,9 +25,19 @@ public Bugzilla44461() BackgroundColor = Colors.Yellow, HeightRequest = 50 }; - grid.Children.Add(scrollView); - var stackLayout = new StackLayout + + var scrollButton = new Button + { + Text = "Scroll to Button0", + AutomationId = "Scroll to Button0", + Margin = 10, + }; + + stackLayout.Add(scrollButton); + stackLayout.Add(scrollView); + + var horizontalStack = new StackLayout { Orientation = StackOrientation.Horizontal, Spacing = 20 @@ -47,10 +55,16 @@ public Bugzilla44461() scrollView.ScrollToAsync(sender as Button, ScrollToPosition.Center, true); }; - stackLayout.Children.Add(button); + horizontalStack.Children.Add(button); } - scrollView.Content = stackLayout; - Content = grid; + + scrollButton.Clicked += (sender, args) => + { + var button = horizontalStack.Children[0]; + scrollView.ScrollToAsync(button as Element, ScrollToPosition.Center, true); + }; + scrollView.Content = horizontalStack; + Content = stackLayout; } } -} +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/Bugzilla44461Test.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/Bugzilla44461Test.png new file mode 100644 index 000000000000..1016ec90dc91 Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/Bugzilla44461Test.png differ diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/ScrollToElement3End.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/ScrollToElement3End.png index ed581f0629e8..55ec25aa06a9 100644 Binary files a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/ScrollToElement3End.png and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/ScrollToElement3End.png differ diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla44461.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla44461.cs index 7f6457b41167..a0a47a6d0923 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla44461.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla44461.cs @@ -1,6 +1,4 @@ -#if TEST_FAILS_ON_IOS && TEST_FAILS_ON_CATALYST //When clicking Button0 (the first button) incorrectly centers it in the ScrollView instead of maintaining its left alignment. -//Issue Link: https://github.com/dotnet/maui/issues/26760 -using NUnit.Framework; +using NUnit.Framework; using NUnit.Framework.Legacy; using UITest.Appium; using UITest.Core; @@ -18,24 +16,10 @@ public Bugzilla44461UITests(TestDevice device) public override string Issue => "ScrollToPosition.Center works differently on Android and iOS"; [Test] - [FailsOnIOSWhenRunningOnXamarinUITest("This test is failing, likely due to product issue")] - [FailsOnMacWhenRunningOnXamarinUITest("This test is failing, likely due to product issue")] public void Bugzilla44461Test() { - var positions = TapButton(0); - Assert.That(positions.initialPosition.X, Is.EqualTo(positions.finalPosition.X)); - Assert.That(positions.finalPosition.X, Is.LessThanOrEqualTo(1)); - } - - (System.Drawing.Rectangle initialPosition, System.Drawing.Rectangle finalPosition) TapButton(int position) - { - var buttonId = $"{position}"; - App.WaitForElement(buttonId); - var initialPosition = App.WaitForElement(buttonId).GetRect(); - App.Tap(buttonId); - var finalPosition = App.WaitForElement(buttonId).GetRect(); - return (initialPosition, finalPosition); + App.Tap("Scroll to Button0"); + VerifyScreenshot(); } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/Bugzilla44461Test.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/Bugzilla44461Test.png new file mode 100644 index 000000000000..8286bac3ba15 Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/Bugzilla44461Test.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/Bugzilla44461Test.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/Bugzilla44461Test.png new file mode 100644 index 000000000000..01f64a909179 Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/Bugzilla44461Test.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ScrollToElement3End.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ScrollToElement3End.png index e07c9e25a667..a0ca50d2f15d 100644 Binary files a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ScrollToElement3End.png and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ScrollToElement3End.png differ diff --git a/src/Core/src/Handlers/ScrollView/ScrollViewHandler.iOS.cs b/src/Core/src/Handlers/ScrollView/ScrollViewHandler.iOS.cs index 9561c9f423ca..56baabdf0fc5 100644 --- a/src/Core/src/Handlers/ScrollView/ScrollViewHandler.iOS.cs +++ b/src/Core/src/Handlers/ScrollView/ScrollViewHandler.iOS.cs @@ -108,10 +108,10 @@ public static void MapRequestScrollTo(IScrollViewHandler handler, IScrollView sc return; } - var availableScrollHeight = uiScrollView.ContentSize.Height - uiScrollView.Frame.Height; - var availableScrollWidth = uiScrollView.ContentSize.Width - uiScrollView.Frame.Width; - var minScrollHorizontal = Math.Min(request.HorizontalOffset, availableScrollWidth); - var minScrollVertical = Math.Min(request.VerticalOffset, availableScrollHeight); + var availableScrollHeight = Math.Max(uiScrollView.ContentSize.Height - uiScrollView.Frame.Height, 0); + var availableScrollWidth = Math.Max(uiScrollView.ContentSize.Width - uiScrollView.Frame.Width, 0); + var minScrollHorizontal = Math.Clamp(request.HorizontalOffset, 0, availableScrollWidth); + var minScrollVertical = Math.Clamp(request.VerticalOffset, 0, availableScrollHeight); uiScrollView.SetContentOffset(new CGPoint(minScrollHorizontal, minScrollVertical), !request.Instant); if (request.Instant)