-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix CarouselView layout constraint issues on Mac Catalyst #30714
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
Fix CarouselView layout constraint issues on Mac Catalyst #30714
Conversation
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
There was a problem hiding this 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 |
Copilot
AI
Jul 18, 2025
There was a problem hiding this comment.
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.
| // 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... 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. |
|
/rebase |
Co-authored-by: mattleibow <1096616+mattleibow@users.noreply.github.com>
3b7aed4 to
189f2e4
Compare
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
* 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>
* 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>
* 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>
* 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>

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
GetDesiredSizemethod to properly clamp the returned size to the provided constraints: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_CATALYSTfrom the test preprocessor directive: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
Issue22417demonstrates the issue where adding items to a CarouselView withHeightRequest="250"andHorizontalOptions="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
This pull request was created as a result of the following prompt from Copilot chat.
💡 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.