Skip to content

Commit 907d603

Browse files
prakashKannanSf3972PureWeen
authored andcommitted
[Windows] - Fix view position shift when shadows are added or removed at runtime (#29681)
* Fix-view-position-shift-when-toggling-shadows * Added-Pending-SnapShots * Resaved-image
1 parent fb97a7e commit 907d603

File tree

8 files changed

+135
-2
lines changed

8 files changed

+135
-2
lines changed
127 KB
Loading
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
using Microsoft.Maui.Controls.Shapes;
2+
3+
namespace Maui.Controls.Sample.Issues;
4+
5+
[Issue(IssueTracker.Github, 27732, "[Windows] View Position Shifts When Shadows Are Dynamically Removed or Resized", PlatformAffected.UWP)]
6+
public class Issue27732 : TestContentPage
7+
{
8+
Border borderShadow;
9+
Image imageShadow;
10+
Label labelShadow;
11+
Button shadowButton;
12+
bool _shadow = false;
13+
14+
protected override void Init()
15+
{
16+
Title = "Issue27732";
17+
borderShadow = new Border
18+
{
19+
AutomationId = "BorderShadow",
20+
StrokeShape = new RoundRectangle { CornerRadius = 24 },
21+
Background = Colors.Red,
22+
WidthRequest = 80
23+
};
24+
25+
imageShadow = new Image
26+
{
27+
AutomationId = "ImageShadow",
28+
Aspect = Aspect.AspectFit,
29+
Source = "oasis.jpg",
30+
WidthRequest = 80
31+
};
32+
33+
labelShadow = new Label
34+
{
35+
AutomationId = "LabelShadow",
36+
Text = "Label",
37+
FontSize = 18,
38+
WidthRequest = 80
39+
};
40+
41+
shadowButton = new Button
42+
{
43+
AutomationId = "ToggleShadowButton",
44+
Text = "Add Shadow",
45+
HorizontalOptions = LayoutOptions.Start
46+
};
47+
shadowButton.Clicked += OnShadowClicked;
48+
49+
Content = new StackLayout
50+
{
51+
Margin = new Thickness(0, 40),
52+
HorizontalOptions = LayoutOptions.Center,
53+
Spacing = 20,
54+
Children =
55+
{
56+
new HorizontalStackLayout
57+
{
58+
HorizontalOptions = LayoutOptions.Center,
59+
Spacing = 10,
60+
Children = { borderShadow, imageShadow, labelShadow }
61+
},
62+
new HorizontalStackLayout
63+
{
64+
Spacing = 10,
65+
Children =
66+
{
67+
new Label
68+
{
69+
Text = "Toggle Shadow Button:",
70+
FontSize = 15,
71+
VerticalOptions = LayoutOptions.Center,
72+
HorizontalOptions = LayoutOptions.Start
73+
},
74+
shadowButton
75+
}
76+
}
77+
}
78+
};
79+
}
80+
81+
void OnShadowClicked(object sender, EventArgs e)
82+
{
83+
if (_shadow)
84+
{
85+
shadowButton.Text = "Add Shadow";
86+
borderShadow.Shadow = imageShadow.Shadow = labelShadow.Shadow = null;
87+
_shadow = false;
88+
}
89+
else
90+
{
91+
shadowButton.Text = "Remove Shadow";
92+
93+
var newShadow = new Shadow
94+
{
95+
Brush = Brush.Black,
96+
Offset = new Point(4, 4),
97+
Radius = 10,
98+
Opacity = 0.5f
99+
};
100+
101+
borderShadow.Shadow = imageShadow.Shadow = labelShadow.Shadow = newShadow;
102+
_shadow = true;
103+
}
104+
}
105+
}
24 KB
Loading
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using NUnit.Framework;
2+
using UITest.Appium;
3+
using UITest.Core;
4+
5+
namespace Microsoft.Maui.TestCases.Tests.Issues;
6+
7+
public class Issue27732 : _IssuesUITest
8+
{
9+
public Issue27732(TestDevice testDevice) : base(testDevice)
10+
{
11+
}
12+
13+
public override string Issue => "[Windows] View Position Shifts When Shadows Are Dynamically Removed or Resized";
14+
15+
const string ToggleShadowButton = "ToggleShadowButton";
16+
17+
[Test]
18+
[Category(UITestCategories.Visual)]
19+
public void ViewShouldNotShiftOnShadowChanged()
20+
{
21+
App.WaitForElement(ToggleShadowButton);
22+
for (int i = 0; i < 5; i++)
23+
{
24+
App.Tap(ToggleShadowButton);
25+
}
26+
VerifyScreenshot();
27+
}
28+
}
1.69 KB
Loading
25.2 KB
Loading
144 KB
Loading

src/Core/src/Handlers/View/ViewHandlerOfT.Windows.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ protected override void RemoveContainer()
5757
}
5858

5959
#pragma warning disable RS0030 // Do not use banned APIs; Panel.Children is banned for performance reasons. MauiPanel might not be used everywhere though.
60-
var oldParentChildren = PlatformView.Parent is MauiPanel mauiPanel
60+
var oldParentChildren = ContainerView.Parent is MauiPanel mauiPanel
6161
? mauiPanel.CachedChildren
62-
: (PlatformView.Parent as Panel)?.Children;
62+
: (ContainerView.Parent as Panel)?.Children;
6363
#pragma warning restore RS0030 // Do not use banned APIs
6464

6565
var oldIndex = oldParentChildren?.IndexOf(ContainerView);

0 commit comments

Comments
 (0)