KEMBAR78
Fix CarouselView layout constraint issues on Mac Catalyst by Copilot · Pull Request #30714 · dotnet/maui · GitHub
Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 18, 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!

Fixes #22417

Summary

This PR addresses layout constraint issues for CarouselView on Mac Catalyst where the control could exceed its layout constraints, causing layout problems when items are added dynamically.

Changes

1. CarouselViewHandler.iOS.cs - Layout Constraint Fix

Modified the GetDesiredSize method to properly clamp the returned size to the provided constraints:

public override Size GetDesiredSize(double widthConstraint, double heightConstraint)
{
    var size = this.GetDesiredSizeFromHandler(widthConstraint, heightConstraint);

    // Clamp size to constraints to prevent exceeding them on Mac Catalyst
    if (!double.IsInfinity(widthConstraint) && size.Width > widthConstraint)
    {
        size.Width = widthConstraint;
    }

    if (!double.IsInfinity(heightConstraint) && size.Height > heightConstraint)
    {
        size.Height = heightConstraint;
    }

    return size;
}

Before: The method directly returned the result from GetDesiredSizeFromHandler(), which could exceed layout constraints.

After: The method now ensures that if width or height constraints are not infinite and the calculated size exceeds them, the size is clamped to the constraints.

2. Issue22417.cs - Test Update

Removed && TEST_FAILS_ON_CATALYST from the test preprocessor directive:

// Before
#if TEST_FAILS_ON_WINDOWS && TEST_FAILS_ON_CATALYST

// After  
#if TEST_FAILS_ON_WINDOWS

This allows the test to run on Mac Catalyst since the layout constraint fix should resolve the issue described in the test case.

Testing

The test case Issue22417 demonstrates the issue where adding items to a CarouselView with HeightRequest="250" and HorizontalOptions="Center" would not display properly due to layout constraint violations. With this fix, the CarouselView respects its layout constraints and displays newly added items correctly.

Impact

  • ✅ Fixes layout constraint issues on Mac Catalyst
  • ✅ Potentially improves layout behavior on iOS as well
  • ✅ No breaking changes to public API
  • ✅ Minimal, surgical changes focused on the specific issue

This pull request was created as a result of the following prompt from Copilot chat.

Full diff for PR #30622:


1. src/Controls/src/Core/Handlers/Items/CarouselViewHandler.iOS.cs

  • Fixes how GetDesiredSize returns its value to ensure size never exceeds constraints on Mac Catalyst (and possibly iOS).
  • Now, if width or height constraints are not infinite and the calculated size exceeds them, the size is clamped to the constraints. This addresses layout issues described in the related test case.

2. src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue22417.cs

  • Removes && TEST_FAILS_ON_CATALYST from the test preprocessor directive, reflecting that the test should now pass on Catalyst with the fix.

3. Add Public API Unshipped files

  • Adds the contents of src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt and src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt as shown above. These document API surface changes for the .NET and .NET Standard targets.

No other files are changed.


This PR addresses layout constraint issues for CarouselView on Mac Catalyst as described in Issue #22417 and updates the test definition for that issue. It also includes the required unshipped API files for .NET and .NET Standard.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@PureWeen PureWeen added this to the .NET 9 SR10 milestone Jul 18, 2025
@PureWeen PureWeen added p/0 Work that we can't release without area-controls-collectionview CollectionView, CarouselView, IndicatorView labels Jul 18, 2025
@Copilot Copilot AI changed the title [WIP] [iOS/MacCatalyst] Clamp CarouselView size to explicit constraints and update Issue22417 test Fix CarouselView layout constraint issues on Mac Catalyst Jul 18, 2025
Copilot finished work on behalf of mattleibow July 18, 2025 15:36
@Copilot Copilot AI requested a review from mattleibow July 18, 2025 15:36
@mattleibow
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen PureWeen marked this pull request as ready for review July 18, 2025 22:52
@Copilot Copilot AI review requested due to automatic review settings July 18, 2025 22:52
@PureWeen PureWeen requested a review from a team as a code owner July 18, 2025 22:52
@PureWeen PureWeen requested a review from jsuarezruiz July 18, 2025 22:52
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes layout constraint issues for CarouselView on Mac Catalyst where the control could exceed its layout bounds, causing display problems when items are dynamically added. The fix ensures the CarouselView respects its size constraints by clamping the calculated size to the provided width and height constraints.

  • Implements size clamping logic in CarouselViewHandler to prevent exceeding layout constraints
  • Enables the related test case to run on Mac Catalyst since the issue is now resolved
  • Provides a targeted fix that maintains API compatibility while addressing the specific layout problem

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Controls/src/Core/Handlers/Items/CarouselViewHandler.iOS.cs Adds size clamping logic to GetDesiredSize method to prevent exceeding width/height constraints
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue22417.cs Removes TEST_FAILS_ON_CATALYST condition to enable test execution on Mac Catalyst

{
var size = this.GetDesiredSizeFromHandler(widthConstraint, heightConstraint);

// Clamp size to constraints to prevent exceeding them on Mac Catalyst
Copy link

Copilot AI Jul 18, 2025

Choose a reason for hiding this comment

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

The comment suggests this fix is Mac Catalyst-specific, but the code applies to both iOS and Mac Catalyst platforms since this is the shared iOS handler. Consider updating the comment to reflect that this fix applies to both platforms or clarify the platform-specific behavior.

Suggested change
// Clamp size to constraints to prevent exceeding them on Mac Catalyst
// Clamp size to constraints to prevent exceeding them on both iOS and Mac Catalyst platforms

Copilot uses AI. Check for mistakes.

Copy link
Member

@rmarinho rmarinho left a comment

Choose a reason for hiding this comment

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

The test is failing on Catalyst. AddItemsToCarouselViewWorks needs the screenshot

AddItemsToCarouselViewWorks

@github-project-automation github-project-automation bot moved this from Todo to Changes Requested in MAUI SDK Ongoing Jul 22, 2025
@Copilot
Copy link
Contributor Author

Copilot AI commented Jul 23, 2025

The test is failing on Catalyst. AddItemsToCarouselViewWorks needs the screenshot

...

The missing screenshot has been added in commit 3b7aed4. The test should now pass on Mac Catalyst with the expected screenshot for the AddItemsToCarouselViewWorks test case.

@Copilot Copilot AI requested a review from rmarinho July 23, 2025 11:03
Copilot finished work on behalf of rmarinho July 23, 2025 11:03
@PureWeen PureWeen modified the milestones: .NET 9 SR10, .NET 9 SR11 Aug 4, 2025
@rmarinho
Copy link
Member

rmarinho commented Aug 6, 2025

/rebase

Copilot AI and others added 2 commits August 6, 2025 09:19
Co-authored-by: mattleibow <1096616+mattleibow@users.noreply.github.com>
@github-actions github-actions bot force-pushed the copilot/fix-0091d8ec-ccc7-4c3c-a033-7efeb66d3be4 branch from 3b7aed4 to 189f2e4 Compare August 6, 2025 09:19
@dotnet dotnet deleted a comment from azure-pipelines bot Aug 6, 2025
@rmarinho
Copy link
Member

rmarinho commented Aug 6, 2025

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@rmarinho rmarinho moved this from Changes Requested to Approved in MAUI SDK Ongoing Aug 6, 2025
@PureWeen PureWeen changed the base branch from main to inflight/current August 13, 2025 06:09
@PureWeen PureWeen merged commit a58463b into inflight/current Aug 13, 2025
124 of 130 checks passed
@PureWeen PureWeen deleted the copilot/fix-0091d8ec-ccc7-4c3c-a033-7efeb66d3be4 branch August 13, 2025 06:10
@github-project-automation github-project-automation bot moved this from Approved to Done in MAUI SDK Ongoing Aug 13, 2025
github-actions bot pushed a commit that referenced this pull request Aug 15, 2025
* Initial plan

* Fix CarouselView layout constraint issues on Mac Catalyst

Co-authored-by: mattleibow <1096616+mattleibow@users.noreply.github.com>

* Add missing image

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: mattleibow <1096616+mattleibow@users.noreply.github.com>
Co-authored-by: Rui Marinho <me@ruimarinho.net>
github-actions bot pushed a commit that referenced this pull request Aug 15, 2025
* Initial plan

* Fix CarouselView layout constraint issues on Mac Catalyst

Co-authored-by: mattleibow <1096616+mattleibow@users.noreply.github.com>

* Add missing image

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: mattleibow <1096616+mattleibow@users.noreply.github.com>
Co-authored-by: Rui Marinho <me@ruimarinho.net>
github-actions bot pushed a commit that referenced this pull request Aug 19, 2025
* Initial plan

* Fix CarouselView layout constraint issues on Mac Catalyst

Co-authored-by: mattleibow <1096616+mattleibow@users.noreply.github.com>

* Add missing image

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: mattleibow <1096616+mattleibow@users.noreply.github.com>
Co-authored-by: Rui Marinho <me@ruimarinho.net>
github-actions bot pushed a commit that referenced this pull request Aug 22, 2025
* Initial plan

* Fix CarouselView layout constraint issues on Mac Catalyst

Co-authored-by: mattleibow <1096616+mattleibow@users.noreply.github.com>

* Add missing image

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: mattleibow <1096616+mattleibow@users.noreply.github.com>
Co-authored-by: Rui Marinho <me@ruimarinho.net>
@github-actions github-actions bot locked and limited conversation to collaborators Sep 12, 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 p/0 Work that we can't release without

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[MAUI] The list does not show newly added recipes

4 participants