-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed Unnecessary SizeChanged Event Triggering (#27476)
* Fixed Fixed Unnecessary SizeChanged Event Triggering * Added test case * Added comment on testcase * Added test case * Added comment on testcase * Moved SizeAllocated() within if condition
- Loading branch information
1 parent
c458a44
commit 86f2b95
Showing
3 changed files
with
116 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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,79 @@ | ||
namespace Maui.Controls.Sample.Issues | ||
{ | ||
[Issue(IssueTracker.Github, 27223, "SizeChanged event fires when size hasn't changed", PlatformAffected.UWP)] | ||
public class Issue27223 : ContentPage | ||
{ | ||
private int counter = 0; | ||
private Label Counter; | ||
private Editor ShowSizes; | ||
private Editor ShowCoordinates; | ||
private VerticalStackLayout stackLayout; | ||
|
||
public Issue27223() | ||
{ | ||
Grid mainGrid = new Grid | ||
{ | ||
ColumnDefinitions = | ||
{ | ||
new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }, | ||
new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }, | ||
new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) } | ||
} | ||
}; | ||
|
||
Grid leftGrid = new Grid | ||
{ | ||
RowDefinitions = | ||
{ | ||
new RowDefinition { Height = GridLength.Auto }, | ||
new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, | ||
new RowDefinition { Height = GridLength.Auto } | ||
} | ||
}; | ||
|
||
Counter = new Label { AutomationId = "Label" }; | ||
leftGrid.Children.Add(Counter); | ||
Grid.SetRow(Counter, 0); | ||
|
||
stackLayout = new VerticalStackLayout(); | ||
stackLayout.SizeChanged += VerticalStackLayout_SizeChanged; | ||
var button1 = new Button { Text = "button 1", AutomationId = "Button1" }; | ||
button1.Clicked += Button_Clicked; | ||
stackLayout.Children.Add(button1); | ||
stackLayout.Children.Add(new Button { Text = "button 2" }); | ||
stackLayout.Children.Add(new Button { Text = "button 3" }); | ||
leftGrid.Children.Add(stackLayout); | ||
Grid.SetRow(stackLayout, 2); | ||
|
||
ShowSizes = new Editor { BackgroundColor = Colors.SkyBlue, VerticalOptions = LayoutOptions.Fill }; | ||
ShowCoordinates = new Editor { BackgroundColor = Colors.DarkGoldenrod, VerticalOptions = LayoutOptions.Fill }; | ||
|
||
mainGrid.Children.Add(leftGrid); | ||
Grid.SetColumn(leftGrid, 0); | ||
|
||
mainGrid.Children.Add(ShowSizes); | ||
Grid.SetColumn(ShowSizes, 1); | ||
|
||
mainGrid.Children.Add(ShowCoordinates); | ||
Grid.SetColumn(ShowCoordinates, 2); | ||
|
||
Content = mainGrid; | ||
} | ||
|
||
private void Button_Clicked(object sender, EventArgs e) | ||
{ | ||
#if WINDOWS | ||
Window.Height = 500; | ||
#endif | ||
} | ||
|
||
private void VerticalStackLayout_SizeChanged(object sender, EventArgs e) | ||
{ | ||
if (sender is VerticalStackLayout ctrl) | ||
{ | ||
counter++; | ||
Counter.Text = $"resized {counter} times"; | ||
} | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue27223.cs
This file contains 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,28 @@ | ||
#if WINDOWS // mac does not respond to the window size change. so, ignored test on mac. | ||
using NUnit.Framework; | ||
using UITest.Appium; | ||
using UITest.Core; | ||
|
||
namespace Microsoft.Maui.TestCases.Tests.Issues | ||
{ | ||
public class Issue27223 : _IssuesUITest | ||
{ | ||
public Issue27223(TestDevice testDevice) : base(testDevice) | ||
{ | ||
} | ||
|
||
public override string Issue => "SizeChanged event fires when size hasn't changed"; | ||
|
||
[Test] | ||
[Category(UITestCategories.Layout)] | ||
public void SizeChangedOnlyFiresWhenSizeChanges() | ||
{ | ||
App.WaitForElement("Label"); | ||
var initialValue = App.FindElement("Label").GetText(); | ||
App.Tap("Button1"); | ||
var finalValue = App.FindElement("Label").GetText(); | ||
Assert.That(initialValue, Is.EqualTo(finalValue)); | ||
} | ||
} | ||
} | ||
#endif |