-
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 VerticalOffset Update When Modifying CollectionView.ItemsSource While Scrolled #26782
Open
devanathan-vaithiyanathan
wants to merge
15
commits into
dotnet:main
Choose a base branch
from
devanathan-vaithiyanathan:fix-21708
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.
+151
−16
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b21b146
fix vertical offset issue
devanathan-vaithiyanathan 7df30a5
fix added
devanathan-vaithiyanathan 9c88612
codes optimized
devanathan-vaithiyanathan 0056c96
test cases added
devanathan-vaithiyanathan 5877d3d
comments removed
devanathan-vaithiyanathan a2e0d06
test case modified
devanathan-vaithiyanathan 33b7c9c
test case modified
devanathan-vaithiyanathan 792570d
test case modified
devanathan-vaithiyanathan b9bbf71
comments updated
devanathan-vaithiyanathan 6d9465e
issue link added
devanathan-vaithiyanathan 6cb67a5
modified test case
devanathan-vaithiyanathan 2176454
modified a test case
devanathan-vaithiyanathan 14e2f9d
modified a test case
devanathan-vaithiyanathan e6dda65
iOS Offset fix added
devanathan-vaithiyanathan 1d9d4b0
issue string modified
devanathan-vaithiyanathan 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
69 changes: 69 additions & 0 deletions
69
src/Controls/tests/TestCases.HostApp/Issues/Issue21708.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,69 @@ | ||
<?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:controls="clr-namespace:Maui.Controls.Sample.Issues" | ||
x:Class="Maui.Controls.Sample.Issues.Issue21708"> | ||
|
||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition /> | ||
</Grid.RowDefinitions> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition /> | ||
<ColumnDefinition /> | ||
<ColumnDefinition /> | ||
</Grid.ColumnDefinitions> | ||
|
||
<Button | ||
Grid.Row="0" | ||
Grid.Column="0" | ||
Margin="10" | ||
AutomationId="Fill" | ||
Clicked="FillButton_OnClicked" | ||
Text="Fill" /> | ||
|
||
<Button | ||
Grid.Row="0" | ||
Grid.Column="2" | ||
Margin="10" | ||
AutomationId="Empty" | ||
Clicked="EmptyButton_OnClicked" | ||
Text="Empty" /> | ||
|
||
<Label | ||
Grid.Row="1" | ||
Grid.Column="0" | ||
AutomationId="VerticalOffsetLabel" | ||
Text="VerticalOffset: " /> | ||
|
||
<Label AutomationId="Label" | ||
Grid.ColumnSpan="2" | ||
Grid.Row="1" | ||
HorizontalTextAlignment="Start" | ||
Grid.Column="1" | ||
Text="{Binding VerticalOffset}" /> | ||
|
||
<CollectionView AutomationId="CollectionView" | ||
x:Name="CollectionView" | ||
Grid.Row="2" | ||
Grid.Column="0" | ||
Grid.ColumnSpan="3" | ||
ItemsSource="{Binding Items}" | ||
Scrolled="CollectionView_OnScrolled"> | ||
<CollectionView.ItemTemplate> | ||
<DataTemplate> | ||
<Label | ||
Margin="10" | ||
FontSize="Default" | ||
HeightRequest="20" | ||
HorizontalTextAlignment="Center" | ||
Text="{Binding .}" | ||
TextColor="RoyalBlue" /> | ||
</DataTemplate> | ||
</CollectionView.ItemTemplate> | ||
</CollectionView> | ||
</Grid> | ||
|
||
</ContentPage> |
52 changes: 52 additions & 0 deletions
52
src/Controls/tests/TestCases.HostApp/Issues/Issue21708.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,52 @@ | ||
using System.Collections.ObjectModel; | ||
|
||
namespace Maui.Controls.Sample.Issues | ||
{ | ||
[XamlCompilation(XamlCompilationOptions.Compile)] | ||
[Issue(IssueTracker.Github, 21708, "CollectionView.Scrolled event offset isn't correctly reset when items change", PlatformAffected.All)] | ||
public partial class Issue21708 : ContentPage | ||
{ | ||
ObservableCollection<int> _items; | ||
double _verticalOffset; | ||
|
||
public Issue21708() | ||
{ | ||
InitializeComponent(); | ||
_items = new ObservableCollection<int>(); | ||
AddItemsToCollectionView(); | ||
CollectionView.ItemsSource = _items; | ||
BindingContext = this; | ||
} | ||
|
||
public double VerticalOffset | ||
{ | ||
get => _verticalOffset; | ||
set | ||
{ | ||
_verticalOffset = value; | ||
OnPropertyChanged(nameof(VerticalOffset)); | ||
} | ||
} | ||
|
||
void CollectionView_OnScrolled(object sender, ItemsViewScrolledEventArgs e) | ||
{ | ||
VerticalOffset = e.VerticalOffset; | ||
} | ||
|
||
void EmptyButton_OnClicked(object sender, EventArgs e) | ||
{ | ||
_items.Clear(); | ||
} | ||
|
||
void FillButton_OnClicked(object sender, EventArgs e) | ||
{ | ||
AddItemsToCollectionView(); | ||
} | ||
|
||
void AddItemsToCollectionView() | ||
{ | ||
foreach (var i in Enumerable.Range(0, 50)) | ||
_items.Add(i); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue21708.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,23 @@ | ||
using NUnit.Framework; | ||
using UITest.Appium; | ||
using UITest.Core; | ||
|
||
namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
||
public class Issue21708 : _IssuesUITest | ||
{ | ||
public Issue21708(TestDevice device) : base(device) { } | ||
|
||
public override string Issue => "CollectionView.Scrolled event offset isn't correctly reset when items change"; | ||
|
||
[Test] | ||
[Category(UITestCategories.CollectionView)] | ||
public void VerifyCollectionViewVerticalOffset() | ||
{ | ||
App.WaitForElement("Fill"); | ||
App.ScrollDown("CollectionView"); | ||
Assert.That(App.FindElement("Label").GetText(), Is.GreaterThan("0")); | ||
App.Tap("Empty"); | ||
Assert.That(App.FindElement("Label").GetText(), Is.EqualTo("0")); | ||
} | ||
} |
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.
The test is failing on Android:
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, I ran the test on my local machine, and it passed successfully.