From de37c278c3fab7ec5ecbf2ba5270b490ca36bf3e Mon Sep 17 00:00:00 2001 From: xiaoy312 Date: Wed, 26 Jan 2022 10:31:01 -0500 Subject: [PATCH] fix(shape): Stroke update not triggering re-render --- .../Windows_UI_Xaml_Shapes/Shapes_Tests.cs | 27 +++++- .../UITests.Shared/UITests.Shared.projitems | 7 ++ .../Shape_StrokeTest.xaml | 17 ++++ .../Shape_StrokeTest.xaml.cs | 88 +++++++++++++++++++ src/Uno.UI/UI/Xaml/Shapes/Shape.cs | 7 +- 5 files changed, 141 insertions(+), 5 deletions(-) create mode 100644 src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Shapes/Shape_StrokeTest.xaml create mode 100644 src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Shapes/Shape_StrokeTest.xaml.cs diff --git a/src/SamplesApp/SamplesApp.UITests/Windows_UI_Xaml_Shapes/Shapes_Tests.cs b/src/SamplesApp/SamplesApp.UITests/Windows_UI_Xaml_Shapes/Shapes_Tests.cs index 0a70c3a0772c..c1843afba4b7 100644 --- a/src/SamplesApp/SamplesApp.UITests/Windows_UI_Xaml_Shapes/Shapes_Tests.cs +++ b/src/SamplesApp/SamplesApp.UITests/Windows_UI_Xaml_Shapes/Shapes_Tests.cs @@ -201,7 +201,7 @@ public void Default_StrokeThickness() else { var shapeContainer = _app.GetPhysicalRect($"{expectation}Grid"); - + ImageAssert.HasColorAt(screenshot, shapeContainer.X + expectation.Offsets[0], shapeContainer.CenterY, expectation.Colors, tolerance: 15); ImageAssert.HasColorAt(screenshot, shapeContainer.CenterX, shapeContainer.Y + expectation.Offsets[1], expectation.Colors, tolerance: 15); ImageAssert.HasColorAt(screenshot, shapeContainer.Right + expectation.Offsets[2], shapeContainer.CenterY, expectation.Colors, tolerance: 15); @@ -233,6 +233,29 @@ public void Setting_ImageBrush_In_Code_Behind() ImageAssert.HasColorAt(screenshot, rect2.X, rect2.Y, Color.FromArgb(255, 236, 197, 175), tolerance: 5); } + [Test] + [AutoRetry] + public void Shape_StrokeColor_ShouldRerenderWithChange() + { + Run("UITests.Windows_UI_Xaml_Shapes.Shape_StrokeTest"); + + var rect = _app.GetPhysicalRect("TestTarget").ToRectangle(); + var center = rect.Location + new Size(rect.Size.Width / 2, rect.Size.Height / 2); + var initialColor = Color.Red; + var invertedColor = Color.FromArgb(255, 0, 255, 255); // UpdateBrushColor: flip (x => x^255) all rgb channels, except alpha + + // check color before + using var before = TakeScreenshot("Shape_StrokeTest_Before"); + ImageAssert.HasColorAt(before, center.X, center.Y, initialColor); + + // update brush color + _app.FastTap("UpdateBrushColorButton"); + + // check color after + using var after = TakeScreenshot("Shape_StrokeTest_After"); + ImageAssert.HasColorAt(after, center.X, center.Y, invertedColor); + } + private static string GetReddish() => AppInitializer.GetLocalPlatform() switch { @@ -244,7 +267,7 @@ private static string GetReddish() => private struct ShapeExpectation { public string Name { get; set; } - public int[] Offsets { get; set; } + public int[] Offsets { get; set; } public string Colors { get; set; } public override string ToString() => $"{Name}"; diff --git a/src/SamplesApp/UITests.Shared/UITests.Shared.projitems b/src/SamplesApp/UITests.Shared/UITests.Shared.projitems index 8549be834fe6..419b035d1aff 100644 --- a/src/SamplesApp/UITests.Shared/UITests.Shared.projitems +++ b/src/SamplesApp/UITests.Shared/UITests.Shared.projitems @@ -4369,6 +4369,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -7126,6 +7130,9 @@ Shapes_Default_StrokeThickness.xaml + + Shape_StrokeTest.xaml + StretchPage.xaml diff --git a/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Shapes/Shape_StrokeTest.xaml b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Shapes/Shape_StrokeTest.xaml new file mode 100644 index 000000000000..96fb2ff523f4 --- /dev/null +++ b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Shapes/Shape_StrokeTest.xaml @@ -0,0 +1,17 @@ + + + + + + + + +