-
Notifications
You must be signed in to change notification settings - Fork 2k
[Android] Fix ScrollTo regression when IsGrouped true on CollectionView #35356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
src/Controls/tests/TestCases.HostApp/Issues/Issue35313.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<Issue35313ItemGroup> _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)) | ||
|
SubhikshaSf4851 marked this conversation as resolved.
|
||
| }; | ||
|
|
||
| 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<Issue35313Item> | ||
| { | ||
| public string Key { get; set; } = string.Empty; | ||
| } | ||
32 changes: 32 additions & 0 deletions
32
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue35313.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #if ANDROID // Open Issue For iOS, MacCatalyst and Windows : https://github.com/dotnet/maui/issues/35326 | ||
|
SubhikshaSf4851 marked this conversation as resolved.
SubhikshaSf4851 marked this conversation as resolved.
|
||
| 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 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.