-
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 for Try scrolling down and when new items are added the first item does not kept in the displayed list. #27153
Open
SuthiYuvaraj
wants to merge
14
commits into
dotnet:main
Choose a base branch
from
SuthiYuvaraj:fix-26810
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
14 commits
Select commit
Hold shift + click to select a range
cd7837e
Fix for 26810
SuthiYuvaraj ffd2647
Update ItemsViewLayout.cs
SuthiYuvaraj df7a2e3
TestCases for 26810
SuthiYuvaraj 03c9f3b
Update Issue26810.xaml
SuthiYuvaraj 085d924
Update Issue26810.xaml.cs
SuthiYuvaraj 1e9fcb9
Update Issue26810.cs
SuthiYuvaraj de4acfe
Update Issue26810.xaml
SuthiYuvaraj e14ce95
Update MauiRecyclerView.cs
SuthiYuvaraj 18a7878
Update ItemsViewLayout.cs
SuthiYuvaraj b5c54ff
Testcases changes
SuthiYuvaraj 3fe0b97
Commit for HorizontalChanges
SuthiYuvaraj 934c205
commit for testcase failure
SuthiYuvaraj 5ae698a
Update ItemsViewLayout.cs
SuthiYuvaraj 8116107
Update CollectionViewUITests.CollectionViewItemsUpdatingScrollMode.cs
SuthiYuvaraj 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
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
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
65 changes: 65 additions & 0 deletions
65
src/Controls/tests/TestCases.HostApp/Issues/Issue26810.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,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> |
51 changes: 51 additions & 0 deletions
51
src/Controls/tests/TestCases.HostApp/Issues/Issue26810.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,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; } | ||
} |
61 changes: 61 additions & 0 deletions
61
src/Controls/tests/TestCases.HostApp/Issues/Issue26810Vertical.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,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> |
47 changes: 47 additions & 0 deletions
47
src/Controls/tests/TestCases.HostApp/Issues/Issue26810Vertical.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,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); | ||
} | ||
} | ||
} |
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
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.
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.