[iOS] Fixed the Items not displayed properly in CarouselView2#31336
[iOS] Fixed the Items not displayed properly in CarouselView2#31336PureWeen merged 7 commits intodotnet:inflight/currentfrom
Conversation
|
/azp run MAUI-UITests-public |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an issue where CarouselView2 items on iOS were not displaying updated content when the ItemsSource was modified from another page during navigation. The root cause was that the CollectionViewUpdated event handler was being unsubscribed when navigating away, leaving updates unhandled.
- Adds a mechanism to track when the view was detached from the window
- Refreshes visible items when re-attaching to the window after navigation
- Includes comprehensive UI tests to validate the fix across platforms
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Controls/src/Core/Handlers/Items2/iOS/CarouselViewController2.cs | Core fix: adds tracking for detachment state and refreshes visible items on re-attachment |
| src/Controls/tests/TestCases.HostApp/Issues/Issue31148.cs | UI test page implementing navigation scenario with ItemsSource updates |
| src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue31148.cs | NUnit test case validating the CarouselView update behavior |
src/Controls/src/Core/Handlers/Items2/iOS/CarouselViewController2.cs
Outdated
Show resolved
Hide resolved
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
/azp run MAUI-UITests-public |
|
Azure Pipelines successfully started running 1 pipeline(s). |
src/Controls/src/Core/Handlers/Items2/iOS/CarouselViewController2.cs
Outdated
Show resolved
Hide resolved
src/Controls/src/Core/Handlers/Items2/iOS/CarouselViewController2.cs
Outdated
Show resolved
Hide resolved
mattleibow
left a comment
There was a problem hiding this comment.
Thanks for this PR! The fix looks good overall and correctly addresses the root cause. However, there are a few small issues that need to be addressed:
-
Unnecessary array copy (lines 158-160): The defensive copy of
indexPathsis redundant since the ObjC binding already creates a managed copy viaCFArray.ArrayFromHandle<NSIndexPath>(). This adds
unnecessary memory allocation without providing the protection the comment suggests. -
Missing execution order comment: Please add a comment explaining why
RefreshVisibleItems()must be called BEFORESetup(ItemsView)in theAttachingToWindow()method. This is critical for future
maintainability. -
Comment spacing: Minor - add a space after
//on line 154 for consistency with the rest of the codebase.
Could you please address these issues? The logic is sound, just needs these small cleanup items before merging.
f08e6bb to
ce8f7d5
Compare
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [Microsoft.Maui.Controls](https://github.com/dotnet/maui) | nuget | patch | `10.0.20` -> `10.0.30` | --- ### Release Notes <details> <summary>dotnet/maui (Microsoft.Maui.Controls)</summary> ### [`v10.0.30`](https://github.com/dotnet/maui/releases/tag/10.0.30): SR3 [Compare Source](dotnet/maui@10.0.20...10.0.30) #### What's Changed .NET MAUI 10.0.30 introduces significant improvements across all platforms with focus on quality, performance, and developer experience. This release includes 106 commits with various improvements, bug fixes, and enhancements. #### .NET 10 Features - \[net10.0] Merge main to net10.0 by [@​PureWeen](https://github.com/PureWeen) in dotnet/maui#33323 #### CollectionView - Fixed the NRE in CarouselViewController on iOS 15.5 & 16.4 by [@​Ahamed-Ali](https://github.com/Ahamed-Ali) in dotnet/maui#30838 <details> <summary>🔧 Fixes</summary> - [NRE in CarouselViewController on iOS 15.5 & 16.4](dotnet/maui#28557) </details> - \[iOS, macOS] Fixed CollectionView group header size changes with ItemSizingStrategy by [@​NanthiniMahalingam](https://github.com/NanthiniMahalingam) in dotnet/maui#33161 <details> <summary>🔧 Fixes</summary> - [\[NET 10\] I6\_Grouping - Grouping_with_variable_sized_items changing the 'ItemSizingStrategy' also changes the header size.](dotnet/maui#33130) </details> - \[iOS]\[CV2] Fix page can be dragged down, and it would cause an extra space between Header and EmptyView text by [@​devanathan-vaithiyanathan](https://github.com/devanathan-vaithiyanathan) in dotnet/maui#31840 <details> <summary>🔧 Fixes</summary> - [I8\_Header_and_Footer_Null - The page can be dragged down, and it would cause an extra space between Header and EmptyView text.](dotnet/maui#31465) </details> - \[iOS] Fixed the Items not displayed properly in CarouselView2 by [@​Ahamed-Ali](https://github.com/Ahamed-Ali) in dotnet/maui#31336 <details> <summary>🔧 Fixes</summary> - [\[iOS\] Items are not updated properly in CarouselView2.](dotnet/maui#31148) </details> #### Docs - Add comprehensive README to Microsoft.Maui.Controls NuGet package by [@​jfversluis](https://github.com/jfversluis) via [@​Copilot](https://github.com/Copilot) in dotnet/maui#32835 <details> <summary>🔧 Fixes</summary> - [Improve the MAUI Nuget readme.md file](dotnet/maui#31969) </details> - Improve Controls Core API docs 2 by [@​jfversluis](https://github.com/jfversluis) in https://github.com/dotnet...
Root Cause of the issue
CollectionViewUpdatedmethod in CarouselViewController2 is not called when the ItemsSource is updated from another page, because CollectionViewUpdated is null at the time of invocation. When navigating away from the page, the event handler is unsubscribed, leaving it null. As a result, the replaced items were not reflected.Description of Change
Issues Fixed
Fixes #31148
Tested the behaviour in the following platforms
Screenshot
Cv2Issue.mov
CV2Fixed.mov