-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Fix the ListView scroll position center and end without animation #27001
Open
Shalini-Ashokan
wants to merge
3
commits into
dotnet:main
Choose a base branch
from
Shalini-Ashokan:fix-26945
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.
Open
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 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
Binary file added
BIN
+28.2 KB
...ses.Android.Tests/snapshots/android/Issue26945Test_SelectItemPositionCenter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+28.8 KB
...tCases.Android.Tests/snapshots/android/Issue26945Test_SelectItemPositionEnd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+30.1 KB
...ases.Android.Tests/snapshots/android/Issue26945Test_SelectItemPositionStart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
135 changes: 135 additions & 0 deletions
135
src/Controls/tests/TestCases.HostApp/Issues/Issue26945.cs
This file contains 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,135 @@ | ||
using System.Collections.ObjectModel; | ||
|
||
namespace Maui.Controls.Sample.Issues | ||
{ | ||
[Issue(IssueTracker.Github, 26945, "ListView ScrollTo position always remains at the start even when set to Center or End without animation", PlatformAffected.All)] | ||
public class Issue26945 : ContentPage | ||
{ | ||
private ListView ListView; | ||
private ObservableCollection<string> Items; | ||
|
||
public Issue26945() | ||
{ | ||
Items = new ObservableCollection<string> | ||
{ | ||
"Item 1", | ||
"Item 2", | ||
"Item 3", | ||
"Item 4", | ||
"Item 5", | ||
"Item 6", | ||
"Item 7", | ||
"Item 8", | ||
"Item 9", | ||
"Item 10", | ||
"Item 11", | ||
"Item 12", | ||
"Item 13", | ||
"Item 14", | ||
"Item 15", | ||
"Item 16", | ||
"Item 17", | ||
"Item 18", | ||
"Item 19", | ||
"Item 20", | ||
"Item 21", | ||
"Item 22", | ||
"Item 23", | ||
"Item 24", | ||
"Item 25", | ||
}; | ||
|
||
ListView = new ListView | ||
{ | ||
ItemsSource = Items, | ||
SelectedItem = "Item 10", | ||
VerticalOptions = LayoutOptions.Center, | ||
HorizontalOptions = LayoutOptions.Center, | ||
WidthRequest = 300, | ||
HeightRequest = 220, | ||
}; | ||
|
||
var horizontalStack = new StackLayout | ||
{ | ||
Orientation = StackOrientation.Horizontal, | ||
HorizontalOptions = LayoutOptions.Center, | ||
Spacing = 20 | ||
}; | ||
|
||
var startButton = new Button | ||
{ | ||
Text = "Start", | ||
AutomationId = "StartButton", | ||
}; | ||
startButton.Clicked += ScrollPositionStart_Clicked; | ||
|
||
var centerButton = new Button | ||
{ | ||
Text = "Center", | ||
AutomationId = "CenterButton", | ||
}; | ||
centerButton.Clicked += ScrollPositionCenter_Clicked; | ||
|
||
var endButton = new Button | ||
{ | ||
Text = "End", | ||
AutomationId = "EndButton", | ||
}; | ||
endButton.Clicked += ScrollPositionEnd_Clicked; | ||
|
||
horizontalStack.Children.Add(startButton); | ||
horizontalStack.Children.Add(centerButton); | ||
horizontalStack.Children.Add(endButton); | ||
|
||
var stackLayout = new StackLayout | ||
{ | ||
Orientation = StackOrientation.Vertical, | ||
Spacing = 20 | ||
}; | ||
|
||
stackLayout.Children.Add(ListView); | ||
stackLayout.Children.Add(horizontalStack); | ||
this.Content = stackLayout; | ||
} | ||
|
||
private void ScrollToSelectedItem(ScrollToPosition toPosition) | ||
{ | ||
if (ListView?.SelectedItem != null) | ||
{ | ||
switch (toPosition) | ||
{ | ||
case ScrollToPosition.Start: | ||
ListView.ScrollTo(ListView.SelectedItem, ScrollToPosition.Start, false); | ||
break; | ||
case ScrollToPosition.Center: | ||
ListView.ScrollTo(ListView.SelectedItem, ScrollToPosition.Center, false); | ||
break; | ||
case ScrollToPosition.End: | ||
ListView.ScrollTo(ListView.SelectedItem, ScrollToPosition.End, false); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
private void ScrollPositionStart_Clicked(object sender, EventArgs e) | ||
{ | ||
var currentIndex = Items.IndexOf(ListView.SelectedItem as string); | ||
ListView.SelectedItem = Items[currentIndex + 2]; | ||
ScrollToSelectedItem(ScrollToPosition.Start); | ||
} | ||
|
||
private void ScrollPositionCenter_Clicked(object sender, EventArgs e) | ||
{ | ||
var currentIndex = Items.IndexOf(ListView.SelectedItem as string); | ||
ListView.SelectedItem = Items[currentIndex + 2]; | ||
ScrollToSelectedItem(ScrollToPosition.Center); | ||
} | ||
|
||
private void ScrollPositionEnd_Clicked(object sender, EventArgs e) | ||
{ | ||
var currentIndex = Items.IndexOf(ListView.SelectedItem as string); | ||
ListView.SelectedItem = Items[currentIndex + 2]; | ||
ScrollToSelectedItem(ScrollToPosition.End); | ||
} | ||
} | ||
} |
Binary file added
BIN
+49.3 KB
...s/TestCases.Mac.Tests/snapshots/mac/Issue26945Test_SelectItemPositionCenter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+49.4 KB
...ests/TestCases.Mac.Tests/snapshots/mac/Issue26945Test_SelectItemPositionEnd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+49.5 KB
...ts/TestCases.Mac.Tests/snapshots/mac/Issue26945Test_SelectItemPositionStart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions
43
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue26945.cs
This file contains 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,43 @@ | ||
using NUnit.Framework; | ||
using NUnit.Framework.Legacy; | ||
using UITest.Appium; | ||
using UITest.Core; | ||
|
||
namespace Microsoft.Maui.TestCases.Tests.Issues | ||
{ | ||
public class Issue26945 : _IssuesUITest | ||
{ | ||
public override string Issue => "ListView ScrollTo position always remains at the start even when set to Center or End without animation"; | ||
|
||
public Issue26945(TestDevice device) : base(device) | ||
{ | ||
} | ||
|
||
[Test] | ||
[Category(UITestCategories.ListView)] | ||
public void Issue26945Test_SelectItemPositionStart() | ||
{ | ||
App.WaitForElement("StartButton"); | ||
App.Tap("StartButton"); | ||
VerifyScreenshot(); | ||
} | ||
|
||
[Test] | ||
[Category(UITestCategories.ListView)] | ||
public void Issue26945Test_SelectItemPositionCenter() | ||
{ | ||
App.WaitForElement("CenterButton"); | ||
App.Tap("CenterButton"); | ||
VerifyScreenshot(); | ||
} | ||
|
||
[Test] | ||
[Category(UITestCategories.ListView)] | ||
public void Issue26945Test_SelectItemPositionEnd() | ||
{ | ||
App.WaitForElement("EndButton"); | ||
App.Tap("EndButton"); | ||
VerifyScreenshot(); | ||
} | ||
} | ||
} |
Binary file added
BIN
+13.5 KB
...Cases.WinUI.Tests/snapshots/windows/Issue26945Test_SelectItemPositionCenter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+13.3 KB
...estCases.WinUI.Tests/snapshots/windows/Issue26945Test_SelectItemPositionEnd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+14.4 KB
...tCases.WinUI.Tests/snapshots/windows/Issue26945Test_SelectItemPositionStart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+35.4 KB
...s/TestCases.iOS.Tests/snapshots/ios/Issue26945Test_SelectItemPositionCenter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+35.4 KB
...ests/TestCases.iOS.Tests/snapshots/ios/Issue26945Test_SelectItemPositionEnd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+38.5 KB
...ts/TestCases.iOS.Tests/snapshots/ios/Issue26945Test_SelectItemPositionStart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
Could modify the sample using for example, a CheckBox, to use the ScrollTo method with the animated parameter using true and also false values?
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, The current PR includes a test case without animation. We already have a test case with animation in this PR. Could you please review it and share your feedback?