Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 83 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue27730.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using Microsoft.Maui.Controls.Shapes;

namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 27730, "Shadow not updated when Clipping a View with a shadow", PlatformAffected.UWP)]
public class Issue27730 : TestContentPage
{
Border _borderWithShadow;
Border _normalBorder;

protected override void Init()
{
VerticalStackLayout rootLayout = new VerticalStackLayout
{
Spacing = 10,
Padding = 10
};

Label shadowLabel = new Label { Text = "Border with Shadow, Clipping applied at runtime" };
Label clipLabel = new Label { Text = "Normal Border without shadow, Clipping first, Shadow added later" };

_borderWithShadow = CreateBorder(true);
_normalBorder = CreateBorder(false);

Button applyClipButton = new Button { Text = "Apply Clip", AutomationId = "ApplyClipBtn" };
Button applyShadowButton = new Button { Text = "Apply Shadow", AutomationId = "ApplyShadowBtn" };

applyClipButton.Clicked += (s, e) => ApplyClip();
applyShadowButton.Clicked += (s, e) => ApplyShadow();

rootLayout.Add(shadowLabel);
rootLayout.Add(_borderWithShadow);
rootLayout.Add(clipLabel);
rootLayout.Add(_normalBorder);
rootLayout.Add(applyClipButton);
rootLayout.Add(applyShadowButton);
Content = rootLayout;
}

Border CreateBorder(bool withShadow)
{
return new Border
{
StrokeShape = new RoundRectangle { CornerRadius = new CornerRadius(24) },
Background = Colors.Red,
WidthRequest = 100,
HeightRequest = 100,
Margin = new Thickness(12, 0),
Shadow = withShadow ? new Shadow
{
Brush = Colors.Black,
Offset = new Point(12, 12),
Radius = 10,
Opacity = 1
} : null
};
}

void ApplyClip()
{
EllipseGeometry clipGeometry = new EllipseGeometry
{
Center = new Point(50, 50),
RadiusX = 25,
RadiusY = 25
};

_borderWithShadow.Clip = clipGeometry;
_normalBorder.Clip = clipGeometry;
}

void ApplyShadow()
{
_normalBorder.Shadow = new Shadow
{
Brush = Colors.Black,
Offset = new Point(12, 12),
Radius = 10,
Opacity = 1
};
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue27730 : _IssuesUITest
{
public Issue27730(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "Shadow not updated when Clipping a View with a shadow";

[Test]
[Category(UITestCategories.Visual)]
public void ShadowShouldUpdateWhenClipping()
{
App.WaitForElement("ApplyShadowBtn");
App.Tap("ApplyClipBtn");
App.Tap("ApplyShadowBtn");
VerifyScreenshot();
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/Core/src/Platform/Windows/WrapperView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ void UpdateClip()
var geometricClip = compositor.CreateGeometricClip(pathGeometry);

visual.Clip = geometricClip;
//When the clip is updated, the shadow must be updated as well
UpdateShadowAsync().FireAndForget(IPlatformApplication.Current?.Services?.CreateLogger(nameof(WrapperView)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works if the View already have a Shadow, but, works if the order is:

  1. Clip
  2. Add a Shadow
    ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsuarezruiz , A new shadow will be created if the order is reversed.

}

void DisposeClip()
Expand Down
Loading