dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.94k stars 1.7k forks source link

[iOS/Catalyst] CollectionView VisualDiagnostic Item Registration is broken #14506

Open drasticactions opened 1 year ago

drasticactions commented 1 year ago

Description

スクリーンショット 2023-04-11 16 58 02

When a CollectionView ItemsSource is populated, UI Items are generated and registered in VisualDiagnostics. On iOS and Mac Catalyst, the first item in the given ItemSource is added to multiple items. The underlying UICollectionView is not creating it, but it does appear in LogicalChildren and IVisualTreeElement.Children as Virtual items. These views also appear in the Live Visual Tree and are being registered with OnChildAdd.

I could only reproduce this on iOS and Catalyst.

Steps to Reproduce

Run my reproduction project: https://github.com/drasticactions/MauiRepros/tree/main/MauiCollectionView

Link to public reproduction project repository

https://github.com/drasticactions/MauiRepros/tree/main/MauiCollectionView

Version with bug

7.0 (current)

Last version that worked well

7.0 (current)

Affected platforms

iOS, macOS

Affected platform versions

All versions

Did you find any workaround?

No response

Relevant log output

No response

ghost commented 1 year ago

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

drasticactions commented 1 year ago

I think I understand what's going on here:

スクリーンショット 2023-04-20 17 32 20 スクリーンショット 2023-04-20 17 33 13

UpdateItemsSource is being called multiple times by the PropertyHandlers: Once for the ItemSource, once for IsGrouped, and each time those clear out the underlying cells from the internal _measurementCells list.

I believe the order of operations is this:

Because of that, the underlying cells get recreated and readded to the LogicalChildren list. So the underlying platform item is removed from the list but not the virtual one.

Ideally, these should only be made once. I am still trying to figure out the best way to handle this. It feels very load-bearing, and any change to this will cause something else to blow up.

@PureWeen Do you have any ideas?

homeyf commented 7 months ago

Verified this issue with VSM 17.6.7 (build 419). Can repro on iOS and maccatalyst platforms with sample project. https://github.com/drasticactions/MauiRepros/tree/main/MauiCollectionView image