fix: apply opacity to currentColor for fill and stroke on Apple platforms#2923
Open
davor-bauk-sh wants to merge 2 commits intosoftware-mansion:mainfrom
Open
fix: apply opacity to currentColor for fill and stroke on Apple platforms#2923davor-bauk-sh wants to merge 2 commits intosoftware-mansion:mainfrom
davor-bauk-sh wants to merge 2 commits intosoftware-mansion:mainfrom
Conversation
f62edc3 to
2928263
Compare
Adds an E2E test case and a test example (Test2923) covering all combinations of currentColor with fill-opacity and stroke-opacity on Apple platforms.
…orms When currentColor is used as a fill or stroke brush, the fillOpacity and strokeOpacity values were ignored because the color was passed directly without applying the opacity multiplier. This creates a copy of the color with the correct alpha using CGColorCreateCopyWithAlpha.
2928263 to
938aa89
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #1802 on iOS/macOS.
When
currentColoris used as a fill or stroke brush on Apple platforms, thefillOpacityandstrokeOpacityvalues are ignored — the color is passed directly toCGContextSetFillColorWithColor/CGContextSetStrokeColorWithColorwithout applying the opacity multiplier.This fix creates a copy of the color with the correct alpha using
CGColorCreateCopyWithAlpha(currentColor, opacity * CGColorGetAlpha(currentColor)), and properly releases the created color to avoid memory leaks.Related: #2080 (Android-only opacity fix)
Affected files:
RNSVGContextBrush.mm,RNSVGRenderable.mm,RNSVGTSpan.mmTest Plan
Added E2E test case (
e2e/cases/4.svg) covering all combinations ofcurrentColorwithfill-opacityandstroke-opacity: fill only, stroke only, and fill + stroke.What's required for testing (prerequisites)?
An iOS or macOS device/simulator.
What are the steps to reproduce (after prerequisites)?
Render an SVG element that uses
currentColorfor fill or stroke withfill-opacityorstroke-opacityset to a value less than 1. Without this fix, the opacity is ignored and the element renders at full opacity.Compatibility
Checklist
README.md__tests__folderScreenshots