-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android] Fix for CollectionView Scrolled event is triggered on the initial app load. #33558
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
jfversluis
merged 5 commits into
dotnet:inflight/current
from
BagavathiPerumal:fix-33333
Feb 24, 2026
+102
−0
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
461d925
fix-33333-Made code changes to avoid firing the ItemsView Scrolled ev…
BagavathiPerumal 1e3107f
fix-33333-Made changes to suppress initial CollectionView Scrolled ev…
BagavathiPerumal 3026fde
fix-33333-Made changes to prevent CollectionView Scrolled event from …
BagavathiPerumal 39ac9f9
fix-33333-Changes committed.
BagavathiPerumal b009ee4
fix-33333-Changes committed.
BagavathiPerumal 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
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,65 @@ | ||
| using System.Collections.ObjectModel; | ||
| using Microsoft.Maui.Controls; | ||
| using Microsoft.Maui.Graphics; | ||
|
|
||
| namespace Maui.Controls.Sample.Issues; | ||
|
|
||
| [Issue(IssueTracker.Github, 33333, "CollectionView Scrolled event is triggered on the initial app load", PlatformAffected.Android)] | ||
| public class Issue33333 : ContentPage | ||
| { | ||
| int _scrolledEventCount = 0; | ||
|
|
||
| public Issue33333() | ||
| { | ||
| var items = new ObservableCollection<string>(); | ||
| for (int i = 0; i < 50; i++) | ||
| { | ||
| items.Add($"Item {i}"); | ||
| } | ||
|
|
||
| var scrollCountLabel = new Label | ||
| { | ||
| AutomationId = "ScrollCountLabel", | ||
| Text = "Scrolled Event Count: 0", | ||
| FontSize = 18, | ||
| Padding = new Thickness(10), | ||
| BackgroundColor = Colors.LightYellow | ||
| }; | ||
|
|
||
| var collectionView = new CollectionView | ||
| { | ||
| AutomationId = "TestCollectionView", | ||
| ItemsSource = items, | ||
| ItemTemplate = new DataTemplate(() => | ||
| { | ||
| var label = new Label | ||
| { | ||
| Padding = new Thickness(10), | ||
| VerticalOptions = LayoutOptions.Center | ||
| }; | ||
| label.SetBinding(Label.TextProperty, "."); | ||
| return label; | ||
| }) | ||
| }; | ||
|
|
||
| collectionView.Scrolled += (sender, e) => | ||
| { | ||
| _scrolledEventCount++; | ||
| scrollCountLabel.Text = $"Scrolled Event Count: {_scrolledEventCount}"; | ||
| }; | ||
|
|
||
| var instructionLabel = new Label | ||
| { | ||
| AutomationId = "InstructionLabel", | ||
| Text = "The Scrolled event count should remain 0 on initial load. On Android, it incorrectly fires immediately.", | ||
| Padding = new Thickness(10), | ||
| FontSize = 14, | ||
| TextColor = Colors.Gray | ||
| }; | ||
|
|
||
| Content = new StackLayout | ||
| { | ||
| Children = { scrollCountLabel, instructionLabel, collectionView } | ||
| }; | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue33333.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,23 @@ | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
|
||
| public class Issue33333 : _IssuesUITest | ||
| { | ||
| public override string Issue => "CollectionView Scrolled event is triggered on the initial app load"; | ||
|
|
||
| public Issue33333(TestDevice device) : base(device) { } | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.CollectionView)] | ||
| public void CollectionViewScrolledEventShouldNotFireOnInitialLoad() | ||
| { | ||
| App.WaitForElement("ScrollCountLabel"); | ||
|
|
||
| var scrollCountText = App.FindElement("ScrollCountLabel").GetText(); | ||
| Assert.That(scrollCountText, Is.EqualTo("Scrolled Event Count: 0"), | ||
| "Scrolled event should not fire on initial load without user interaction"); | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test only verifies that the Scrolled event doesn't fire on initial load, but doesn't validate that subsequent scrolling events work correctly after the initial load. Consider adding a second test case or extending this test to perform an actual scroll and verify that the event fires properly (e.g., scroll count should be 1 after user scrolls).