Skip to content

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
davor-bauk-sh:fix/current-color-opacity-apple
Open

fix: apply opacity to currentColor for fill and stroke on Apple platforms#2923
davor-bauk-sh wants to merge 2 commits intosoftware-mansion:mainfrom
davor-bauk-sh:fix/current-color-opacity-apple

Conversation

@davor-bauk-sh
Copy link
Copy Markdown

@davor-bauk-sh davor-bauk-sh commented Apr 6, 2026

Summary

Fixes #1802 on iOS/macOS.

When currentColor is used as a fill or stroke brush on Apple platforms, the fillOpacity and strokeOpacity values are ignored — the color is passed directly to CGContextSetFillColorWithColor/CGContextSetStrokeColorWithColor without 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.mm

Test Plan

Added E2E test case (e2e/cases/4.svg) covering all combinations of currentColor with fill-opacity and stroke-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 currentColor for fill or stroke with fill-opacity or stroke-opacity set to a value less than 1. Without this fix, the opacity is ignored and the element renders at full opacity.

Compatibility

OS Implemented
iOS
MacOS
Android
Web

Checklist

  • I have tested this on a device and a simulator
  • I added documentation in README.md
  • I updated the typed files (typescript)
  • I added a test for the API in the __tests__ folder

Screenshots

Before After
react-native-svg-current-color-opacity-before react-native-svg-current-color-opacity-after

@davor-bauk-sh davor-bauk-sh marked this pull request as draft April 6, 2026 23:33
@davor-bauk-sh davor-bauk-sh force-pushed the fix/current-color-opacity-apple branch from f62edc3 to 2928263 Compare April 7, 2026 00:18
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.
@davor-bauk-sh davor-bauk-sh force-pushed the fix/current-color-opacity-apple branch from 2928263 to 938aa89 Compare April 7, 2026 00:23
@davor-bauk-sh davor-bauk-sh marked this pull request as ready for review April 7, 2026 00:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fillOpacity not working with fill="currentColor"

1 participant