-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android] Fix for Incorrect ItemsViewScrolledEventArgs Values in CollectionView with Grouped Items #31437
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
Open
SyedAbdulAzeemSF4852
wants to merge
7
commits into
dotnet:main
Choose a base branch
from
SyedAbdulAzeemSF4852:fix-17664
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+279
−37
Open
[Android] Fix for Incorrect ItemsViewScrolledEventArgs Values in CollectionView with Grouped Items #31437
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b5351e8
[Android & iOS] Fix for incorrect ItemsViewScrolledEventArgs in Colle…
SyedAbdulAzeemSF4852 b5f2458
Modified the fix and have added comment lines to explain the logic
SyedAbdulAzeemSF4852 8536b19
Updated variable naming and condition order in Android; added comment…
SyedAbdulAzeemSF4852 be5d951
Added GetGroupedDataCount method to count only data items, and update…
SyedAbdulAzeemSF4852 100cc6f
Used Math.Clamp instead of Math.Max to ensure that visible item indic…
SyedAbdulAzeemSF4852 d4c6b1c
Revert iOS fix
SyedAbdulAzeemSF4852 262f346
Fix off-by-one in AdjustGroupIndex, correct position < 0 handling, an…
SyedAbdulAzeemSF4852 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
120 changes: 120 additions & 0 deletions
120
src/Controls/tests/TestCases.HostApp/Issues/Issue17664.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,120 @@ | ||
| using System.Collections.ObjectModel; | ||
|
|
||
| namespace Maui.Controls.Sample.Issues; | ||
|
|
||
| [Issue(IssueTracker.Github, 17664, "Incorrect ItemsViewScrolledEventArgs in CollectionView when IsGrouped is set to true", PlatformAffected.Android)] | ||
| public class Issue17664 : ContentPage | ||
| { | ||
| CollectionView _collectionView; | ||
| Label descriptionLabel; | ||
| ObservableCollection<Issue17664_ItemModelGroup> _groupedItems; | ||
|
|
||
| public Issue17664() | ||
| { | ||
| Button scrollButton = new Button | ||
| { | ||
| AutomationId = "Issue17664ScrollBtn", | ||
| Text = "Scroll to Category C, Item #2" | ||
| }; | ||
| scrollButton.Clicked += ScrollButton_Clicked; | ||
|
|
||
| descriptionLabel = new Label | ||
| { | ||
| AutomationId = "Issue17664DescriptionLabel", | ||
| Text = "Use the button above to scroll the CollectionView.", | ||
| FontSize = 14, | ||
| HorizontalOptions = LayoutOptions.Center | ||
| }; | ||
|
|
||
| _collectionView = new CollectionView | ||
| { | ||
| IsGrouped = true, | ||
| GroupHeaderTemplate = new DataTemplate(() => | ||
| { | ||
| Label label = new Label | ||
| { | ||
| FontAttributes = FontAttributes.Bold, | ||
| BackgroundColor = Colors.LightGray, | ||
| Padding = 10 | ||
| }; | ||
|
|
||
| label.SetBinding(Label.TextProperty, "Name"); | ||
| return label; | ||
| }), | ||
| ItemTemplate = new DataTemplate(() => | ||
| { | ||
| Label textLabel = new Label | ||
| { | ||
| FontAttributes = FontAttributes.Bold, | ||
| Padding = 30 | ||
| }; | ||
|
|
||
| textLabel.SetBinding(Label.TextProperty, "."); | ||
| return textLabel; | ||
| }) | ||
| }; | ||
|
|
||
| _collectionView.Scrolled += (s, e) => | ||
| { | ||
| var flatItems = _groupedItems.SelectMany(group => group).ToList(); | ||
| if (e.LastVisibleItemIndex < flatItems.Count) | ||
| { | ||
| descriptionLabel.Text = flatItems[e.LastVisibleItemIndex]; | ||
| } | ||
| }; | ||
|
|
||
| List<string> categories = new List<string> { "Category A", "Category B", "Category C" }; | ||
|
|
||
| _groupedItems = new ObservableCollection<Issue17664_ItemModelGroup>(); | ||
|
|
||
| foreach (var category in categories) | ||
| { | ||
| List<string> items = new List<string>(); | ||
|
|
||
| for (int i = 0; i < 5; i++) | ||
| { | ||
| items.Add($"{category} item #{i}"); | ||
| } | ||
|
|
||
| _groupedItems.Add(new Issue17664_ItemModelGroup(category, items)); | ||
| } | ||
|
|
||
| _collectionView.ItemsSource = _groupedItems; | ||
|
|
||
| Grid grid = new Grid | ||
| { | ||
| RowSpacing = 10, | ||
| Padding = 10, | ||
| RowDefinitions = | ||
| { | ||
| new RowDefinition { Height = GridLength.Auto }, | ||
| new RowDefinition { Height = GridLength.Auto }, | ||
| new RowDefinition { Height = GridLength.Star } | ||
| } | ||
| }; | ||
|
|
||
| grid.Add(scrollButton, 0, 0); | ||
| grid.Add(descriptionLabel, 0, 1); | ||
| grid.Add(_collectionView, 0, 2); | ||
|
|
||
| Content = grid; | ||
| } | ||
|
|
||
| private void ScrollButton_Clicked(object sender, EventArgs e) | ||
| { | ||
| var targetGroup = _groupedItems.FirstOrDefault(group => group.Name == "Category C"); | ||
| var targetItem = targetGroup.FirstOrDefault(item => item == "Category C item #2"); | ||
|
|
||
| _collectionView.ScrollTo(targetItem, targetGroup, ScrollToPosition.End); | ||
| } | ||
| } | ||
|
|
||
| public class Issue17664_ItemModelGroup : ObservableCollection<string> | ||
| { | ||
| public string Name { get; set; } | ||
|
|
||
| public Issue17664_ItemModelGroup(string name, IEnumerable<string> items) : base(items) | ||
| { | ||
| Name = name; | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue17664.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,30 @@ | ||
| #if TEST_FAILS_ON_IOS && TEST_FAILS_ON_CATALYST && TEST_FAILS_ON_WINDOWS // iOS/MacCatalyst fix: https://github.com/dotnet/maui/pull/34240 | ||
| // Windows: The Scrolled event is not consistently triggered in the CI environment during automated | ||
| // scrolling, so the label text is never updated. This is a test infrastructure limitation on Windows; | ||
| // the fix itself (RecyclerViewScrollListener.cs) is Android-only and works correctly on Android. | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
|
||
| public class Issue17664 : _IssuesUITest | ||
| { | ||
| public Issue17664(TestDevice device) : base(device) | ||
| { | ||
| } | ||
|
|
||
| public override string Issue => "Incorrect ItemsViewScrolledEventArgs in CollectionView when IsGrouped is set to true"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.CollectionView)] | ||
| public void VerifyGroupedCollectionViewVisibleItemIndices() | ||
|
jsuarezruiz marked this conversation as resolved.
|
||
| { | ||
| App.WaitForElement("Issue17664ScrollBtn"); | ||
| App.Tap("Issue17664ScrollBtn"); | ||
|
|
||
| var resultItem = App.WaitForElement("Issue17664DescriptionLabel").GetText(); | ||
| Assert.That(resultItem, Is.EqualTo("Category C item #2")); | ||
| } | ||
| } | ||
| #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.