Skip to content
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

[Bug] Fix Grid cells not honoring MaxWidth #16215

Merged
merged 9 commits into from Jul 21, 2023
Merged

[Bug] Fix Grid cells not honoring MaxWidth #16215

merged 9 commits into from Jul 21, 2023

Conversation

jknaudt21
Copy link
Contributor

@jknaudt21 jknaudt21 commented Jul 18, 2023

Problem

When computing the size of a cell, Grid would run into trouble depending on the platform when given MaxWidth.

On Android, the grid's children would often look at the screen's max width (even if that meant looking at the wrong orientation) and ignore the dimensions passed to the grid object.

On iOS, the grid's children would compute their width when SizeThatFits was called. This call was done without taking into account MaxWidth

Solution

When calculating the dimension constraints for a view, we take into account the MaxWidth and MaxHeight as long as they are smaller than the already established constraints.

Before After
image image
image image
(Windows was working fine, so no changes were needed)

Issues Fixed

Fixes #15785
Fixes #7366

Remaining Work

  • Write tests
  • Figure out why Android's MaxWidth beats out the screen's width
  • Add android screenshots

@jknaudt21 jknaudt21 requested a review from hartez July 18, 2023 20:07
@jsuarezruiz jsuarezruiz added area/layout 🔲 StackLayout, GridLayout, ScrollView, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter layout-grid labels Jul 19, 2023
The key was in the view handlers, where we weren't doing the proper handling for MaximumWidth
The problem belongs more to device tests
@jknaudt21 jknaudt21 marked this pull request as ready for review July 20, 2023 21:23
@jknaudt21 jknaudt21 requested a review from hartez July 20, 2023 21:28
@jknaudt21 jknaudt21 merged commit b8b5b75 into main Jul 21, 2023
36 checks passed
@jknaudt21 jknaudt21 deleted the dev/jd/15785 branch July 21, 2023 17:06
@Toine-db
Copy link

Toine-db commented Aug 1, 2023

Hello Guys,

Thanks for the fix, but please merge this fix to the .Net 7 version as well.
We currently need to put migration projects on hold because of this issue that otherwise would be finished within weeks, and new migrations won't be started anymore because of this.
This is waiting for the .Net8 release really comes at a bad time because currently other development environments are also being considered, waiting a few months for .Net8 is really (too) long for our department.

Please consider copying the three lines of code to the .Net7 version.

Kind Regards,

FYI: using preview versions (like for .Net8) for production releases is really a no-go for us :-(

@hartez hartez added the backport/suggested The PR author or issue review has suggested that the change should be backported. label Aug 7, 2023
@hartez hartez added the backport/approved After some discussion or review, this PR or change was approved to be backported. label Aug 16, 2023
@hartez
Copy link
Contributor

hartez commented Aug 16, 2023

/backport to net7.0

@github-actions
Copy link
Contributor

Started backporting to net7.0: https://github.com/dotnet/maui/actions/runs/5880806564

@github-actions
Copy link
Contributor

@hartez backporting to net7.0 failed, the patch most likely resulted in conflicts:

$ git am --3way --ignore-whitespace --keep-non-patch changes.patch

Applying: Make Grid be constrained by MaxWidth
Applying: Ensure grid cells honor max width/height
Applying: Attempt to (unsuccessfully) add tests
Applying: Fix typo
Applying: Fix bug, revert wrong changes
Using index info to reconstruct a base tree...
M	src/Core/src/Handlers/ViewHandlerExtensions.iOS.cs
M	src/Core/src/Layouts/GridLayoutManager.cs
M	src/Core/src/Platform/Android/ContextExtensions.cs
Falling back to patching base and 3-way merge...
Auto-merging src/Core/src/Platform/Android/ContextExtensions.cs
Auto-merging src/Core/src/Layouts/GridLayoutManager.cs
Auto-merging src/Core/src/Handlers/ViewHandlerExtensions.iOS.cs
CONFLICT (content): Merge conflict in src/Core/src/Handlers/ViewHandlerExtensions.iOS.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0005 Fix bug, revert wrong changes
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

@github-actions
Copy link
Contributor

@hartez an error occurred while backporting to net7.0, please check the run log for details!

Error: git am failed, most likely due to a merge conflict.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/layout 🔲 StackLayout, GridLayout, ScrollView, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter backport/approved After some discussion or review, this PR or change was approved to be backported. backport/suggested The PR author or issue review has suggested that the change should be backported. layout-grid
Projects
None yet
4 participants