-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android] Fix for unexpected CurrentItem updates in CarouselView when scroll animation is enabled #31875
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
Closed
SyedAbdulAzeemSF4852
wants to merge
6
commits into
dotnet:main
from
SyedAbdulAzeemSF4852:fix-carouselview-inconsistent-notify
Closed
[Android] Fix for unexpected CurrentItem updates in CarouselView when scroll animation is enabled #31875
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8aa8b54
[Android] Fix for incorrect intermediate CurrentItem updates when Car…
SyedAbdulAzeemSF4852 4280839
I've modified the test case and removed the iOS and Android snapshots
SyedAbdulAzeemSF4852 2be5375
Updated the fix and renamed file and class names to match the associa…
SyedAbdulAzeemSF4852 854181b
Modified the fix
SyedAbdulAzeemSF4852 dfb7c5a
Used constants for item values and removed redundant recyclerView nul…
SyedAbdulAzeemSF4852 99d3d84
Add clarifying comments for scroll detection behavior and known race …
SyedAbdulAzeemSF4852 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| using System.Collections.ObjectModel; | ||
| using System.ComponentModel; | ||
|
|
||
| namespace Maui.Controls.Sample.Issues; | ||
|
|
||
| [Issue(IssueTracker.Github, 31874, "Incorrect Intermediate CurrentItem updates with CarouselView Scroll Animation Enabled", PlatformAffected.Android)] | ||
| public class Issue31874 : ContentPage | ||
| { | ||
| const string InitialItem = "0"; | ||
| const string TargetItem = "4"; | ||
|
|
||
| Label resultStatus; | ||
| Label selectedItemLabel; | ||
| CarouselView carouselView; | ||
| public Issue31874() | ||
| { | ||
| carouselView = new CarouselView | ||
| { | ||
| HeightRequest = 150, | ||
| Loop = false, | ||
| IsScrollAnimated = true, | ||
| ItemsSource = new ObservableCollection<string>{ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11" }, | ||
|
||
| ItemTemplate = new DataTemplate(() => | ||
| { | ||
| Border border = new Border | ||
| { | ||
| BackgroundColor = Colors.LightGray, | ||
| Content = new Label | ||
| { | ||
| VerticalOptions = LayoutOptions.Center, | ||
| HorizontalOptions = LayoutOptions.Center, | ||
| FontSize = 80 | ||
| } | ||
| }; | ||
| border.Content.SetBinding(Label.TextProperty, "."); | ||
| return border; | ||
| }) | ||
| }; | ||
| carouselView.PropertyChanged += CarouselView_PropertyChanged; | ||
|
|
||
| selectedItemLabel = new Label | ||
| { | ||
| Text = $"Selected Item : {InitialItem}", | ||
| FontSize = 16 | ||
| }; | ||
|
|
||
| Button selectButton = new Button | ||
| { | ||
| AutomationId = "Issue31874ScrollBtn", | ||
| Text = $"Select item {TargetItem}", | ||
| FontSize = 12 | ||
| }; | ||
|
|
||
| selectButton.Clicked += (s, e) => | ||
| { | ||
| carouselView.CurrentItem = TargetItem; | ||
| selectedItemLabel.Text = $"Selected Item : {carouselView.CurrentItem}"; | ||
| }; | ||
|
|
||
| resultStatus = new Label | ||
| { | ||
| AutomationId = "Issue31874ResultLabel", | ||
| Text = "Success" | ||
| }; | ||
|
|
||
| Content = new VerticalStackLayout | ||
| { | ||
| Padding = 25, | ||
| Spacing = 15, | ||
| Children = | ||
| { | ||
| carouselView, | ||
| selectedItemLabel, | ||
| selectButton, | ||
| resultStatus | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| void CarouselView_PropertyChanged(object sender, PropertyChangedEventArgs e) | ||
| { | ||
| if (e.PropertyName == nameof(CarouselView.CurrentItem)) | ||
| { | ||
| var currentItemValue = carouselView.CurrentItem?.ToString(); | ||
|
|
||
| if (!string.IsNullOrEmpty(currentItemValue) && currentItemValue != InitialItem && | ||
| currentItemValue != TargetItem) | ||
| { | ||
| resultStatus.Text = "Failure"; | ||
| } | ||
| } | ||
| } | ||
| } | ||
27 changes: 27 additions & 0 deletions
27
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue31874.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,27 @@ | ||
| #if TEST_FAILS_ON_WINDOWS // Issue Link - https://github.com/dotnet/maui/issues/31670 | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
|
||
| public class Issue31874 : _IssuesUITest | ||
| { | ||
| public Issue31874(TestDevice device) : base(device) | ||
| { | ||
| } | ||
|
|
||
| public override string Issue => "Incorrect Intermediate CurrentItem updates with CarouselView Scroll Animation Enabled"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.CarouselView)] | ||
| public void VerifyCurrentItemUpdatesWithScrollAnimation() | ||
| { | ||
| App.WaitForElement("Issue31874ScrollBtn"); | ||
| App.Tap("Issue31874ScrollBtn"); | ||
|
|
||
| var resultLabel = App.WaitForElement("Issue31874ResultLabel").GetText(); | ||
| Assert.That(resultLabel, Is.EqualTo("Success")); | ||
| } | ||
| } | ||
| #endif |
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.