-
Notifications
You must be signed in to change notification settings - Fork 2k
[Android] Fix CollectionView items not resizing after orientation change on Shell pages #34420
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
Changes from 3 commits
5b6d844
309de37
a57a2fd
04b6b29
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,53 @@ | ||
| namespace Maui.Controls.Sample.Issues; | ||
|
|
||
| [Issue(IssueTracker.Github, 19667, "CollectionView contents not sizing correctly after orientation change", PlatformAffected.Android)] | ||
| public class Issue19667 : TestShell | ||
| { | ||
| protected override void Init() | ||
| { | ||
| ContentPage page1 = new ContentPage | ||
| { | ||
| Content = new Label | ||
| { | ||
| Text = "Page 1", | ||
| AutomationId = "Page1Label", | ||
| HorizontalOptions = LayoutOptions.Center, | ||
| VerticalOptions = LayoutOptions.Center | ||
| } | ||
| }; | ||
|
|
||
| var items = Enumerable.Range(0, 15).ToList(); | ||
|
|
||
| CollectionView collectionView = new CollectionView | ||
| { | ||
| AutomationId = "CollectionView19667", | ||
| ItemsSource = items, | ||
| ItemTemplate = new DataTemplate(() => | ||
| { | ||
| Label label = new Label | ||
| { | ||
| VerticalTextAlignment = TextAlignment.Center | ||
| }; | ||
| label.SetBinding(Label.TextProperty, new Binding(".", stringFormat: "Item {0}")); | ||
| label.SetBinding(AutomationIdProperty, new Binding(".", stringFormat: "CvItem{0}")); | ||
|
|
||
| Grid grid = new Grid | ||
| { | ||
| BackgroundColor = Colors.Beige, | ||
| Padding = new Thickness(20), | ||
| Margin = new Thickness(5, 2) | ||
| }; | ||
| grid.Add(label); | ||
| return grid; | ||
| }) | ||
| }; | ||
|
|
||
| ContentPage page2 = new ContentPage | ||
| { | ||
| Content = collectionView | ||
| }; | ||
|
|
||
| AddFlyoutItem(page1, "Page1"); | ||
| AddFlyoutItem(page2, "CollectionViewPage"); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| #if ANDROID || IOS // The test fails on Windows and MacCatalyst because the SetOrientation method, which is intended to change the device orientation, is only supported on mobile platforms iOS and Android. | ||
|
SyedAbdulAzeemSF4852 marked this conversation as resolved.
Collaborator
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. [moderate] UI Test Applicability - This regression is for an Android-only handler fix and the HostApp issue page is marked |
||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
|
||
| public class Issue19667 : _IssuesUITest | ||
| { | ||
| public Issue19667(TestDevice device) : base(device) | ||
| { | ||
| } | ||
|
|
||
| public override string Issue => "CollectionView contents not sizing correctly after orientation change"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.CollectionView)] | ||
| public void CollectionViewItemsSizeCorrectlyAfterOrientationChange() | ||
| { | ||
| App.TapShellFlyoutIcon(); | ||
| App.Tap("CollectionViewPage"); | ||
| App.WaitForElement("CollectionView19667"); | ||
| App.WaitForElement("CvItem0"); | ||
|
|
||
| var portraitWidth = App.WaitForElement("CvItem0").GetRect().Width; | ||
|
|
||
| App.TapShellFlyoutIcon(); | ||
| App.Tap("Page1"); | ||
| App.WaitForElement("Page1Label"); | ||
|
|
||
| App.SetOrientationLandscape(); | ||
|
|
||
| App.TapShellFlyoutIcon(); | ||
| App.Tap("CollectionViewPage"); | ||
| App.WaitForElement("CollectionView19667"); | ||
| App.WaitForElement("CvItem0"); | ||
|
|
||
| var landscapeWidth = App.WaitForElement("CvItem0").GetRect().Width; | ||
| Assert.That(landscapeWidth, Is.GreaterThan(portraitWidth), | ||
| "CollectionView items should resize to landscape width after orientation change."); | ||
| } | ||
|
|
||
| [TearDown] | ||
| public void TearDown() | ||
| { | ||
| App.SetOrientationPortrait(); | ||
| } | ||
| } | ||
| #endif | ||
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.
[moderate] Regression Prevention and Test Coverage - The production fix adds
ClearMeasureCache()specifically for the AndroidMeasureFirstItemstatic-size cache, but this test leavesCollectionView.ItemSizingStrategyat its default (MeasureAllItems). That means the regression only exercises the visible-childForceLayout()path and does not cover the adapter_sizecache invalidation added in this PR. Please setItemSizingStrategy = ItemSizingStrategy.MeasureFirstItemhere, or add a second case, so the test would fail ifStructuredItemsViewAdapter.ClearMeasureCache()regresses.