-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Change iOS SetNeedsLayout propagation mechanism #26629
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
Merged
PureWeen
merged 5 commits into
dotnet:main
from
albyrock87:ios-set-neesd-layout-propagation-mapper
Mar 5, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
63b56d6
Standardize the way we invalidate measure on iOS
albyrock87 047e973
Updated screenshot
albyrock87 28e4710
Remove `PageView` in favor of tagging `ContentView` as a page
albyrock87 2d1169c
Remove `SetNeedsLayout` overrides
albyrock87 d1408f4
Fix image view extensions padding computation
albyrock87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
39 changes: 39 additions & 0 deletions
39
src/Controls/tests/TestCases.HostApp/Issues/Issue24996.xaml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
| xmlns:issues="clr-namespace:Maui.Controls.Sample.Issues" | ||
| x:Class="Maui.Controls.Sample.Issues.Issue24996" | ||
| Title="Issue24996" | ||
| x:Name="Self"> | ||
| <AbsoluteLayout BackgroundColor="DarkSlateBlue"> | ||
| <AbsoluteLayout.GestureRecognizers> | ||
| <TapGestureRecognizer Tapped="OnTapped" /> | ||
| </AbsoluteLayout.GestureRecognizers> | ||
| <Grid RowDefinitions="*" ColumnDefinitions="*"> | ||
| <issues:ObservedLayout24996 x:Name="Lvl1" BackgroundColor="BlueViolet"> | ||
| <issues:ObservedLayout24996 x:Name="Lvl2" BackgroundColor="AliceBlue"> | ||
| <issues:ObservedLayout24996 x:Name="Lvl3" | ||
| BackgroundColor="Aqua" | ||
| HeightRequest="200" | ||
| WidthRequest="200"> | ||
| <Border BackgroundColor="GreenYellow" HeightRequest="100" WidthRequest="100" /> | ||
| </issues:ObservedLayout24996> | ||
| </issues:ObservedLayout24996> | ||
| </issues:ObservedLayout24996> | ||
| </Grid> | ||
| <VerticalStackLayout AbsoluteLayout.LayoutFlags="PositionProportional" | ||
| AbsoluteLayout.LayoutBounds="0,1,-1,-1" | ||
| BackgroundColor="#222222"> | ||
| <Label x:Name="Coords" | ||
| HeightRequest="40" | ||
| WidthRequest="{Binding Width, Source={x:Reference Self}}" | ||
| AutomationId="Coords" | ||
| TextColor="White"/> | ||
| <Label x:Name="Stats" | ||
| HeightRequest="40" | ||
| WidthRequest="{Binding Width, Source={x:Reference Self}}" | ||
| AutomationId="Stats" | ||
| TextColor="White"/> | ||
| </VerticalStackLayout> | ||
| </AbsoluteLayout> | ||
| </ContentPage> |
73 changes: 73 additions & 0 deletions
73
src/Controls/tests/TestCases.HostApp/Issues/Issue24996.xaml.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| namespace Maui.Controls.Sample.Issues; | ||
|
|
||
| [Issue(IssueTracker.Github, 24996, "Changing Translation of an element causes Maui in iOS to constantly run Measure & ArrangeChildren", PlatformAffected.All)] | ||
| public partial class Issue24996 : ContentPage | ||
| { | ||
| Point[] _translations = [ | ||
| new(40, 80), | ||
| new(1000, 20), | ||
| new(20, 1000), | ||
| new(1000, 1000), | ||
| ]; | ||
|
|
||
| int _index = -1; | ||
|
|
||
| public Issue24996() | ||
| { | ||
| InitializeComponent(); | ||
| UpdateText(); | ||
|
|
||
| SizeChanged += delegate { | ||
| if (Width > 0) { | ||
| // For some reason, constraining this layout to a fixed size causes a `SetNeedsLayout` to be called | ||
| // when translating the Lvl2 view outside the bottom boundary. | ||
| // This causes a layout pass to be called on the Root, Lvl1, Lvl2, and Lvl3. | ||
| Lvl1.WidthRequest = Width; | ||
| Lvl1.HeightRequest = Height; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| protected override async void OnAppearing() | ||
| { | ||
| base.OnAppearing(); | ||
| await Task.Delay(250); | ||
| Lvl1.MeasurePasses = Lvl1.ArrangePasses = 0; | ||
| Lvl2.MeasurePasses = Lvl2.ArrangePasses = 0; | ||
| Lvl3.MeasurePasses = Lvl3.ArrangePasses = 0; | ||
| UpdateText(); | ||
| } | ||
|
|
||
| public async void OnTapped(object sender, EventArgs e) | ||
| { | ||
| var testPoint = _translations[++_index % _translations.Length]; | ||
| Coords.Text = $"X: {testPoint.X}, Y: {testPoint.Y}"; | ||
| Lvl2.TranslationX = testPoint.X; | ||
| Lvl2.TranslationY = testPoint.Y; | ||
| await Task.Delay(100); | ||
| UpdateText(); | ||
| } | ||
|
|
||
| void UpdateText() | ||
| { | ||
| Stats.Text = $"Lvl1[{Lvl1.MeasurePasses}/{Lvl1.ArrangePasses}] - Lvl2[{Lvl2.MeasurePasses}/{Lvl2.ArrangePasses}] - Lvl3[{Lvl3.MeasurePasses}/{Lvl3.ArrangePasses}]"; | ||
| } | ||
| } | ||
|
|
||
| public class ObservedLayout24996 : AbsoluteLayout | ||
| { | ||
| public int MeasurePasses { get; set; } | ||
| public int ArrangePasses { get; set; } | ||
|
|
||
| protected override Size MeasureOverride(double widthConstraint, double heightConstraint) | ||
| { | ||
| MeasurePasses++; | ||
| return base.MeasureOverride(widthConstraint, heightConstraint); | ||
| } | ||
|
|
||
| protected override Size ArrangeOverride(Rect bounds) | ||
| { | ||
| ArrangePasses++; | ||
| return base.ArrangeOverride(bounds); | ||
| } | ||
| } |
Binary file modified
BIN
-136 Bytes
(100%)
src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/Issue18242Test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions
30
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24996.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| using NUnit.Framework; | ||
| using NUnit.Framework.Legacy; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues | ||
| { | ||
| public class Issue24996 : _IssuesUITest | ||
| { | ||
| public Issue24996(TestDevice testDevice) : base(testDevice) | ||
| { | ||
| } | ||
|
|
||
| public override string Issue => "Changing Translation of an element causes Maui in iOS to constantly run Measure & ArrangeChildren"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.Layout)] | ||
| public async Task ChangingTranslationShouldNotCauseLayoutPassOnAncestors() | ||
| { | ||
| var element = App.WaitForElement("Stats"); | ||
| // Tries to translate the element in different positions, on-screen and off-screen. | ||
| for (int i = 0; i < 4; i++) | ||
| { | ||
| element.Tap(); | ||
| await Task.Delay(150); | ||
| ClassicAssert.True(element.GetText()!.StartsWith("Lvl1[0/0]")); | ||
| } | ||
| } | ||
| } | ||
| } |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.