-
Notifications
You must be signed in to change notification settings - Fork 2k
[Android, Windows] Fix CarouselView PreviousPosition/PreviousItem incorrect during animated ScrollTo() #34570
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
Merged
kubaflo
merged 6 commits into
dotnet:inflight/current
from
praveenkumarkarunanithi:29544-fix
Mar 28, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9949e7c
fix and test update
praveenkumarkarunanithi 7b278bb
updating test and fix for windows
praveenkumarkarunanithi 374db59
Update CarouselViewHandler.Windows.cs
praveenkumarkarunanithi 964fea5
Update CarouselViewHandler.Windows.cs
praveenkumarkarunanithi 0cd6fdc
Update MauiCarouselRecyclerView.cs
praveenkumarkarunanithi e6bb4bf
Update MauiCarouselRecyclerView.cs
praveenkumarkarunanithi 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 hidden or 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 hidden or 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
1 change: 1 addition & 0 deletions
1
src/Controls/src/Core/PublicAPI/net-windows/PublicAPI.Unshipped.txt
This file contains hidden or 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 |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| #nullable enable | ||
| ~override Microsoft.Maui.Controls.Handlers.Items.CarouselViewHandler.ScrollTo(Microsoft.Maui.Controls.ScrollToRequestEventArgs args) -> System.Threading.Tasks.Task | ||
| override Microsoft.Maui.Controls.Shapes.Shape.OnPropertyChanged(string? propertyName = null) -> void |
152 changes: 152 additions & 0 deletions
152
src/Controls/tests/TestCases.HostApp/Issues/Issue29544.cs
This file contains hidden or 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,152 @@ | ||
| using System.Collections.ObjectModel; | ||
|
|
||
| namespace Maui.Controls.Sample.Issues; | ||
|
|
||
| [Issue(IssueTracker.Github, 29544, | ||
| "PreviousItem and PreviousPosition not updating correctly on ScrollTo or Position set", | ||
| PlatformAffected.Android | PlatformAffected.UWP)] | ||
| public class Issue29544 : ContentPage | ||
| { | ||
| readonly CarouselView _carouselView; | ||
| readonly ObservableCollection<string> _items; | ||
| readonly Label _previousItemLabel; | ||
| readonly Label _previousPositionLabel; | ||
| readonly Label _currentItemLabel; | ||
| readonly Label _currentPositionLabel; | ||
|
|
||
| public Issue29544() | ||
| { | ||
| _items = new ObservableCollection<string> | ||
| { | ||
| "Item 1", | ||
| "Item 2", | ||
| "Item 3", | ||
| "Item 4", | ||
| "Item 5" | ||
| }; | ||
|
|
||
| _currentItemLabel = new Label | ||
| { | ||
| AutomationId = "CurrentItemLabel", | ||
| Text = "Current Item: Item 1" | ||
| }; | ||
|
|
||
| _previousItemLabel = new Label | ||
| { | ||
| AutomationId = "PreviousItemLabel", | ||
| Text = "Previous Item: none" | ||
| }; | ||
|
|
||
| _currentPositionLabel = new Label | ||
| { | ||
| AutomationId = "CurrentPositionLabel", | ||
| Text = "Current Position: 0" | ||
| }; | ||
|
|
||
| _previousPositionLabel = new Label | ||
| { | ||
| AutomationId = "PreviousPositionLabel", | ||
| Text = "Previous Position: none" | ||
| }; | ||
|
|
||
| _carouselView = new CarouselView | ||
| { | ||
| AutomationId = "CarouselView", | ||
| Loop = false, | ||
| ItemsSource = _items, | ||
| ItemTemplate = new DataTemplate(() => | ||
| { | ||
| var label = new Label | ||
| { | ||
| FontSize = 24, | ||
| BackgroundColor = Colors.LightGray, | ||
| HorizontalOptions = LayoutOptions.Fill, | ||
| VerticalOptions = LayoutOptions.Center, | ||
| HorizontalTextAlignment = TextAlignment.Center | ||
| }; | ||
| label.SetBinding(Label.TextProperty, "."); | ||
| return label; | ||
| }) | ||
| }; | ||
|
|
||
| _carouselView.CurrentItemChanged += OnCurrentItemChanged; | ||
| _carouselView.PositionChanged += OnPositionChanged; | ||
|
|
||
| var scrollTo3Button = new Button | ||
| { | ||
| AutomationId = "ScrollTo3Button", | ||
| Text = "Scroll To 3" | ||
| }; | ||
| scrollTo3Button.Clicked += (s, e) => _carouselView.ScrollTo(3); | ||
|
|
||
| var scrollTo1Button = new Button | ||
| { | ||
| AutomationId = "ScrollTo1Button", | ||
| Text = "Scroll To 1" | ||
| }; | ||
| scrollTo1Button.Clicked += (s, e) => _carouselView.ScrollTo(1); | ||
|
|
||
| var setPosition3Button = new Button | ||
| { | ||
| AutomationId = "SetPosition3Button", | ||
| Text = "Set Position 3" | ||
| }; | ||
| setPosition3Button.Clicked += (s, e) => _carouselView.Position = 3; | ||
|
|
||
| var setPosition0Button = new Button | ||
| { | ||
| AutomationId = "SetPosition0Button", | ||
| Text = "Set Position 0" | ||
| }; | ||
| setPosition0Button.Clicked += (s, e) => _carouselView.Position = 0; | ||
|
|
||
| Content = new Grid | ||
| { | ||
| Padding = new Thickness(10), | ||
| RowDefinitions = | ||
| { | ||
| new RowDefinition { Height = GridLength.Auto }, | ||
| new RowDefinition { Height = GridLength.Star } | ||
| }, | ||
| Children = | ||
| { | ||
| new VerticalStackLayout | ||
| { | ||
| Spacing = 6, | ||
| Children = | ||
| { | ||
| _currentItemLabel, | ||
| _previousItemLabel, | ||
| _currentPositionLabel, | ||
| _previousPositionLabel, | ||
| new HorizontalStackLayout | ||
| { | ||
| Spacing = 8, | ||
| Children = { scrollTo3Button, scrollTo1Button } | ||
| }, | ||
| new HorizontalStackLayout | ||
| { | ||
| Spacing = 8, | ||
| Children = { setPosition3Button, setPosition0Button } | ||
| } | ||
| } | ||
| }, | ||
| _carouselView | ||
| } | ||
| }; | ||
|
|
||
| Grid.SetRow(_carouselView, 1); | ||
| } | ||
|
|
||
| void OnCurrentItemChanged(object sender, CurrentItemChangedEventArgs e) | ||
| { | ||
| _currentItemLabel.Text = $"Current Item: {e.CurrentItem}"; | ||
| _previousItemLabel.Text = $"Previous Item: {e.PreviousItem ?? "none"}"; | ||
| } | ||
|
|
||
| void OnPositionChanged(object sender, PositionChangedEventArgs e) | ||
| { | ||
| _currentPositionLabel.Text = $"Current Position: {e.CurrentPosition}"; | ||
| _previousPositionLabel.Text = $"Previous Position: {e.PreviousPosition}"; | ||
| } | ||
| } |
84 changes: 84 additions & 0 deletions
84
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29544.cs
This file contains hidden or 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,84 @@ | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
|
||
| public class Issue29544 : _IssuesUITest | ||
| { | ||
| public override string Issue => | ||
| "PreviousItem and PreviousPosition not updating correctly on ScrollTo or Position set"; | ||
|
|
||
| public Issue29544(TestDevice device) : base(device) { } | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.CarouselView)] | ||
| public void PreviousPositionUpdatesCorrectlyOnScrollTo() | ||
| { | ||
| App.WaitForElement("ScrollTo3Button"); | ||
| App.Tap("ScrollTo3Button"); | ||
|
|
||
| App.RetryAssert(() => | ||
| { | ||
| var currentPos = App.FindElement("CurrentPositionLabel").GetText(); | ||
| Assert.That(currentPos, Does.Contain("3"), | ||
| "CarouselView should reach position 3 after ScrollTo"); | ||
| }); | ||
|
|
||
| var previousPositionText = App.FindElement("PreviousPositionLabel").GetText(); | ||
| Assert.That(previousPositionText, Does.Contain("0"), | ||
| "After scrolling from position 0 to 3, PreviousPosition should be 0"); | ||
|
|
||
| var previousItemText = App.FindElement("PreviousItemLabel").GetText(); | ||
| Assert.That(previousItemText, Does.Contain("Item 1"), | ||
| "After scrolling from position 0 to 3, PreviousItem should be 'Item 1'"); | ||
|
|
||
| App.Tap("ScrollTo1Button"); | ||
|
|
||
| App.RetryAssert(() => | ||
| { | ||
| var currentPos = App.FindElement("CurrentPositionLabel").GetText(); | ||
| Assert.That(currentPos, Does.Contain("1"), | ||
| "CarouselView should reach position 1 after second ScrollTo"); | ||
| }); | ||
|
|
||
| var secondPreviousPosition = App.FindElement("PreviousPositionLabel").GetText(); | ||
| Assert.That(secondPreviousPosition, Does.Contain("3"), | ||
| "After scrolling from position 3 to 1, PreviousPosition should be 3"); | ||
|
|
||
| var secondPreviousItem = App.FindElement("PreviousItemLabel").GetText(); | ||
| Assert.That(secondPreviousItem, Does.Contain("Item 4"), | ||
| "After scrolling from position 3 to 1, PreviousItem should be 'Item 4'"); | ||
|
praveenkumarkarunanithi marked this conversation as resolved.
|
||
| } | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.CarouselView)] | ||
| public void PreviousPositionUpdatesCorrectlyOnSetPosition() | ||
| { | ||
| App.WaitForElement("SetPosition0Button"); | ||
| App.Tap("SetPosition0Button"); | ||
|
|
||
| App.RetryAssert(() => | ||
| { | ||
| var pos = App.FindElement("CurrentPositionLabel").GetText(); | ||
| Assert.That(pos, Does.Contain("0"), "CarouselView should be at position 0"); | ||
| }); | ||
|
|
||
| App.Tap("SetPosition3Button"); | ||
|
|
||
| App.RetryAssert(() => | ||
| { | ||
| var currentPos = App.FindElement("CurrentPositionLabel").GetText(); | ||
| Assert.That(currentPos, Does.Contain("3"), | ||
| "CarouselView should reach position 3 after setting Position = 3"); | ||
| }); | ||
|
|
||
| var previousPositionText = App.FindElement("PreviousPositionLabel").GetText(); | ||
| Assert.That(previousPositionText, Does.Contain("0"), | ||
| "After setting Position from 0 to 3, PreviousPosition should be 0"); | ||
|
|
||
| var previousItemText = App.FindElement("PreviousItemLabel").GetText(); | ||
| Assert.That(previousItemText, Does.Contain("Item 1"), | ||
| "After setting Position from 0 to 3, PreviousItem should be 'Item 1'"); | ||
|
praveenkumarkarunanithi marked this conversation as resolved.
|
||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.