-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[Android] - Fix Shadow Rendering For Transparent Fill, Stroke (Lines), and Text on Shapes #29528
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
Open
prakashKannanSf3972
wants to merge
2
commits into
dotnet:main
Choose a base branch
from
prakashKannanSf3972:fix-29394
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Binary file added
BIN
+71.4 KB
...ases.Android.Tests/snapshots/android/TransparentShapeShouldNotDisplayShadow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,68 @@ | ||
namespace Maui.Controls.Sample.Issues; | ||
|
||
[Issue(IssueTracker.Github, 29394, "On Android Shadows should not be rendered over fully transparent areas of drawn shapes", PlatformAffected.Android)] | ||
public class Issue29394 : TestContentPage | ||
{ | ||
protected override void Init() | ||
{ | ||
var verticalStackLayout = new VerticalStackLayout() | ||
{ | ||
Padding = new Thickness(30, 0), | ||
Spacing = 25, | ||
VerticalOptions = LayoutOptions.Center | ||
}; | ||
|
||
var graphicsView = new GraphicsView() | ||
{ | ||
HeightRequest = 500, | ||
WidthRequest = 400, | ||
Drawable = new Issue29394_Drawable() | ||
}; | ||
var label = new Label() | ||
{ | ||
Text = "This is a test for Shadows should not be rendered over fully transparent areas of drawn shapes.", | ||
AutomationId = "label", | ||
HorizontalOptions = LayoutOptions.Center, | ||
VerticalOptions = LayoutOptions.Center | ||
}; | ||
|
||
verticalStackLayout.Children.Add(graphicsView); | ||
verticalStackLayout.Children.Add(label); | ||
Content = verticalStackLayout; | ||
} | ||
} | ||
|
||
public class Issue29394_Drawable : IDrawable | ||
{ | ||
Rect fillRect = new Rect(0, 0, 300, 300); | ||
|
||
public void Draw(ICanvas canvas, RectF dirtyRect) | ||
{ | ||
canvas.SaveState(); | ||
|
||
float centerX = (dirtyRect.Width - (float)fillRect.Width) / 2; | ||
float centerY = (dirtyRect.Height - (float)fillRect.Height) / 2; | ||
var outerRect = new RectF(centerX, centerY, (float)fillRect.Width, (float)fillRect.Height); | ||
|
||
canvas.SetFillPaint(Colors.Transparent.AsPaint(), outerRect); | ||
canvas.SetShadow(new SizeF(0, 15), 4, Color.FromArgb("#59000000")); | ||
canvas.FillEllipse(outerRect.X, outerRect.Y, outerRect.Width, outerRect.Height); | ||
|
||
float arcSize = 250f; | ||
float arcX = outerRect.X + (outerRect.Width - arcSize) / 2; | ||
float arcY = outerRect.Y + (outerRect.Height - arcSize) / 2; | ||
|
||
canvas.FillColor = Colors.Blue; | ||
canvas.FillCircle(arcX + arcSize / 2, arcY + arcSize / 2, 15); | ||
canvas.DrawArc(arcX, arcY, arcSize, arcSize, 45, 90, true, false); | ||
|
||
canvas.StrokeColor = Colors.Transparent; | ||
canvas.StrokeSize = 2; | ||
canvas.DrawLine(0, 25, dirtyRect.Width, 25); | ||
|
||
canvas.FontColor = Colors.Transparent; | ||
canvas.DrawString("Shadow should not be Rendered", dirtyRect.Width / 2, 10, HorizontalAlignment.Center); | ||
|
||
canvas.RestoreState(); | ||
} | ||
} |
Binary file added
BIN
+27.4 KB
...ts/TestCases.Mac.Tests/snapshots/mac/TransparentShapeShouldNotDisplayShadow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions
19
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29394.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,19 @@ | ||
using NUnit.Framework; | ||
using UITest.Appium; | ||
using UITest.Core; | ||
|
||
namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
public class Issue29394 : _IssuesUITest | ||
{ | ||
public Issue29394(TestDevice device) : base(device) { } | ||
|
||
public override string Issue => "On Android Shadows should not be rendered over fully transparent areas of drawn shapes"; | ||
|
||
[Test] | ||
[Category(UITestCategories.GraphicsView)] | ||
public void TransparentShapeShouldNotDisplayShadow() | ||
{ | ||
App.WaitForElement("label"); | ||
VerifyScreenshot(); | ||
} | ||
} |
Binary file added
BIN
+21.6 KB
...tCases.WinUI.Tests/snapshots/windows/TransparentShapeShouldNotDisplayShadow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+90.4 KB
...ts/TestCases.iOS.Tests/snapshots/ios/TransparentShapeShouldNotDisplayShadow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider refactoring UpdateShadowState to batch multiple color updates to avoid redundant calls to SetShadow if several color properties change consecutively. This could improve performance if shadow re-application becomes expensive.
Copilot uses AI. Check for mistakes.