Skip to content

[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
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

prakashKannanSf3972
Copy link
Contributor

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Root Cause

  • ShadowLayer renders shadows even when a shape is filled or drawn using a transparent color. The Android canvas still processes the shape’s path and applies the shadow, despite the shape itself being visually transparent. This leads to shadows appearing without visible content, potentially causing unintended visual output.

Description of Change

  • Refined ShadowLayer to apply shadows only when FillColor, StrokeColor, or FontColor have a non-zero alpha value, avoiding unnecessary shadow rendering for fully transparent elements.

  • Additionally, ShadowLayer is now explicitly invoked whenever any of these color properties change, ensuring consistent and accurate shadow rendering across platforms.

Issues Fixed

Fixes #29394

Tested the behaviour in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Output

Before After

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label May 15, 2025
Copy link
Contributor

Hey there @@prakashKannanSf3972! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@dotnet-policy-service dotnet-policy-service bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label May 15, 2025
@jsuarezruiz jsuarezruiz added the area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing label May 16, 2025
@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@prakashKannanSf3972 prakashKannanSf3972 marked this pull request as ready for review May 16, 2025 13:15
@Copilot Copilot AI review requested due to automatic review settings May 16, 2025 13:15
@prakashKannanSf3972 prakashKannanSf3972 requested a review from a team as a code owner May 16, 2025 13:15
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR resolves an issue where shadows were rendered for fully transparent shapes by refining the shadow rendering logic and ensuring shadow updates are triggered on color property changes.

  • Updated PlatformCanvasState.cs to trigger shadow state updates when StrokeColor, FillColor, or FontColor change and to conditionally apply shadows based on alpha values.
  • Added a unit test (Issue29394.cs in TestCases.Shared.Tests) and an associated UI test page (Issue29394.cs in TestCases.HostApp) to cover the transparent shadow rendering scenario.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

File Description
src/Graphics/src/Graphics/Platforms/Android/PlatformCanvasState.cs Refactored to apply shadows based on color alpha and ensure state updates on color changes.
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29394.cs Added a unit test to verify shadow behavior with transparent colors.
src/Controls/tests/TestCases.HostApp/Issues/Issue29394.cs Provided a test page to facilitate automated UI tests for the shadow rendering update.

}
}

void UpdateShadowState()
Copy link
Preview

Copilot AI May 16, 2025

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.

@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ellipse Transparency Not Rendered When Drawing Arc Inside the Ellipse Using GraphicsView on Android
2 participants