Repository navigation
[Windows] Fix grouped CollectionView item display in CollectionViewHandler2 #40607
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 all commits
a2b6af9
3178aaa
cbd7d4a
41848ba
a978a6e
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 |
|---|---|---|
|
|
@@ -348,6 +348,7 @@ internal partial class ElementWrapper : ContentControl | |
|
|
||
| // Stored so RecycleElement can unsubscribe without a flag — mirrors iOS prepareForReuse. | ||
| SizeChangedEventHandler? _contentSizeChangedHandler; | ||
| RoutedEventHandler? _contentUnloadedHandler; | ||
| FrameworkElement? _observedContent; | ||
| WAccessibilityView? _defaultAccessibilityView; | ||
| bool _semanticsRefreshAttached; | ||
|
|
@@ -369,17 +370,27 @@ internal bool TryAttachSemanticsRefresh() | |
| } | ||
|
|
||
| /// <summary> | ||
| /// Unsubscribes the first-item SizeChanged observer wired during MeasureOverride. | ||
| /// Unsubscribes the first-item SizeChanged and Unloaded observers wired during MeasureOverride. | ||
| /// Must be called from RecycleElement so a recycled wrapper cannot poison the global size cache. | ||
| /// </summary> | ||
| internal void UnwireContentSizeObserver() | ||
| { | ||
| if (_observedContent != null && _contentSizeChangedHandler != null) | ||
| if (_observedContent is not null) | ||
| { | ||
| _observedContent.SizeChanged -= _contentSizeChangedHandler; | ||
| _contentSizeChangedHandler = null; | ||
| _observedContent = null; | ||
| if (_contentSizeChangedHandler is not null) | ||
| { | ||
| _observedContent.SizeChanged -= _contentSizeChangedHandler; | ||
| } | ||
|
|
||
| if (_contentUnloadedHandler is not null) | ||
| { | ||
| _observedContent.Unloaded -= _contentUnloadedHandler; | ||
| } | ||
| } | ||
|
|
||
| _contentSizeChangedHandler = null; | ||
| _contentUnloadedHandler = null; | ||
| _observedContent = null; | ||
| } | ||
|
|
||
| public ElementWrapper(IMauiContext context) | ||
|
|
@@ -518,11 +529,19 @@ void OnContentUnloaded(object? sender, RoutedEventArgs e) | |
| element.SizeChanged -= OnContentSizeChanged; | ||
| element.Unloaded -= OnContentUnloaded; | ||
| } | ||
| _contentSizeChangedHandler = null; | ||
| _observedContent = null; | ||
|
|
||
| // A late unload from replaced content must not clear the current observer. | ||
| if (ReferenceEquals(_observedContent, sender)) | ||
|
Contributor
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] Regression Prevention and Test Coverage - No discriminating test protects this stale-sender guard or the replacement observer's lifecycle. |
||
| { | ||
| _contentSizeChangedHandler = null; | ||
| _contentUnloadedHandler = null; | ||
| _observedContent = null; | ||
| } | ||
| } | ||
| // Store delegate and content so RecycleElement can unsubscribe directly. | ||
| UnwireContentSizeObserver(); | ||
| // Store delegates and content so RecycleElement can unsubscribe directly. | ||
| _contentSizeChangedHandler = OnContentSizeChanged; | ||
| _contentUnloadedHandler = OnContentUnloaded; | ||
| _observedContent = content; | ||
| content.SizeChanged += OnContentSizeChanged; | ||
| content.Unloaded += OnContentUnloaded; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace Maui.Controls.Sample.Issues; | ||
|
|
||
| [Issue(IssueTracker.Github, 40414, "CollectionViewHandler2 does not display grouped CollectionView items after ItemsSource is reset", PlatformAffected.UWP)] | ||
| public class Issue40414 : Shell | ||
| { | ||
| public Issue40414() | ||
| { | ||
| FlyoutBehavior = FlyoutBehavior.Flyout; | ||
|
|
||
| Items.Add(new ShellContent | ||
| { | ||
| Title = "Flyout1Content", | ||
| ContentTemplate = new DataTemplate(() => new ContentPage | ||
| { | ||
| Content = new Label | ||
| { | ||
| Text = "Open Flyout2Content, return to Flyout1Content, then open Flyout2Content again. The grouped items should be visible.", | ||
| AutomationId = "Flyout1Label" | ||
| } | ||
| }) | ||
| }); | ||
|
|
||
| Items.Add(new ShellContent | ||
| { | ||
| Title = "Flyout2Content", | ||
| ContentTemplate = new DataTemplate(() => new Issue40414CollectionPage()) | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| class Issue40414CollectionPage : ContentPage | ||
| { | ||
| readonly CollectionView _collectionView; | ||
|
|
||
| public Issue40414CollectionPage() | ||
| { | ||
| _collectionView = new CollectionView | ||
| { | ||
| IsGrouped = true, | ||
| ItemSizingStrategy = ItemSizingStrategy.MeasureAllItems, | ||
| SelectionMode = SelectionMode.None, | ||
| AutomationId = "GroupedCollectionView", | ||
| ItemsLayout = new GridItemsLayout(5, ItemsLayoutOrientation.Vertical), | ||
| // A layout as the template root is required to reproduce the issue. | ||
| ItemTemplate = new DataTemplate(() => | ||
| { | ||
| var label = new Label(); | ||
| label.SetBinding(Label.TextProperty, "."); | ||
| return new HorizontalStackLayout { Children = { label } }; | ||
| }), | ||
| GroupHeaderTemplate = new DataTemplate(() => | ||
| { | ||
| var label = new Label(); | ||
| label.SetBinding(Label.TextProperty, nameof(Issue40414Group.GroupName)); | ||
| return new HorizontalStackLayout { Children = { new Label { Text = "Group: " }, label } }; | ||
| }) | ||
| }; | ||
|
|
||
| Padding = 16; | ||
| Content = _collectionView; | ||
| } | ||
|
|
||
| protected override void OnAppearing() | ||
| { | ||
| base.OnAppearing(); | ||
|
|
||
| _collectionView.ItemsSource = new List<Issue40414Group> | ||
| { | ||
| new Issue40414Group("1", ["A", "B", "C", "D", "E", "F", "G"]), | ||
| new Issue40414Group("2", ["A", "B", "C", "D", "E", "F", "G"]), | ||
| new Issue40414Group("3", ["A", "B", "C", "D", "E", "F", "G"]), | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| public class Issue40414Group : List<string> | ||
| { | ||
| public Issue40414Group(string groupName, List<string> items) : base(items) | ||
| { | ||
| GroupName = groupName; | ||
| } | ||
|
|
||
| public string GroupName { get; } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
|
||
| public class Issue40414 : _IssuesUITest | ||
| { | ||
| public override string Issue => "CollectionViewHandler2 does not display grouped CollectionView items after ItemsSource is reset"; | ||
|
|
||
| public Issue40414(TestDevice device) | ||
| : base(device) | ||
| { } | ||
|
|
||
| [Test] | ||
| [ShardedTestCategory(UITestCategories.CollectionView)] | ||
| public void GroupedItemsAreDisplayedAfterNavigatingBackToFlyoutPage() | ||
| { | ||
| App.WaitForElement("Flyout1Label"); | ||
|
|
||
| App.TapInShellFlyout("Flyout2Content"); | ||
| App.WaitForElement("GroupedCollectionView"); | ||
|
|
||
| App.TapInShellFlyout("Flyout1Content"); | ||
| App.WaitForElement("Flyout1Label"); | ||
|
|
||
| App.TapInShellFlyout("Flyout2Content"); | ||
| App.WaitForElement("GroupedCollectionView"); | ||
|
|
||
| VerifyScreenshot(retryTimeout: TimeSpan.FromSeconds(2)); | ||
|
devanathan-vaithiyanathan marked this conversation as resolved.
Resolved
devanathan-vaithiyanathan marked this conversation as resolved.
Resolved
devanathan-vaithiyanathan marked this conversation as resolved.
Resolved
Contributor
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] Regression Prevention and Test Coverage - The added baselines still omit two enabled configurations: |
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.