Repository navigation
[iOS/Mac] Fix CollectionView2 height not updating when ItemsSource changes - #38441
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 38441Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 38441" |
|
Hey there @@SyedAbdulAzeemSF4852! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Note 🔍
|
MauiBot
left a comment
There was a problem hiding this comment.
Expert Review — 1 findings
See inline comments for details.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command. |
|
| pointerHandled = _pointerGestureHandler.HasAnyPointerGestures() && | ||
| ev.Action == MotionEventActions.Down && | ||
| !_pointerGestureHandler.HasClickablePlatformViewInHierarchy; |
c47eea0 to
e230623
Compare
…anges (#38441) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ### Issue Details - On Mac Catalyst and iOS, when a CollectionView is initially populated with a larger number of items, it expands and reports a larger rendered height through the SizeChanged event. If the ItemsSource is subsequently updated with fewer items, the CollectionView retains the previously measured height instead of recalculating and shrinking to match the new content size. ### Root Cause - InvalidateMeasureIfContentSizeChanged() ran in ViewWillLayoutSubviews(), where CV2's compositional layout could still expose the previous content size because estimated, self-sizing cells had not completed layout. Once UIKit produced the updated size later in the layout pass, MAUI received no subsequent measure invalidation and retained the stale CollectionView height. ### Description of Change - Moved the CV2 content-size check to ViewDidLayoutSubviews() so MAUI invalidates and remeasures the CollectionView after UIKit has updated the compositional layout's content size. Added the ViewDidLayoutSubviews override to ItemsViewController2 and updated the public API files for iOS and Mac Catalyst. ### Issues Fixed Fixes #38276 ### Validated the behaviour in the following platforms - [ ] Windows - [ ] Android - [x] iOS - [x] Mac ### Output | Before | After | |----------|----------| | <video src="https://github.com/user-attachments/assets/bd45e97e-0915-4296-9fb0-cf5845cabfaf"> | <video src="https://github.com/user-attachments/assets/503bd075-9031-4029-b2aa-b84c39be8fb9"> | --------- Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…anges (#38441) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ### Issue Details - On Mac Catalyst and iOS, when a CollectionView is initially populated with a larger number of items, it expands and reports a larger rendered height through the SizeChanged event. If the ItemsSource is subsequently updated with fewer items, the CollectionView retains the previously measured height instead of recalculating and shrinking to match the new content size. ### Root Cause - InvalidateMeasureIfContentSizeChanged() ran in ViewWillLayoutSubviews(), where CV2's compositional layout could still expose the previous content size because estimated, self-sizing cells had not completed layout. Once UIKit produced the updated size later in the layout pass, MAUI received no subsequent measure invalidation and retained the stale CollectionView height. ### Description of Change - Moved the CV2 content-size check to ViewDidLayoutSubviews() so MAUI invalidates and remeasures the CollectionView after UIKit has updated the compositional layout's content size. Added the ViewDidLayoutSubviews override to ItemsViewController2 and updated the public API files for iOS and Mac Catalyst. ### Issues Fixed Fixes #38276 ### Validated the behaviour in the following platforms - [ ] Windows - [ ] Android - [x] iOS - [x] Mac ### Output | Before | After | |----------|----------| | <video src="https://github.com/user-attachments/assets/bd45e97e-0915-4296-9fb0-cf5845cabfaf"> | <video src="https://github.com/user-attachments/assets/503bd075-9031-4029-b2aa-b84c39be8fb9"> | --------- Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…anges (#38441) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ### Issue Details - On Mac Catalyst and iOS, when a CollectionView is initially populated with a larger number of items, it expands and reports a larger rendered height through the SizeChanged event. If the ItemsSource is subsequently updated with fewer items, the CollectionView retains the previously measured height instead of recalculating and shrinking to match the new content size. ### Root Cause - InvalidateMeasureIfContentSizeChanged() ran in ViewWillLayoutSubviews(), where CV2's compositional layout could still expose the previous content size because estimated, self-sizing cells had not completed layout. Once UIKit produced the updated size later in the layout pass, MAUI received no subsequent measure invalidation and retained the stale CollectionView height. ### Description of Change - Moved the CV2 content-size check to ViewDidLayoutSubviews() so MAUI invalidates and remeasures the CollectionView after UIKit has updated the compositional layout's content size. Added the ViewDidLayoutSubviews override to ItemsViewController2 and updated the public API files for iOS and Mac Catalyst. ### Issues Fixed Fixes #38276 ### Validated the behaviour in the following platforms - [ ] Windows - [ ] Android - [x] iOS - [x] Mac ### Output | Before | After | |----------|----------| | <video src="https://github.com/user-attachments/assets/bd45e97e-0915-4296-9fb0-cf5845cabfaf"> | <video src="https://github.com/user-attachments/assets/503bd075-9031-4029-b2aa-b84c39be8fb9"> | --------- Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
<!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ### Description of Change - Reverts all changes introduced by #38441 to address the iOS nested-scrolling regression reported in #39847. - The original change moved the content-size check from ViewWillLayoutSubviews() to ViewDidLayoutSubviews(). With this timing change, the existing bounds-based condition could skip remeasurement when both the previous and updated content heights exceeded the CollectionView's current bounds. This could leave the CollectionView independently scrollable inside its parent ScrollView, producing two vertical scrollbars. - This revert restores the check to ViewWillLayoutSubviews(), removes the added ViewDidLayoutSubviews() override and its iOS/MacCatalyst API entries, and removes the four test/sample files introduced by the original PR. ### Issues Fixed Fixes #39847 ### Output | Before | After | |----------|----------| | <video src="https://github.com/user-attachments/assets/42415724-f289-4da2-b6fc-988c20a435db"> | <video src="https://github.com/user-attachments/assets/ce64d764-4d56-4b20-8942-8e694b5bc0e4"> |
<!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ### Description of Change - Reverts all changes introduced by #38441 to address the iOS nested-scrolling regression reported in #39847. - The original change moved the content-size check from ViewWillLayoutSubviews() to ViewDidLayoutSubviews(). With this timing change, the existing bounds-based condition could skip remeasurement when both the previous and updated content heights exceeded the CollectionView's current bounds. This could leave the CollectionView independently scrollable inside its parent ScrollView, producing two vertical scrollbars. - This revert restores the check to ViewWillLayoutSubviews(), removes the added ViewDidLayoutSubviews() override and its iOS/MacCatalyst API entries, and removes the four test/sample files introduced by the original PR. ### Issues Fixed Fixes #39847 ### Output | Before | After | |----------|----------| | <video src="https://github.com/user-attachments/assets/42415724-f289-4da2-b6fc-988c20a435db"> | <video src="https://github.com/user-attachments/assets/ce64d764-4d56-4b20-8942-8e694b5bc0e4"> | Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…ed scrolling (#39882) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Description of Change <!-- Enter description of the fix in this section --> Fix CollectionView height updates after replacing ItemsSource with fewer items on iOS and Mac Catalyst, while preserving sizing behavior when CollectionView is nested inside ScrollView. In #38276, CollectionView retains its previously rendered height after the item count decreases, leaving unused space and stale Height/SizeChanged values. The previous fix, #38441, moved content-size checking exclusively to ViewDidLayoutSubviews. This introduced the nested-scroll regression reported in #39847: the CollectionView could remain smaller than its content, creating an additional vertical scroll range inside the outer ScrollView. That fix was reverted by #39856. This replacement builds on the reverted implementation: - Preserve the existing ViewWillLayoutSubviews content-size check. - Add a guarded ViewDidLayoutSubviews check to detect self-sizing content changes resolved during native layout, allowing the CollectionView to shrink. - Skip the post-layout check when content exceeds the current bounds in the scrolling direction, without updating the cached content size. This leaves growth detection to the pre-layout check and avoids the nested-scroll regression. - Refresh empty-source tracking when replacing ItemsSource so grouped collections collapsed to zero can grow again, even when UIKit defers data-source callbacks. - Restore the required iOS and Mac Catalyst public API entries for the layout callback override. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #38276 Related: #39847 — adds coverage to prevent reintroducing the nested-scroll regression already addressed by the revert. <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->
…ed scrolling (#39882) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Description of Change <!-- Enter description of the fix in this section --> Fix CollectionView height updates after replacing ItemsSource with fewer items on iOS and Mac Catalyst, while preserving sizing behavior when CollectionView is nested inside ScrollView. In #38276, CollectionView retains its previously rendered height after the item count decreases, leaving unused space and stale Height/SizeChanged values. The previous fix, #38441, moved content-size checking exclusively to ViewDidLayoutSubviews. This introduced the nested-scroll regression reported in #39847: the CollectionView could remain smaller than its content, creating an additional vertical scroll range inside the outer ScrollView. That fix was reverted by #39856. This replacement builds on the reverted implementation: - Preserve the existing ViewWillLayoutSubviews content-size check. - Add a guarded ViewDidLayoutSubviews check to detect self-sizing content changes resolved during native layout, allowing the CollectionView to shrink. - Skip the post-layout check when content exceeds the current bounds in the scrolling direction, without updating the cached content size. This leaves growth detection to the pre-layout check and avoids the nested-scroll regression. - Refresh empty-source tracking when replacing ItemsSource so grouped collections collapsed to zero can grow again, even when UIKit defers data-source callbacks. - Restore the required iOS and Mac Catalyst public API entries for the layout callback override. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #38276 Related: #39847 — adds coverage to prevent reintroducing the nested-scroll regression already addressed by the revert. <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->
…ed scrolling (#39882) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Description of Change <!-- Enter description of the fix in this section --> Fix CollectionView height updates after replacing ItemsSource with fewer items on iOS and Mac Catalyst, while preserving sizing behavior when CollectionView is nested inside ScrollView. In #38276, CollectionView retains its previously rendered height after the item count decreases, leaving unused space and stale Height/SizeChanged values. The previous fix, #38441, moved content-size checking exclusively to ViewDidLayoutSubviews. This introduced the nested-scroll regression reported in #39847: the CollectionView could remain smaller than its content, creating an additional vertical scroll range inside the outer ScrollView. That fix was reverted by #39856. This replacement builds on the reverted implementation: - Preserve the existing ViewWillLayoutSubviews content-size check. - Add a guarded ViewDidLayoutSubviews check to detect self-sizing content changes resolved during native layout, allowing the CollectionView to shrink. - Skip the post-layout check when content exceeds the current bounds in the scrolling direction, without updating the cached content size. This leaves growth detection to the pre-layout check and avoids the nested-scroll regression. - Refresh empty-source tracking when replacing ItemsSource so grouped collections collapsed to zero can grow again, even when UIKit defers data-source callbacks. - Restore the required iOS and Mac Catalyst public API entries for the layout callback override. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #38276 Related: #39847 — adds coverage to prevent reintroducing the nested-scroll regression already addressed by the revert. <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->
…ed scrolling (#39882) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Description of Change <!-- Enter description of the fix in this section --> Fix CollectionView height updates after replacing ItemsSource with fewer items on iOS and Mac Catalyst, while preserving sizing behavior when CollectionView is nested inside ScrollView. In #38276, CollectionView retains its previously rendered height after the item count decreases, leaving unused space and stale Height/SizeChanged values. The previous fix, #38441, moved content-size checking exclusively to ViewDidLayoutSubviews. This introduced the nested-scroll regression reported in #39847: the CollectionView could remain smaller than its content, creating an additional vertical scroll range inside the outer ScrollView. That fix was reverted by #39856. This replacement builds on the reverted implementation: - Preserve the existing ViewWillLayoutSubviews content-size check. - Add a guarded ViewDidLayoutSubviews check to detect self-sizing content changes resolved during native layout, allowing the CollectionView to shrink. - Skip the post-layout check when content exceeds the current bounds in the scrolling direction, without updating the cached content size. This leaves growth detection to the pre-layout check and avoids the nested-scroll regression. - Refresh empty-source tracking when replacing ItemsSource so grouped collections collapsed to zero can grow again, even when UIKit defers data-source callbacks. - Restore the required iOS and Mac Catalyst public API entries for the layout callback override. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #38276 Related: #39847 — adds coverage to prevent reintroducing the nested-scroll regression already addressed by the revert. <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->
…ed scrolling (#39882) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Description of Change <!-- Enter description of the fix in this section --> Fix CollectionView height updates after replacing ItemsSource with fewer items on iOS and Mac Catalyst, while preserving sizing behavior when CollectionView is nested inside ScrollView. In #38276, CollectionView retains its previously rendered height after the item count decreases, leaving unused space and stale Height/SizeChanged values. The previous fix, #38441, moved content-size checking exclusively to ViewDidLayoutSubviews. This introduced the nested-scroll regression reported in #39847: the CollectionView could remain smaller than its content, creating an additional vertical scroll range inside the outer ScrollView. That fix was reverted by #39856. This replacement builds on the reverted implementation: - Preserve the existing ViewWillLayoutSubviews content-size check. - Add a guarded ViewDidLayoutSubviews check to detect self-sizing content changes resolved during native layout, allowing the CollectionView to shrink. - Skip the post-layout check when content exceeds the current bounds in the scrolling direction, without updating the cached content size. This leaves growth detection to the pre-layout check and avoids the nested-scroll regression. - Refresh empty-source tracking when replacing ItemsSource so grouped collections collapsed to zero can grow again, even when UIKit defers data-source callbacks. - Restore the required iOS and Mac Catalyst public API entries for the layout callback override. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #38276 Related: #39847 — adds coverage to prevent reintroducing the nested-scroll regression already addressed by the revert. <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->
…ed scrolling (#39882) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Description of Change <!-- Enter description of the fix in this section --> Fix CollectionView height updates after replacing ItemsSource with fewer items on iOS and Mac Catalyst, while preserving sizing behavior when CollectionView is nested inside ScrollView. In #38276, CollectionView retains its previously rendered height after the item count decreases, leaving unused space and stale Height/SizeChanged values. The previous fix, #38441, moved content-size checking exclusively to ViewDidLayoutSubviews. This introduced the nested-scroll regression reported in #39847: the CollectionView could remain smaller than its content, creating an additional vertical scroll range inside the outer ScrollView. That fix was reverted by #39856. This replacement builds on the reverted implementation: - Preserve the existing ViewWillLayoutSubviews content-size check. - Add a guarded ViewDidLayoutSubviews check to detect self-sizing content changes resolved during native layout, allowing the CollectionView to shrink. - Skip the post-layout check when content exceeds the current bounds in the scrolling direction, without updating the cached content size. This leaves growth detection to the pre-layout check and avoids the nested-scroll regression. - Refresh empty-source tracking when replacing ItemsSource so grouped collections collapsed to zero can grow again, even when UIKit defers data-source callbacks. - Restore the required iOS and Mac Catalyst public API entries for the layout callback override. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #38276 Related: #39847 — adds coverage to prevent reintroducing the nested-scroll regression already addressed by the revert. <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->
…ed scrolling (#39882) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Description of Change <!-- Enter description of the fix in this section --> Fix CollectionView height updates after replacing ItemsSource with fewer items on iOS and Mac Catalyst, while preserving sizing behavior when CollectionView is nested inside ScrollView. In #38276, CollectionView retains its previously rendered height after the item count decreases, leaving unused space and stale Height/SizeChanged values. The previous fix, #38441, moved content-size checking exclusively to ViewDidLayoutSubviews. This introduced the nested-scroll regression reported in #39847: the CollectionView could remain smaller than its content, creating an additional vertical scroll range inside the outer ScrollView. That fix was reverted by #39856. This replacement builds on the reverted implementation: - Preserve the existing ViewWillLayoutSubviews content-size check. - Add a guarded ViewDidLayoutSubviews check to detect self-sizing content changes resolved during native layout, allowing the CollectionView to shrink. - Skip the post-layout check when content exceeds the current bounds in the scrolling direction, without updating the cached content size. This leaves growth detection to the pre-layout check and avoids the nested-scroll regression. - Refresh empty-source tracking when replacing ItemsSource so grouped collections collapsed to zero can grow again, even when UIKit defers data-source callbacks. - Restore the required iOS and Mac Catalyst public API entries for the layout callback override. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #38276 Related: #39847 — adds coverage to prevent reintroducing the nested-scroll regression already addressed by the revert. <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->
…ed scrolling (#39882) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Description of Change <!-- Enter description of the fix in this section --> Fix CollectionView height updates after replacing ItemsSource with fewer items on iOS and Mac Catalyst, while preserving sizing behavior when CollectionView is nested inside ScrollView. In #38276, CollectionView retains its previously rendered height after the item count decreases, leaving unused space and stale Height/SizeChanged values. The previous fix, #38441, moved content-size checking exclusively to ViewDidLayoutSubviews. This introduced the nested-scroll regression reported in #39847: the CollectionView could remain smaller than its content, creating an additional vertical scroll range inside the outer ScrollView. That fix was reverted by #39856. This replacement builds on the reverted implementation: - Preserve the existing ViewWillLayoutSubviews content-size check. - Add a guarded ViewDidLayoutSubviews check to detect self-sizing content changes resolved during native layout, allowing the CollectionView to shrink. - Skip the post-layout check when content exceeds the current bounds in the scrolling direction, without updating the cached content size. This leaves growth detection to the pre-layout check and avoids the nested-scroll regression. - Refresh empty-source tracking when replacing ItemsSource so grouped collections collapsed to zero can grow again, even when UIKit defers data-source callbacks. - Restore the required iOS and Mac Catalyst public API entries for the layout callback override. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #38276 Related: #39847 — adds coverage to prevent reintroducing the nested-scroll regression already addressed by the revert. <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->
…ed scrolling (#39882) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Description of Change <!-- Enter description of the fix in this section --> Fix CollectionView height updates after replacing ItemsSource with fewer items on iOS and Mac Catalyst, while preserving sizing behavior when CollectionView is nested inside ScrollView. In #38276, CollectionView retains its previously rendered height after the item count decreases, leaving unused space and stale Height/SizeChanged values. The previous fix, #38441, moved content-size checking exclusively to ViewDidLayoutSubviews. This introduced the nested-scroll regression reported in #39847: the CollectionView could remain smaller than its content, creating an additional vertical scroll range inside the outer ScrollView. That fix was reverted by #39856. This replacement builds on the reverted implementation: - Preserve the existing ViewWillLayoutSubviews content-size check. - Add a guarded ViewDidLayoutSubviews check to detect self-sizing content changes resolved during native layout, allowing the CollectionView to shrink. - Skip the post-layout check when content exceeds the current bounds in the scrolling direction, without updating the cached content size. This leaves growth detection to the pre-layout check and avoids the nested-scroll regression. - Refresh empty-source tracking when replacing ItemsSource so grouped collections collapsed to zero can grow again, even when UIKit defers data-source callbacks. - Restore the required iOS and Mac Catalyst public API entries for the layout callback override. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #38276 Related: #39847 — adds coverage to prevent reintroducing the nested-scroll regression already addressed by the revert. <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->

Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Issue Details
Root Cause
Description of Change
Issues Fixed
Fixes #38276
Validated the behaviour in the following platforms
Output
Before.mov
After.mov