-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Incorrect First and Last Visible Item index in CollectionView Scr…
…olled Event (#26468) * Fixed the CollectionView Scrolled Calls and parameters are incorrect * Removed unwanted changes * Fix the failures cases * Fixed the failed scenarios * Removed the unwanted code changes * Removed unwanted line * Modified a test case * Modified a test cases * Added a details for mac failure --------- Co-authored-by: Shalini-Ashokan <[email protected]>
- Loading branch information
1 parent
4c42078
commit b5d4c66
Showing
4 changed files
with
225 additions
and
0 deletions.
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
66 changes: 66 additions & 0 deletions
66
src/Controls/tests/TestCases.HostApp/Issues/Issue25649.xaml
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,66 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="Maui.Controls.Sample.Issues.Issue25649" | ||
xmlns:local="clr-namespace:Maui.Controls.Sample.Issues"> | ||
|
||
<ContentPage.BindingContext> | ||
<local:_25649MainViewModel/> | ||
</ContentPage.BindingContext> | ||
|
||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="0.8*"/> | ||
<RowDefinition Height="0.2*"/> | ||
</Grid.RowDefinitions> | ||
|
||
<CollectionView AutomationId="collectionView" | ||
x:DataType="local:_25649MainViewModel" | ||
ItemsSource="{Binding _25649People}" | ||
Scrolled="OnCollectionViewScrolled" | ||
BackgroundColor="DarkGray"> | ||
<CollectionView.ItemsLayout> | ||
<LinearItemsLayout Orientation="Vertical" | ||
SnapPointsType="Mandatory"/> | ||
</CollectionView.ItemsLayout> | ||
|
||
<CollectionView.Header> | ||
<StackLayout BackgroundColor="LightGray"> | ||
<Label Margin="10,0,0,0" | ||
Text="People" | ||
FontSize="12" | ||
FontAttributes="Bold"/> | ||
</StackLayout> | ||
</CollectionView.Header> | ||
|
||
<CollectionView.ItemTemplate> | ||
<DataTemplate x:DataType="local:_25649Person"> | ||
<VerticalStackLayout> | ||
<Label Text="{Binding Name}" | ||
FontSize="Medium"/> | ||
<Rectangle HeightRequest="2" | ||
BackgroundColor="Black"/> | ||
</VerticalStackLayout> | ||
</DataTemplate> | ||
</CollectionView.ItemTemplate> | ||
|
||
<CollectionView.Footer> | ||
<StackLayout BackgroundColor="LightGray"> | ||
<Label Margin="10,0,0,0" | ||
Text="Footer" | ||
FontSize="12" | ||
FontAttributes="Bold"/> | ||
</StackLayout> | ||
</CollectionView.Footer> | ||
</CollectionView> | ||
|
||
<Label | ||
x:Name="lastVisibleItemIndex" | ||
Grid.Row="1" | ||
AutomationId="LastVisibleItemIndex" | ||
Text="Last Visible Item Index" | ||
HorizontalOptions="Start" | ||
VerticalOptions="Center"/> | ||
|
||
</Grid> | ||
</ContentPage> |
71 changes: 71 additions & 0 deletions
71
src/Controls/tests/TestCases.HostApp/Issues/Issue25649.xaml.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,71 @@ | ||
using System.Collections.ObjectModel; | ||
using System.Diagnostics; | ||
using System.Windows.Input; | ||
|
||
namespace Maui.Controls.Sample.Issues | ||
{ | ||
[Issue(IssueTracker.Github, 25649, "CollectionView OnCollectionViewScrolled Calls and parameters are inconsistent or incorrect", PlatformAffected.All)] | ||
public partial class Issue25649 : ContentPage | ||
{ | ||
public Issue25649() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
void OnCollectionViewScrolled(object sender, ItemsViewScrolledEventArgs e) | ||
{ | ||
lastVisibleItemIndex.Text = e.LastVisibleItemIndex.ToString(); | ||
} | ||
} | ||
|
||
public class _25649MainViewModel : BindableObject | ||
{ | ||
public ObservableCollection<_25649Person> _25649People { get; set; } | ||
public _25649MainViewModel() | ||
{ | ||
|
||
_25649People = new ObservableCollection<_25649Person>() | ||
{ | ||
new _25649Person() { Name = "Person 0" }, | ||
new _25649Person() { Name = "Person 1" }, | ||
new _25649Person() { Name = "Person 2" }, | ||
new _25649Person() { Name = "Person 3" }, | ||
new _25649Person() { Name = "Person 4" }, | ||
new _25649Person() { Name = "Person 5" }, | ||
new _25649Person() { Name = "Person 6" }, | ||
new _25649Person() { Name = "Person 7" }, | ||
new _25649Person() { Name = "Person 8" }, | ||
new _25649Person() { Name = "Person 9" }, | ||
new _25649Person() { Name = "Person 10" }, | ||
new _25649Person() { Name = "Person 11" }, | ||
new _25649Person() { Name = "Person 12" }, | ||
new _25649Person() { Name = "Person 13" }, | ||
new _25649Person() { Name = "Person 14" }, | ||
new _25649Person() { Name = "Person 15" }, | ||
new _25649Person() { Name = "Person 16" }, | ||
new _25649Person() { Name = "Person 17" }, | ||
new _25649Person() { Name = "Person 18" }, | ||
new _25649Person() { Name = "Person 19" }, | ||
new _25649Person() { Name = "Person 20" }, | ||
new _25649Person() { Name = "Person 21" }, | ||
new _25649Person() { Name = "Person 22" }, | ||
new _25649Person() { Name = "Person 23" }, | ||
new _25649Person() { Name = "Person 24" }, | ||
new _25649Person() { Name = "Person 25" }, | ||
new _25649Person() { Name = "Person 26" }, | ||
new _25649Person() { Name = "Person 27" }, | ||
new _25649Person() { Name = "Person 28" }, | ||
new _25649Person() { Name = "Person 29" }, | ||
new _25649Person() { Name = "Person 30" }, | ||
}; | ||
} | ||
} | ||
|
||
public class _25649Person | ||
{ | ||
public string Name { get; set; } | ||
} | ||
} | ||
|
||
|
||
|
31 changes: 31 additions & 0 deletions
31
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue25649.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,31 @@ | ||
#if TEST_FAILS_ON_CATALYST // Scroll actions do not work on MacCatalyst, so this test is ignored on MacCatalyst. | ||
|
||
using NUnit.Framework; | ||
using UITest.Appium; | ||
using UITest.Core; | ||
|
||
namespace Microsoft.Maui.TestCases.Tests.Issues | ||
{ | ||
public class Issue25649 : _IssuesUITest | ||
{ | ||
public Issue25649(TestDevice testDevice) : base(testDevice) | ||
{ | ||
} | ||
|
||
public override string Issue => "CollectionView OnCollectionViewScrolled Calls and parameters are inconsistent or incorrect"; | ||
|
||
[Test] | ||
[Category(UITestCategories.CollectionView)] | ||
public void Issue25649Test() | ||
{ | ||
App.WaitForElement("collectionView"); | ||
App.ScrollDown("collectionView", ScrollStrategy.Gesture, 0.99); | ||
|
||
// The ScrollDown method returns a different FirstVisibleItemIndex values on each call, so it cannot be used for consistent test validation. | ||
|
||
var lastVisibleItemIndex = App.FindElement("LastVisibleItemIndex").GetText(); | ||
Assert.That(lastVisibleItemIndex, Is.EqualTo("30")); | ||
} | ||
} | ||
} | ||
#endif |