From 9dc69de1869d181d03a49bc7c6e173bf89057414 Mon Sep 17 00:00:00 2001 From: Subhiksha Chandrasekaran Date: Wed, 6 May 2026 12:50:12 +0530 Subject: [PATCH 1/3] [Android] Fix ScrollTo not working on CollectionView --- .../src/Core/Handlers/Items/Android/MauiRecyclerView.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Controls/src/Core/Handlers/Items/Android/MauiRecyclerView.cs b/src/Controls/src/Core/Handlers/Items/Android/MauiRecyclerView.cs index 288727d264c2..4d65a66e44b0 100644 --- a/src/Controls/src/Core/Handlers/Items/Android/MauiRecyclerView.cs +++ b/src/Controls/src/Core/Handlers/Items/Android/MauiRecyclerView.cs @@ -461,6 +461,13 @@ protected virtual int DetermineTargetPosition(ScrollToRequestEventArgs args) private static object FindBoundItemInGroup(ScrollToRequestEventArgs args, IGroupableItemsViewSource groupItemSource) { + // When no group index is specified (groupIndex < 0), fall back to flat index lookup. + // This handles the case where ScrollTo(index) is called without a group on a grouped CollectionView. + if (args.GroupIndex < 0) + { + return groupItemSource.GetItem(args.Index); + } + var group = groupItemSource.GetGroupItemsViewSource(args.GroupIndex); // GetItem calls AdjustIndexRequest, which subtracts 1 if we have a header (UngroupedItemsSource does not do this) From a32d7a042b93d554884549883b638ebd7c2ff8f9 Mon Sep 17 00:00:00 2001 From: Subhiksha Chandrasekaran Date: Wed, 6 May 2026 17:59:23 +0530 Subject: [PATCH 2/3] Test sample Added --- .../TestCases.HostApp/Issues/Issue35313.cs | 112 ++++++++++++++++++ .../Tests/Issues/Issue35313.cs | 32 +++++ 2 files changed, 144 insertions(+) create mode 100644 src/Controls/tests/TestCases.HostApp/Issues/Issue35313.cs create mode 100644 src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue35313.cs diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue35313.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue35313.cs new file mode 100644 index 000000000000..e71ca8a3e607 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue35313.cs @@ -0,0 +1,112 @@ +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 35313, "ScrollTo(0) not working on grouped CollectionView", PlatformAffected.Android)] +public class Issue35313 : ContentPage +{ + CollectionView _collectionView; + List _groups; + + public Issue35313() + { + _groups = []; + for (int g = 1; g <= 5; g++) + { + var group = new Issue35313ItemGroup { Key = $"Group {g}" }; + for (int i = 1; i <= 10; i++) + group.Add(new Issue35313Item { Name = $"Group {g} — Item {i}" }); + _groups.Add(group); + } + + _collectionView = new CollectionView + { + AutomationId = "CollectionView", + IsGrouped = true, + ItemsSource = _groups, + GroupHeaderTemplate = new DataTemplate(() => + { + var label = new Label + { + Padding = new Thickness(8, 4), + BackgroundColor = Colors.LightGray, + FontAttributes = FontAttributes.Bold + }; + label.SetBinding(Label.TextProperty, "Key"); + label.SetBinding(Label.AutomationIdProperty, "Key"); + return label; + }), + ItemTemplate = new DataTemplate(() => + { + var label = new Label { Padding = new Thickness(16, 8) }; + label.SetBinding(Label.TextProperty, "Name"); + label.SetBinding(Label.AutomationIdProperty, "Name"); + return label; + }) + }; + + var buttonStart = new Button + { + Text = "Start", + AutomationId = "ScrollToStartButton", + Command = new Command(() => _collectionView.ScrollTo(0)) + }; + + var buttonFirstItem = new Button + { + Text = "First item", + AutomationId = "ScrollToFirstItemButton", + Command = new Command(() => + { + var firstGroup = _groups[0]; + _collectionView.ScrollTo(firstGroup[0], firstGroup, ScrollToPosition.Start, animate: true); + }) + }; + + var buttonLastItem = new Button + { + Text = "Last item", + AutomationId = "ScrollToLastItemButton", + Command = new Command(() => + { + var lastGroup = _groups[^1]; + _collectionView.ScrollTo(lastGroup[^1], lastGroup, ScrollToPosition.End, animate: true); + }) + }; + + var buttonEnd = new Button + { + Text = "End", + AutomationId = "ScrollToEndButton", + Command = new Command(() => _collectionView.ScrollTo(54)) + }; + + var buttonRow = new HorizontalStackLayout + { + Padding = new Thickness(8), + Spacing = 8, + Children = { buttonStart, buttonFirstItem, buttonLastItem, buttonEnd } + }; + + Content = new Grid + { + RowDefinitions = + { + new RowDefinition { Height = GridLength.Auto }, + new RowDefinition { Height = GridLength.Star }, + }, + Children = { buttonRow, _collectionView } + }; + + Grid.SetRow(buttonRow, 0); + Grid.SetRow(_collectionView, 1); + } +} + +public class Issue35313Item +{ + public string Name { get; set; } = string.Empty; +} + +public class Issue35313ItemGroup : List +{ + public string Key { get; set; } = string.Empty; +} diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue35313.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue35313.cs new file mode 100644 index 000000000000..d2f9a442e6d2 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue35313.cs @@ -0,0 +1,32 @@ +#if ANDROID +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue35313 : _IssuesUITest +{ + public Issue35313(TestDevice device) : base(device) { } + + public override string Issue => "ScrollTo(0) not working on grouped CollectionView"; + + [Test] + [Category(UITestCategories.CollectionView)] + public void GroupedCollectionViewScrollToIndexZeroShouldScrollToStart() + { + App.WaitForElement("ScrollToEndButton"); + + // Scroll to the end so the top is off screen + App.Tap("ScrollToEndButton"); + App.WaitForElement("Group 5 — Item 10"); + + // ScrollTo(0) on a grouped CollectionView — this is the regression + // Without the fix it silently does nothing on Android + App.Tap("ScrollToStartButton"); + + // Group 1 header should be visible after scrolling to index 0 + App.WaitForElement("Group 1"); + } +} +#endif \ No newline at end of file From 2242a957b3b7e2c3cce3cab932ef0ec1d718de7d Mon Sep 17 00:00:00 2001 From: Subhiksha Chandrasekaran Date: Wed, 6 May 2026 19:11:11 +0530 Subject: [PATCH 3/3] Restricted Test --- .../tests/TestCases.Shared.Tests/Tests/Issues/Issue35313.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue35313.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue35313.cs index d2f9a442e6d2..47e6ff09f76f 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue35313.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue35313.cs @@ -1,4 +1,4 @@ -#if ANDROID +#if ANDROID // Open Issue For iOS, MacCatalyst and Windows : https://github.com/dotnet/maui/issues/35326 using NUnit.Framework; using UITest.Appium; using UITest.Core;