-
Notifications
You must be signed in to change notification settings - Fork 2k
[Android] Fix for incorrect scroll position when using ScrollTo with a header in CollectionView #30966
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
PureWeen
merged 3 commits into
dotnet:inflight/current
from
SyedAbdulAzeemSF4852:fix-18389
Feb 18, 2026
Merged
[Android] Fix for incorrect scroll position when using ScrollTo with a header in CollectionView #30966
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
113 changes: 113 additions & 0 deletions
113
src/Controls/tests/TestCases.HostApp/Issues/Issue18389.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,113 @@ | ||
| using System.Collections.ObjectModel; | ||
|
|
||
| namespace Maui.Controls.Sample.Issues; | ||
|
|
||
| [Issue(IssueTracker.Github, 18389, "Incorrect scroll position when scrolling to an item with header in CollectionView", PlatformAffected.Android)] | ||
| public class Issue18389 : ContentPage | ||
| { | ||
| ObservableCollection<string> _items; | ||
| CollectionView2 _collectionView; | ||
| public Issue18389() | ||
| { | ||
| GenerateItems(); | ||
|
|
||
| Grid mainGrid = new Grid | ||
| { | ||
| Padding = new Thickness(20), | ||
| RowSpacing = 10, | ||
| RowDefinitions = | ||
| { | ||
| new RowDefinition { Height = GridLength.Auto }, | ||
| new RowDefinition { Height = GridLength.Auto }, | ||
| new RowDefinition { Height = GridLength.Auto }, | ||
| new RowDefinition { Height = GridLength.Star } | ||
| } | ||
| }; | ||
|
|
||
| Button scrollToIndexButton = new Button | ||
| { | ||
| AutomationId = "Issue18389_ScrollToBtn", | ||
| Text = "Click me to scroll to index Count - 1!" | ||
| }; | ||
| scrollToIndexButton.Clicked += ScrollToLastItem; | ||
|
|
||
| Button removeHeaderButton = new Button | ||
| { | ||
| AutomationId = "Issue18389_RemoveHeaderBtn", | ||
| Text = "Remove Header" | ||
| }; | ||
| removeHeaderButton.Clicked += RemoveHeader; | ||
|
|
||
| Button resetCollectionViewButton = new Button | ||
| { | ||
| AutomationId = "Issue18389_ResetBtn", | ||
| Text = "Reset CollectionView to 0,0" | ||
| }; | ||
| resetCollectionViewButton.Clicked += ResetCollectionView; | ||
|
|
||
| mainGrid.Add(scrollToIndexButton, 0, 0); | ||
| mainGrid.Add(resetCollectionViewButton, 0, 1); | ||
| mainGrid.Add(removeHeaderButton, 0, 2); | ||
|
|
||
| _collectionView = new CollectionView2 | ||
| { | ||
| ItemsSource = _items, | ||
| ItemTemplate = new DataTemplate(() => | ||
| { | ||
| Label label = new Label | ||
| { | ||
| FontSize = 40 | ||
| }; | ||
| label.SetBinding(Label.TextProperty, "."); | ||
| label.SetBinding(Label.AutomationIdProperty, "."); | ||
|
|
||
| return label; | ||
| }), | ||
| Header = new Label | ||
| { | ||
| Text = "Header", | ||
| BackgroundColor = Colors.Black, | ||
| TextColor = Colors.White, | ||
| FontSize = 50, | ||
| FontFamily = "Bold" | ||
| }, | ||
| Footer = new Label | ||
| { | ||
| Text = "Footer", | ||
| BackgroundColor = Colors.Black, | ||
| TextColor = Colors.White, | ||
| FontSize = 50, | ||
| FontFamily = "Bold" | ||
| }, | ||
| }; | ||
|
|
||
| mainGrid.Add(_collectionView, 0, 3); | ||
|
|
||
| Content = mainGrid; | ||
| } | ||
|
|
||
| void GenerateItems() | ||
| { | ||
| _items = new ObservableCollection<string>(); | ||
|
|
||
| for (int i = 1; i <= 20; i++) | ||
| { | ||
| _items.Add($"Item {i}"); | ||
| } | ||
| } | ||
|
|
||
| void ScrollToLastItem(object sender, EventArgs e) | ||
| { | ||
| _collectionView.ScrollTo(_items.Count - 1, -1, ScrollToPosition.End); | ||
| } | ||
|
|
||
| void RemoveHeader(object sender, EventArgs e) | ||
| { | ||
| _collectionView.Header = null; | ||
| } | ||
|
|
||
| void ResetCollectionView(object sender, EventArgs e) | ||
| { | ||
| _collectionView.ScrollTo(0); | ||
| } | ||
| } | ||
35 changes: 35 additions & 0 deletions
35
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue18389.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,35 @@ | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
|
||
| public class Issue18389 : _IssuesUITest | ||
| { | ||
| public Issue18389(TestDevice device) : base(device) | ||
| { | ||
| } | ||
|
|
||
| public override string Issue => "Incorrect scroll position when scrolling to an item with header in CollectionView"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.CollectionView)] | ||
| public void VerifyScrollToIndexWithHeader() | ||
| { | ||
| App.WaitForElement("Issue18389_ScrollToBtn"); | ||
| App.Tap("Issue18389_ScrollToBtn"); | ||
|
|
||
| App.WaitForElement("Item 20"); | ||
|
|
||
| App.WaitForElement("Issue18389_ResetBtn"); | ||
| App.Tap("Issue18389_ResetBtn"); | ||
|
|
||
| App.WaitForElement("Item 1"); | ||
|
|
||
| App.WaitForElement("Issue18389_RemoveHeaderBtn"); | ||
| App.Tap("Issue18389_RemoveHeaderBtn"); | ||
|
|
||
| App.Tap("Issue18389_ScrollToBtn"); | ||
| App.WaitForElement("Item 20"); | ||
| } | ||
| } |
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.
To validate the behavior in all the conditions, can include a Button to remove the Header, and include a CollectionView without header test?
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.
@jsuarezruiz , As suggested, I’ve added a button to remove the header and validated the behavior of the CollectionView without a header.