Skip to content

Fix for iOS CollectionView2 ItemSizingStrategy="MeasureFirstItem" Fails to Apply Correct Sizing#29496

Merged
StephaneDelcroix merged 23 commits intodotnet:inflight/currentfrom
SuthiYuvaraj:fix-29130
Dec 2, 2025
Merged

Fix for iOS CollectionView2 ItemSizingStrategy="MeasureFirstItem" Fails to Apply Correct Sizing#29496
StephaneDelcroix merged 23 commits intodotnet:inflight/currentfrom
SuthiYuvaraj:fix-29130

Conversation

@SuthiYuvaraj
Copy link
Contributor

@SuthiYuvaraj SuthiYuvaraj commented May 14, 2025

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 Description

When CollectionView2 uses ItemSizingStrategy, the sizing does not update correctly on iOS and macOS platforms.

RootCause

In CollectionView2 , ItemsLayout is directly derived from UICollectionViewController , where the ItemSizing is not considered.

Description of Change

In TemplatedCell2 , each cell is measured by a override method called PreferredLayoutAttributesFittingAttributes which will determine the size of each at initial loading , I have restricted the measure for all items when ItemSizingStatergy is MeasureFirstItem and updated the dynamic changes from GetCell in ItemsViewController2.

Issues Fixed

Fixes #29130
Fixes #23304

Tested the behaviour in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Output Screenshot

Before Issue Fix After Issue Fix
ItemSizingBefore.mov
ItemSizeAfter.mov

@dotnet-policy-service dotnet-policy-service bot added community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration labels May 14, 2025
@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

}
}
}
public class CollectionViewViewModel
Copy link
Contributor

Choose a reason for hiding this comment

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

Modify this class to be something unique like Issue29130ViewModel.

/Users/builder/azdo/_work/1/s/src/Controls/tests/TestCases.HostApp/Issues/Issue29130.cs(88,14): error CS0101: The namespace 'Maui.Controls.Sample.Issues' already contains a definition for 'CollectionViewViewModel' [/Users/builder/azdo/_work/1/s/src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj::TargetFramework=net9.0-maccatalyst]
/Users/builder/azdo/_work/1/s/src/Controls/tests/TestCases.HostApp/Issues/Issue29130.cs(88,14): error CS0101: The namespace 'Maui.Controls.Sample.Issues' already contains a definition for 'CollectionViewViewModel' [/Users/builder/azdo/_work/1/s/src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj::TargetFramework=net9.0-tizen]
/Users/builder/azdo/_work/1/s/src/Controls/tests/TestCases.HostApp/Issues/Issue29130.cs(88,14): error CS0101: The namespace 'Maui.Controls.Sample.Issues' already contains a definition for 'CollectionViewViewModel' [/Users/builder/azdo/_work/1/s/src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj::TargetFramework=net9.0-ios]
/Users/builder/azdo/_work/1/s/src/Controls/tests/TestCases.HostApp/Issues/Issue29130.cs(88,14): error CS0101: The namespace 'Maui.Controls.Sample.Issues' already contains a definition for 'CollectionViewViewModel' [/Users/builder/azdo/_work/1/s/src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj::TargetFramework=net9.0-android]
    1 Warning(s)
    4 Error(s)

Copy link
Contributor

Choose a reason for hiding this comment

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

C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Issues\Issue29130.cs(88,14): error CS0101: The namespace 'Maui.Controls.Sample.Issues' already contains a definition for 'CollectionViewViewModel' [C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Controls.TestCases.HostApp.csproj::TargetFramework=net9.0-windows10.0.20348.0]
C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Issues\Issue29130.cs(88,14): error CS0101: The namespace 'Maui.Controls.Sample.Issues' already contains a definition for 'CollectionViewViewModel' [C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Controls.TestCases.HostApp.csproj::TargetFramework=net9.0-windows10.0.19041.0]
    2 Error(s)

Could you rename to Issue29130ViewMode?

@PureWeen PureWeen added this to the .NET 9 SR9 milestone Jun 9, 2025
@PureWeen PureWeen moved this from Todo to In Progress in MAUI SDK Ongoing Jun 9, 2025
@jsuarezruiz
Copy link
Contributor

/rebase

@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

}
}
}
public class CollectionViewViewModel
Copy link
Contributor

Choose a reason for hiding this comment

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

C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Issues\Issue29130.cs(88,14): error CS0101: The namespace 'Maui.Controls.Sample.Issues' already contains a definition for 'CollectionViewViewModel' [C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Controls.TestCases.HostApp.csproj::TargetFramework=net9.0-windows10.0.20348.0]
C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Issues\Issue29130.cs(88,14): error CS0101: The namespace 'Maui.Controls.Sample.Issues' already contains a definition for 'CollectionViewViewModel' [C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Controls.TestCases.HostApp.csproj::TargetFramework=net9.0-windows10.0.19041.0]
    2 Error(s)

Could you rename to Issue29130ViewMode?

@github-project-automation github-project-automation bot moved this from In Progress to Changes Requested in MAUI SDK Ongoing Jul 1, 2025
@PureWeen PureWeen modified the milestones: .NET 9 SR9, .NET 9 SR10 Jul 3, 2025
@SuthiYuvaraj
Copy link
Contributor Author

@jsuarezruiz, I have updated both the fix and the test case. Please review them and let me know if you have any feedback or concerns.

@SuthiYuvaraj SuthiYuvaraj marked this pull request as ready for review July 15, 2025 12:23
@SuthiYuvaraj SuthiYuvaraj requested a review from a team as a code owner July 15, 2025 12:23
@PureWeen PureWeen modified the milestones: .NET 9 SR10, .NET 9 SR11 Aug 4, 2025
@PureWeen PureWeen added platform/ios area-controls-collectionview CollectionView, CarouselView, IndicatorView labels Aug 7, 2025
@jsuarezruiz
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen PureWeen removed this from the .NET 9 SR11 milestone Sep 10, 2025
@sheiksyedm
Copy link
Contributor

/azp run MAUI-UITests-public

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@sheiksyedm
Copy link
Contributor

/azp run MAUI-UITests-public

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@SuthiYuvaraj
Copy link
Contributor Author

Can we move the firstItemMeasureSize reset call into "reloadData"?

I think all of the paths you have here will hit the reloadData call which will be a nice central place for this.

Hi @PureWeen , In ItemsViewController2, ReloadData is a native UICollectionView method, I’ve introduced an internal method called Reload(). The firstItemMeasureSize cache is being reset inside ReloadData, and since all relevant paths eventually invoke reloadData, the reset is handled centrally there. Please review this approach and let me know if you have any concerns.

@sheiksyedm sheiksyedm moved this from Changes Requested to Ready To Review in MAUI SDK Ongoing Nov 25, 2025
@StephaneDelcroix StephaneDelcroix changed the base branch from main to inflight/current December 2, 2025 15:58
@StephaneDelcroix StephaneDelcroix merged commit 0a09df4 into dotnet:inflight/current Dec 2, 2025
128 of 163 checks passed
@github-project-automation github-project-automation bot moved this from Ready To Review to Done in MAUI SDK Ongoing Dec 2, 2025
PureWeen pushed a commit that referenced this pull request Dec 3, 2025
…ls to Apply Correct Sizing (#29496)

* Fix for ItemSizing issue

* Update ItemsViewController2.cs

* Update TemplatedCell2.cs

* Update TemplatedCell2.cs

* Update TemplatedCell2.cs

* commit for itemsize

* unwanted changes

* commit for testcases

* Update Issue29130.cs

* ItemSizingStatergy changes

* Update ItemsViewController2.cs

* Update TemplatedCell2.cs

* Changes for review

* Update TemplatedCell2.cs

* Update src/Controls/src/Core/Handlers/Items2/iOS/TemplatedCell2.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29130.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update TemplatedCell2.cs

* Update TemplatedCell2.cs

* Update Issue29130.cs

* commit for template testcases

* Handler changes

* Update ItemsViewHandler2.iOS.cs

* Changes on ReloadData

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
PureWeen pushed a commit that referenced this pull request Dec 3, 2025
…ls to Apply Correct Sizing (#29496)

* Fix for ItemSizing issue

* Update ItemsViewController2.cs

* Update TemplatedCell2.cs

* Update TemplatedCell2.cs

* Update TemplatedCell2.cs

* commit for itemsize

* unwanted changes

* commit for testcases

* Update Issue29130.cs

* ItemSizingStatergy changes

* Update ItemsViewController2.cs

* Update TemplatedCell2.cs

* Changes for review

* Update TemplatedCell2.cs

* Update src/Controls/src/Core/Handlers/Items2/iOS/TemplatedCell2.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29130.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update TemplatedCell2.cs

* Update TemplatedCell2.cs

* Update Issue29130.cs

* commit for template testcases

* Handler changes

* Update ItemsViewHandler2.iOS.cs

* Changes on ReloadData

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
PureWeen pushed a commit that referenced this pull request Dec 3, 2025
…ls to Apply Correct Sizing (#29496)

* Fix for ItemSizing issue

* Update ItemsViewController2.cs

* Update TemplatedCell2.cs

* Update TemplatedCell2.cs

* Update TemplatedCell2.cs

* commit for itemsize

* unwanted changes

* commit for testcases

* Update Issue29130.cs

* ItemSizingStatergy changes

* Update ItemsViewController2.cs

* Update TemplatedCell2.cs

* Changes for review

* Update TemplatedCell2.cs

* Update src/Controls/src/Core/Handlers/Items2/iOS/TemplatedCell2.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29130.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update TemplatedCell2.cs

* Update TemplatedCell2.cs

* Update Issue29130.cs

* commit for template testcases

* Handler changes

* Update ItemsViewHandler2.iOS.cs

* Changes on ReloadData

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
PureWeen pushed a commit that referenced this pull request Dec 3, 2025
…ls to Apply Correct Sizing (#29496)

* Fix for ItemSizing issue

* Update ItemsViewController2.cs

* Update TemplatedCell2.cs

* Update TemplatedCell2.cs

* Update TemplatedCell2.cs

* commit for itemsize

* unwanted changes

* commit for testcases

* Update Issue29130.cs

* ItemSizingStatergy changes

* Update ItemsViewController2.cs

* Update TemplatedCell2.cs

* Changes for review

* Update TemplatedCell2.cs

* Update src/Controls/src/Core/Handlers/Items2/iOS/TemplatedCell2.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29130.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update TemplatedCell2.cs

* Update TemplatedCell2.cs

* Update Issue29130.cs

* commit for template testcases

* Handler changes

* Update ItemsViewHandler2.iOS.cs

* Changes on ReloadData

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
PureWeen pushed a commit that referenced this pull request Dec 3, 2025
…ls to Apply Correct Sizing (#29496)

* Fix for ItemSizing issue

* Update ItemsViewController2.cs

* Update TemplatedCell2.cs

* Update TemplatedCell2.cs

* Update TemplatedCell2.cs

* commit for itemsize

* unwanted changes

* commit for testcases

* Update Issue29130.cs

* ItemSizingStatergy changes

* Update ItemsViewController2.cs

* Update TemplatedCell2.cs

* Changes for review

* Update TemplatedCell2.cs

* Update src/Controls/src/Core/Handlers/Items2/iOS/TemplatedCell2.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29130.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update TemplatedCell2.cs

* Update TemplatedCell2.cs

* Update Issue29130.cs

* commit for template testcases

* Handler changes

* Update ItemsViewHandler2.iOS.cs

* Changes on ReloadData

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
github-actions bot pushed a commit that referenced this pull request Dec 5, 2025
…ls to Apply Correct Sizing (#29496)

* Fix for ItemSizing issue

* Update ItemsViewController2.cs

* Update TemplatedCell2.cs

* Update TemplatedCell2.cs

* Update TemplatedCell2.cs

* commit for itemsize

* unwanted changes

* commit for testcases

* Update Issue29130.cs

* ItemSizingStatergy changes

* Update ItemsViewController2.cs

* Update TemplatedCell2.cs

* Changes for review

* Update TemplatedCell2.cs

* Update src/Controls/src/Core/Handlers/Items2/iOS/TemplatedCell2.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29130.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update TemplatedCell2.cs

* Update TemplatedCell2.cs

* Update Issue29130.cs

* commit for template testcases

* Handler changes

* Update ItemsViewHandler2.iOS.cs

* Changes on ReloadData

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@github-actions github-actions bot locked and limited conversation to collaborators Jan 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-controls-collectionview CollectionView, CarouselView, IndicatorView collectionview-cv2 community ✨ Community Contribution p/0 Current heighest priority issues that we are targeting for a release. partner/syncfusion Issues / PR's with Syncfusion collaboration platform/ios

Projects

Status: Done

6 participants