Skip to content

[iOS/Mac] Fix CollectionView2 height not updating when ItemsSource changes - #38441

Merged
kubaflo merged 4 commits into
dotnet:inflight/currentfrom
SyedAbdulAzeemSF4852:fix-38276
Oct 21, 2026
Merged

kubaflo merged 4 commits into
dotnet:inflight/currentfrom
SyedAbdulAzeemSF4852:fix-38276

Conversation

@SyedAbdulAzeemSF4852

Copy link
Copy Markdown
Contributor

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

  • 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
  • iOS
  • Mac

Output

Before After
Before.mov
After.mov

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 38441

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 38441"

@dotnet-policy-service dotnet-policy-service Bot added the community ✨ Community Contribution label Sep 11, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Sep 11, 2026
MauiBot

This comment was marked as outdated.

@MauiBot MauiBot added s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix) s/agent-fix-pr-picked AI could not beat the PR fix - PR is the best among all candidates s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review) and removed s/agent-review-in-progress AI review is currently running for this PR labels Sep 11, 2026
@Tamilarasan-Paranthaman Tamilarasan-Paranthaman added platform/ios area-controls-collectionview CollectionView, CarouselView, IndicatorView labels Sep 18, 2026
@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Sep 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Note

🔍 /review started

AzDO build 15379537 is running for ios.

The s/agent-review-in-progress label stays on this PR while the run is active. The final recommendation and outcome labels are posted only after Gate, expert review, and Deep UI tests finish.

@MauiBot MauiBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expert Review — 1 findings

See inline comments for details.

MauiBot

This comment was marked as outdated.

@MauiBot MauiBot added s/agent-gate-failed AI could not verify tests catch the bug s/agent-fix-win AI found a better alternative fix than the PR and removed s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix) s/agent-fix-pr-picked AI could not beat the PR fix - PR is the best among all candidates labels Sep 18, 2026
@kubaflo

This comment has been minimized.

@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Oct 21, 2026
@azure-pipelines

Copy link
Copy Markdown
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.

Copilot stopped reviewing on behalf of SyedAbdulAzeemSF4852 due to an error October 21, 2026 11:38
@github-actions

Copy link
Copy Markdown
Contributor

/review gate was not started: another review or Gate is already running for this PR.

This command is not queued. Submit it again after the current run finishes.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

One or more issues must be addressed before approval.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment on lines +50 to +52
pointerHandled = _pointerGestureHandler.HasAnyPointerGestures() &&
ev.Action == MotionEventActions.Down &&
!_pointerGestureHandler.HasClickablePlatformViewInHierarchy;
@kubaflo
kubaflo merged commit abec789 into dotnet:inflight/current Oct 21, 2026
9 of 35 checks passed
kubaflo added a commit that referenced this pull request Oct 25, 2026
…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>
kubaflo added a commit that referenced this pull request Oct 26, 2026
…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>
github-actions Bot pushed a commit that referenced this pull request Oct 28, 2026
…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>
kubaflo pushed a commit that referenced this pull request Nov 3, 2026
<!-- 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">
|
kubaflo added a commit that referenced this pull request Nov 3, 2026
<!-- 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>
kubaflo pushed a commit that referenced this pull request Nov 11, 2026
…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.
-->
kubaflo pushed a commit that referenced this pull request Nov 11, 2026
…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.
-->
kubaflo pushed a commit that referenced this pull request Nov 13, 2026
…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.
-->
kubaflo pushed a commit that referenced this pull request Nov 16, 2026
…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.
-->
kubaflo pushed a commit that referenced this pull request Nov 16, 2026
…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.
-->
kubaflo pushed a commit that referenced this pull request Nov 17, 2026
…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.
-->
kubaflo pushed a commit that referenced this pull request Nov 18, 2026
…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.
-->
kubaflo pushed a commit that referenced this pull request Nov 18, 2026
…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.
-->
kubaflo pushed a commit that referenced this pull request Nov 18, 2026
…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.
-->
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-controls-collectionview CollectionView, CarouselView, IndicatorView community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/ios s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix) s/agent-review-in-progress AI review is currently running for this PR s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Mac][iOS] CollectionView does not shrink its rendered height after ItemsSource is updated with fewer items

6 participants