-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix for Try scrolling down and when new items are added the first item does not kept in the displayed list. #27153
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
base: main
Are you sure you want to change the base?
Changes from all commits
1a26837
4bd5bbe
09944f0
3f4f7e2
f92b14d
dbbe3ea
739927b
54dfbe3
4ff068e
9ef687c
c8ed423
7aac65c
ba0f988
a32da09
bd18b85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?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" | ||
xmlns:cv1="clr-namespace:Maui.Controls.Sample" | ||
x:Class="Maui.Controls.Sample.Issues.Issue26810"> | ||
<Grid RowDefinitions="50,50,50,*" | ||
AutomationId="26810MainGrid"> | ||
<Grid Grid.Row="0" | ||
ColumnDefinitions="*,*,*"> | ||
<Button Text="KeepItemsInView" | ||
AutomationId="26810FirstItemButton" | ||
x:Name="KeepItemsInView" | ||
Grid.Column="0" | ||
Clicked="ItemsUpdatingScrollMode_Clicked" | ||
HorizontalOptions="Center" | ||
VerticalOptions="Center"/> | ||
<Button Text="KeepScrollOffset" | ||
AutomationId="26810ScrollOffsetButton" | ||
x:Name="KeepScrollOffset" | ||
Grid.Column="1" | ||
Clicked="ItemsUpdatingScrollMode_Clicked" | ||
HorizontalOptions="Center" | ||
VerticalOptions="Center"/> | ||
<Button Text="KeepLastItemInView" | ||
AutomationId="26810LastItemButton" | ||
x:Name="KeepLastItemInView" | ||
Grid.Column="2" | ||
Clicked="ItemsUpdatingScrollMode_Clicked" | ||
HorizontalOptions="Center" | ||
VerticalOptions="Center"/> | ||
</Grid> | ||
<Button Text="Scroll to Random Item" | ||
AutomationId="26810Button" | ||
x:Name="ScrollToButton" | ||
Grid.Row="1" | ||
Clicked="ScrollToButton_Clicked" | ||
HorizontalOptions="Center" | ||
VerticalOptions="Center"/> | ||
<Button Text="Add New Item" | ||
AutomationId="26810AddButton" | ||
x:Name="AddButton" | ||
Grid.Row="2" | ||
Clicked="AddButton_Clicked" | ||
HorizontalOptions="Center" | ||
VerticalOptions="Center"/> | ||
<cv1:CollectionView1 x:Name="CollectionView" | ||
AutomationId="26810CollectionView" | ||
Grid.Row="3"> | ||
<cv1:CollectionView1.ItemsLayout> | ||
<LinearItemsLayout ItemSpacing="5" | ||
Orientation="Horizontal"/> | ||
</cv1:CollectionView1.ItemsLayout> | ||
<cv1:CollectionView1.ItemTemplate> | ||
<DataTemplate> | ||
<Grid HeightRequest="50"> | ||
<Label Text="{Binding Name}" | ||
AutomationId="{Binding AutomationId}" | ||
VerticalOptions="Center" | ||
HorizontalOptions="Center"/> | ||
</Grid> | ||
</DataTemplate> | ||
</cv1:CollectionView1.ItemTemplate> | ||
</cv1:CollectionView1> | ||
</Grid> | ||
</ContentPage> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System.Collections.ObjectModel; | ||
|
||
namespace Maui.Controls.Sample.Issues; | ||
[Issue(IssueTracker.Github, 26810, "Scroll To first item in CollectionView when updating the collection with KeepItemsInView", | ||
PlatformAffected.Android)] | ||
public partial class Issue26810 : ContentPage | ||
{ | ||
private ObservableCollection<Issue26810ItemModel> Items { get; set; } = new ObservableCollection<Issue26810ItemModel>(); | ||
public Issue26810() | ||
{ | ||
InitializeComponent(); | ||
for (int i = 1; i <= 30; i++) | ||
{ | ||
Items.Add(new Issue26810ItemModel { Name = $"Preloaded Item {i}", AutomationId = $"Item{i}" }); | ||
} | ||
CollectionView.ItemsSource = Items; | ||
this.BindingContext = this; | ||
} | ||
|
||
private void ItemsUpdatingScrollMode_Clicked(object sender, EventArgs e) | ||
{ | ||
var button = (Button)sender; | ||
if (button.Text == "KeepScrollOffset") | ||
{ | ||
CollectionView.ItemsUpdatingScrollMode = ItemsUpdatingScrollMode.KeepScrollOffset; | ||
} | ||
else if (button.Text == "KeepLastItemInView") | ||
{ | ||
CollectionView.ItemsUpdatingScrollMode = ItemsUpdatingScrollMode.KeepLastItemInView; | ||
} | ||
} | ||
|
||
private void AddButton_Clicked(object sender, EventArgs e) | ||
{ | ||
Items.Add(new Issue26810ItemModel { Name = $"Item {Items.Count + 1}", AutomationId = $"Item{Items.Count + 1}" }); | ||
} | ||
private void ScrollToButton_Clicked(object sender, EventArgs e) | ||
{ | ||
if (Items.Count > 0) | ||
{ | ||
// Scroll to random item | ||
CollectionView.ScrollTo(19, position: ScrollToPosition.End, animate: true); | ||
} | ||
} | ||
} | ||
|
||
public class Issue26810ItemModel | ||
{ | ||
public string Name { get; set; } | ||
public string AutomationId { get; set; } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?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" | ||
xmlns:cv1="clr-namespace:Maui.Controls.Sample" | ||
x:Class="Maui.Controls.Sample.Issues.Issue26810Vertical"> | ||
<Grid RowDefinitions="50,50,50,*" | ||
AutomationId="26810MainGrid"> | ||
<Grid Grid.Row="0" | ||
ColumnDefinitions="*,*,*"> | ||
<Button Text="KeepItemsInView" | ||
AutomationId="26810FirstItemButton" | ||
x:Name="KeepItemsInView" | ||
Grid.Column="0" | ||
Clicked="ItemsUpdatingScrollMode_Clicked" | ||
HorizontalOptions="Center" | ||
VerticalOptions="Center"/> | ||
<Button Text="KeepScrollOffset" | ||
AutomationId="26810ScrollOffsetButton" | ||
x:Name="KeepScrollOffset" | ||
Grid.Column="1" | ||
Clicked="ItemsUpdatingScrollMode_Clicked" | ||
HorizontalOptions="Center" | ||
VerticalOptions="Center"/> | ||
<Button Text="KeepLastItemInView" | ||
AutomationId="26810LastItemButton" | ||
x:Name="KeepLastItemInView" | ||
Grid.Column="2" | ||
Clicked="ItemsUpdatingScrollMode_Clicked" | ||
HorizontalOptions="Center" | ||
VerticalOptions="Center"/> | ||
</Grid> | ||
<Button Text="Scroll to Random Item" | ||
AutomationId="26810Button" | ||
x:Name="ScrollToButton" | ||
Grid.Row="1" | ||
Clicked="ScrollToButton_Clicked" | ||
HorizontalOptions="Center" | ||
VerticalOptions="Center"/> | ||
<Button Text="Add New Item" | ||
AutomationId="26810AddButton" | ||
x:Name="AddButton" | ||
Grid.Row="2" | ||
Clicked="AddButton_Clicked" | ||
HorizontalOptions="Center" | ||
VerticalOptions="Center"/> | ||
<cv1:CollectionView1 x:Name="CollectionView" | ||
AutomationId="26810CollectionView" | ||
Grid.Row="3"> | ||
<cv1:CollectionView1.ItemTemplate> | ||
<DataTemplate> | ||
<Grid HeightRequest="50"> | ||
<Label Text="{Binding Name}" | ||
AutomationId="{Binding AutomationId}" | ||
VerticalOptions="Center" | ||
HorizontalOptions="Center"/> | ||
</Grid> | ||
</DataTemplate> | ||
</cv1:CollectionView1.ItemTemplate> | ||
</cv1:CollectionView1> | ||
</Grid> | ||
</ContentPage> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System.Collections.ObjectModel; | ||
|
||
namespace Maui.Controls.Sample.Issues; | ||
|
||
[Issue(IssueTracker.None, 26810, "Scroll To first item in CollectionView with vertical orientation when updating the collection with KeepItemsInView", | ||
PlatformAffected.Android)] | ||
|
||
public partial class Issue26810Vertical : ContentPage | ||
{ | ||
|
||
private ObservableCollection<Issue26810ItemModel> Items { get; set; } = new ObservableCollection<Issue26810ItemModel>(); | ||
public Issue26810Vertical() | ||
{ | ||
InitializeComponent(); | ||
for (int i = 1; i <= 30; i++) | ||
{ | ||
Items.Add(new Issue26810ItemModel { Name = $"Preloaded Item {i}", AutomationId = $"Item{i}" }); | ||
} | ||
CollectionView.ItemsSource = Items; | ||
this.BindingContext = this; | ||
} | ||
private void ItemsUpdatingScrollMode_Clicked(object sender, EventArgs e) | ||
{ | ||
var button = (Button)sender; | ||
if (button.Text == "KeepScrollOffset") | ||
{ | ||
CollectionView.ItemsUpdatingScrollMode = ItemsUpdatingScrollMode.KeepScrollOffset; | ||
} | ||
else if (button.Text == "KeepLastItemInView") | ||
{ | ||
CollectionView.ItemsUpdatingScrollMode = ItemsUpdatingScrollMode.KeepLastItemInView; | ||
} | ||
} | ||
|
||
private void AddButton_Clicked(object sender, EventArgs e) | ||
{ | ||
Items.Add(new Issue26810ItemModel { Name = $"Item {Items.Count + 1}", AutomationId = $"Item{Items.Count + 1}" }); | ||
} | ||
private void ScrollToButton_Clicked(object sender, EventArgs e) | ||
{ | ||
if (Items.Count > 0) | ||
{ | ||
// Scroll to random item | ||
CollectionView.ScrollTo(19, position: ScrollToPosition.End, animate: true); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,6 @@ public CollectionViewItemsUpdatingScrollModeUITests(TestDevice device) | |
|
||
protected override bool ResetAfterEachTest => true; | ||
|
||
#if TEST_FAILS_ON_WINDOWS // For more information, see :https://github.com/dotnet/maui/issues/28006 | ||
// KeepScrollOffset (src\Compatibility\ControlGallery\src\Issues.Shared\CollectionViewItemsUpdatingScrollMode.cs) | ||
[Test] | ||
[Category(UITestCategories.CollectionView)] | ||
jsuarezruiz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
@@ -27,12 +26,13 @@ public void KeepItemsInView() | |
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test is failing on CV2 iOS:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @jsuarezruiz, The |
||
for (int n = 0; n < 25; n++) | ||
{ | ||
App.Click("AddItemAbove"); | ||
App.WaitForElement("AddItemAbove"); | ||
App.Tap("AddItemAbove"); | ||
} | ||
|
||
App.WaitForElement("Vegetables.jpg, 10"); | ||
App.WaitForNoElement("Vegetables.jpg, 10"); | ||
} | ||
#endif | ||
|
||
|
||
#if TEST_FAILS_ON_IOS && TEST_FAILS_ON_CATALYST // The test fails on iOS and macOS because Appium is unable to locate the Picker control elements resulting in a TimeoutException. For more information, see: https://github.com/dotnet/maui/issues/28024 | ||
// KeepScrollOffset (src\Compatibility\ControlGallery\src\Issues.Shared\CollectionViewItemsUpdatingScrollMode.cs) | ||
|
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.
These CollectionView tests are failing:

The App is crashing. Could you check if are related with the changes?
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.
Hi @jsuarezruiz Yes, the crash is due to the
DataObserver
included forKeepItemsInView
. I have modifiedElementAt()
andDetermineTargetPosition
. Please review the changes and let us know if you have any concerns.