Skip to content

Fixed CollectionView's HeaderTemplate is not rendering in iOS and MacCatalyst platform. #27466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Feb 6, 2025

Conversation

KarthikRajaKalaimani
Copy link
Contributor

@KarthikRajaKalaimani KarthikRajaKalaimani commented Jan 30, 2025

Issue Details:

Test Case 1 : CollectionViewHeaderTemplateAndFooterTemplateDontWork failed in iOS and Catalyst platform.

Description:
The HeaderTemplate is not visible in the collection view when a button is directly assigned to the HeaderTemplate property of the CollectionView.

Code example :
The Button is directly load to HeaderTemplate of the CollectionView.
<CollectionView.HeaderTemplate> <DataTemplate> <Button HorizontalOptions="Center" Margin="12,24" Text="Add Item" AutomationId="AddItem" Clicked="AddItem" /> </DataTemplate> </CollectionView.HeaderTemplate>

Test Case 2 : HeaderFooterStringWorks failed in iOS and Catalyst platform.

Description : The footer string is not visible in the collection view when both the header and footer strings are set.

Code Example :
<CollectionView x:Name="CollectionView" Header="Just a string as a header" Footer="This footer is also a string"> </CollectionView>

Root Cause:

Test case 1 :

By default, the UIButton is wrapped in a WrapperView, meaning the PlatformView of the button is the WrapperView. However, when accessing the renderer.PlatformView in the Realize method of the TemplateHelpers class, the incorrect PlatformView is returned. It should return the WrapperView, not the UIButton. As a result, the UIButton is removed from the WrapperView and added as a subview of the CollectionView. Once added, the button’s cross-platform measurement is skipped during layout calculation because, while measuring the WrapperView, the subview’s size is 0.

Test case 2 :

In the HeaderFooterStringWorks test sample, the string is directly assigned to the Header and Footer properties of the CollectionView . In the Maui source code, while positioning the header and footer, the height is get from the formsElement height. If the formsElement is null, the height is set to 0. In this case, the formsElement was null, resulting in the header and footer having a height of 0.

Description of Change:

Test case 1 :

To resolve this, I called the renderer.ToPlatform() method in the Realize method of the TemplateHelpers class. The ToPlatform() method ensures that if the view handler has a container view (the WrapperView), it returns that; if not, it returns the correct PlatformView. This ensures that the WrapperView is added as a subview of the CollectionView and that the button’s cross-platform measurement is not skipped during the layout calculation.

Test case 2 :

The fix introduces a conditional check: if the Header or Footer is a View, it uses _headerViewFormsElement or _footerViewFormsElement (converted to platform-specific view) for height calculation. For string or template-based headers/footers, it continues to use _headerUIView or _footerUIView.

This approach ensures accurate height measurements for all types of headers and footers, particularly addressing the issue with dynamically added View-based items, while maintaining correct functionality for string and template-based options.

Tested the behavior in the following platforms.

  • Android
  • Windows
  • iOS
  • Mac

Test Case:

Enabled the CollectionViewHeaderTemplateAndFooterTemplateDontWork and HeaderFooterStringWorks test cases across all platforms.

Reference:

N/A

Issues Fixed:

Fixes #27177 #27264

Screenshots

Test Case 1 :

Before After
Before-27177_Testcase1 After-27177_TestCase1

Test Case 2 :

Before After
Before-27177_TestCase2 After-27177_TestCase2

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Jan 30, 2025
Copy link
Contributor

Hey there @KarthikRajaKalaimani! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@karthikraja-arumugam karthikraja-arumugam added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Jan 30, 2025
Indentation issue resolved.
@jsuarezruiz jsuarezruiz added area-controls-collectionview CollectionView, CarouselView, IndicatorView platform/iOS 🍎 labels Jan 30, 2025
@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@@ -15,7 +15,6 @@ public CollectionViewHeaderAndFooterTests(TestDevice device)
{
}

#if TEST_FAILS_ON_IOS && TEST_FAILS_ON_CATALYST // Header not rendering issue: https://github.com/dotnet/maui/issues/27177
[Test]
[Category(UITestCategories.CollectionView)]
public void HeaderFooterStringWorks()
Copy link
Contributor

Choose a reason for hiding this comment

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

Pending snapshots:
image
Already available in the latest build. Could you commit the images?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pending snapshots: image Already available in the latest build. Could you commit the images?

@jsuarezruiz I mistakenly enabled all the test cases in HeaderAndFooter.cs, which resulted in unnecessary snapshots being generated. I've reverted those changes and now only enabled the test case relevant to this issue, which does not require a snapshot. Could you please review the changes and let me know if you have any concerns?

@KarthikRajaKalaimani KarthikRajaKalaimani marked this pull request as ready for review February 4, 2025 10:37
@KarthikRajaKalaimani KarthikRajaKalaimani requested a review from a team as a code owner February 4, 2025 10:37
@jsuarezruiz
Copy link
Contributor

/rebase

@PureWeen
Copy link
Member

PureWeen commented Feb 6, 2025

/azp run

@PureWeen PureWeen added this to the .NET 9 SR4 milestone Feb 6, 2025
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

Copy link
Member

@PureWeen PureWeen left a comment

Choose a reason for hiding this comment

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

This looks good!

I put the CV inside a grid on the issue so it's not hidden by the notch.

The changes here are basically just reverting the changes here https://github.com/dotnet/maui/pull/21812/files#diff-3aafb0e01895bc2a4eb5a498ef5a511ce5482284956febfb20d3a04908ecab67R173-R174 for some scenarios.

@PureWeen
Copy link
Member

PureWeen commented Feb 6, 2025

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen
Copy link
Member

PureWeen commented Feb 6, 2025

  • failing tests are unrelated

@PureWeen PureWeen merged commit 2746c46 into dotnet:main Feb 6, 2025
112 of 123 checks passed
@Zhanglirong-Winnie
Copy link

Hi. @PureWeen
I verified this issue on the latest nightly 9.0.40-ci.main.25108.1 and it has been fixed. Thank you for everything.
But I have another question to confirm with you. The header and footer are displayed in the center on iOS and Mac Catalyst. But on Android and Windows, they are displayed on the left. Is this expected?
iOS & MacCatalyst:
Screenshot 2025-02-08 170728
Android & Windows:
image

@PureWeen
Copy link
Member

Hi. @PureWeen I verified this issue on the latest nightly 9.0.40-ci.main.25108.1 and it has been fixed. Thank you for everything. But I have another question to confirm with you. The header and footer are displayed in the center on iOS and Mac Catalyst. But on Android and Windows, they are displayed on the left. Is this expected? iOS & MacCatalyst: Screenshot 2025-02-08 170728 Android & Windows: image

No, can you log a bug

And just validate this isn't something that regressed on iOS?

@Zhanglirong-Winnie
Copy link

Hi, @PureWeen
Thanks for your reply, I created bug to track this issue #27738. It is not a regression issue for iOS and MacOS.
The issue also repro on 9.0.40 & 9.0.0 & 8.0.100 & 8.0.3

@github-actions github-actions bot locked and limited conversation to collaborators Mar 15, 2025
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 🍎
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[Testing] Tests failing on iOS/Catalyst
6 participants