[iOS] Fix ScrollView not expanding to full width in landscape when HorizontalOptions=FillAndExpand#34469
Closed
praveenkumarkarunanithi wants to merge 2 commits intodotnet:mainfrom
Closed
Conversation
Contributor
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 34469Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 34469" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root Cause
During the measure pass on iOS, the
ScrollViewhandler calculated its size as the minimum of the inner content size and the available screen constraint. In landscape, although the available width increased (for example, from portrait to a wider constraint), the inner content had already measured itself at the smaller width. As a result, theScrollViewretained that earlier measured width and did not re-evaluate whether the content intended to stretch and fill the additional space. Unlike Android, the iOS implementation did not check whether the inner content hadFillalignment (which is the default forGridand most layouts) after measurement. Because of this missing alignment evaluation, theScrollViewwould shrink to content size instead of expanding to fill the available width when requested.Description of Change
The iOS ScrollView handler’s measure logic was updated to align with Android behavior. After computing the initial size from content measurement, it now evaluates whether the inner content has Fill horizontal alignment. If so, and if the available width constraint is finite, the ScrollView expands to match the full available constraint. If the available constraint is infinite (such as when the ScrollView is placed inside a StackLayout or another unconstrained parent), the logic safely falls back to the measured content size to avoid invalid fill calculations. The adjustment is applied before explicit size overrides, ensuring that developer-defined Width, MinimumWidth, or MaximumWidth values continue to take precedence.
Issues Fixed
Fixes #20042
Tested the behaviour in the following platforms
Note
Orientation change is not supported on Windows and MacCatalyst in this scenario, so the corresponding test case was not added for those platforms.
Output Video
BeforeFix.22.mov
AfterFix.29.mov