-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Change ComputeConstraintForView to return LayoutConstraint instead of using side effects #31091
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
Change ComputeConstraintForView to return LayoutConstraint instead of using side effects #31091
Conversation
| } | ||
|
|
||
| protected virtual void ComputeConstraintForView(View view) => view.ComputedConstraint = LayoutConstraint.None; | ||
| internal virtual LayoutConstraint ComputeConstraintForView(View view) => LayoutConstraint.None; |
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.
@copilot keep this as protected
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.
Changed ComputeConstraintForView from internal back to protected as requested in commit b9138ec. This maintains the existing inheritance pattern for custom layouts while preserving the return value refactoring.
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
/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 refactors the ComputeConstraintForView method pattern across the MAUI layout system to eliminate side effects and improve code architecture. Previously, this method was a void function that directly modified the child view's ComputedConstraint property, creating side effects that made the code harder to reason about and test.
Key changes:
- Changed
ComputeConstraintForViewfromvoidto returnLayoutConstraintvalue - Updated all layout classes to return constraint values instead of setting them directly
- Modified calling code to assign the returned constraint value to the child's
ComputedConstraintproperty
Reviewed Changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/Controls/src/Core/VisualElement/VisualElement.cs |
Base implementation change from void to return LayoutConstraint, updated callers to assign returned value |
src/Controls/src/Core/TemplatedView/TemplatedView.cs |
Updated override to return constraint instead of setting directly |
src/Controls/src/Core/TemplatedPage.cs |
Updated override to return constraint instead of setting directly |
src/Controls/src/Core/ScrollView/ScrollView.cs |
Updated override to return constraint, added missing return for default case |
src/Controls/src/Core/PublicAPI/*.txt |
Updated public API signatures to reflect method signature change |
src/Controls/src/Core/ListView/ListView.cs |
Removed direct constraint assignment that's now handled by parent |
src/Controls/src/Core/LegacyLayouts/StackLayout.cs |
Updated overrides and internal calls to use return values |
src/Controls/src/Core/LegacyLayouts/Grid.cs |
Updated override to return constraint, fixed property change handler |
src/Controls/src/Core/LegacyLayouts/AbsoluteLayout.cs |
Updated override to return constraint, simplified early return logic |
src/Controls/src/Core/Layout/VerticalStackLayout.cs |
Updated override to return constraint instead of setting directly |
src/Controls/src/Core/Layout/StackLayout.cs |
Updated override to return constraint instead of setting directly |
src/Controls/src/Core/Layout/HorizontalStackLayout.cs |
Updated override to return constraint instead of setting directly |
src/Controls/src/Core/Layout/Grid.cs |
Updated override to return constraint instead of setting directly |
src/Controls/src/Core/ContentPresenter.cs |
Updated override to return constraint instead of setting directly |
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
8ce8ce6 to
5f8b8bc
Compare
|
/azp run |
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
…requested Co-authored-by: PureWeen <[email protected]>
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
Co-authored-by: PureWeen <[email protected]>
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
Entry failure is unrelated |
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 #31083
Summary
This PR refactors the
ComputeConstraintForViewmethod pattern across the MAUI layout system to eliminate side effects and improve code maintainability. Previously,ComputeConstraintForViewwas avoidmethod that directly modified the child view'sComputedConstraintproperty. This change converts it to return aLayoutConstraintvalue instead, with the parentVisualElementresponsible for assigning the returned value.Key Changes
1. VisualElement Base Implementation
ComputeConstraintForViewsignature fromprotected virtual voidtoprotected virtual LayoutConstraintComputedConstraintsetter internal (not private) to allow specific use cases like ViewCellComputeConstrainsForChildren():child.ComputedConstraint = ComputeConstraintForView(child)OnChildAdded():view.ComputedConstraint = ComputeConstraintForView(view)InvalidateMeasureInternal():thisView.ComputedConstraint = visualParent.ComputeConstraintForView(thisView)2. Layout Override Updates
Updated all 11 layout classes to return constraints instead of setting them:
ContentPresenterStackLayout,VerticalStackLayout,HorizontalStackLayoutGrid(both modern and legacy versions)AbsoluteLayoutTemplatedPage,TemplatedViewScrollView3. Special Cases
Maintained direct constraint assignments where needed:
ViewCell: Preserves constraint assignments in View property setter for cell layout behaviorImplementation Pattern
Before (side effects):
After (return values):
Benefits
Compatibility
This change maintains full behavioral compatibility while improving the internal architecture. The constraint computation logic remains identical, only the mechanism for applying constraints has changed.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.