Fix #1345: opacity does not work with currentColor on Android (#2080)

I implemented this by multiplying the alpha of the currentColor by the opacity when setting a currentColor brush.

Co-authored-by: Wojciech Lewicki <wojciech.lewicki@swmansion.com>
This commit is contained in:
Ibiyemi Abiodun
2023-07-05 12:06:23 -04:00
committed by GitHub
parent 50b555cde4
commit 7c1d537c2f
3 changed files with 22 additions and 2 deletions
+1
View File
@@ -6,6 +6,7 @@ import Test1374 from './src/Test1374';
import Test1718 from './src/Test1718';
import Test1813 from './src/Test1813';
import Test1845 from './src/Test1845';
import Test2080 from './src/Test2080';
import PointerEventsBoxNone from './src/PointerEventsBoxNone';
export default function App() {
+17
View File
@@ -0,0 +1,17 @@
import * as React from 'react';
import { View } from 'react-native';
import Svg, {Rect} from 'react-native-svg';
export default function App() {
return (
<View style={{flex: 1}}>
<Svg width="100%" height="100%" viewBox="0 0 56 56" color="red">
<Rect width="20" height="20" rx="4" fill="currentColor" opacity={0.2} />
<Rect x="0" y="25" width="20" height="20" rx="4" fill="red" opacity={0.2} />
<Rect x="25" y="0" width="20" height="20" rx="4" fill="red" />
<Rect x="25" y="25" width="20" height="20" rx="4" fill="blue" fillOpacity="0.2" />
</Svg>
</View>
);
}
@@ -570,8 +570,10 @@ public abstract class RenderableView extends VirtualView implements ReactHitSlop
}
case 2:
{
int brush = getSvgView().mTintColor;
paint.setColor(brush);
int color = getSvgView().mTintColor;
int alpha = color >>> 24;
alpha = Math.round((float) alpha * opacity);
paint.setColor(alpha << 24 | (color & 0x00ffffff));
break;
}
case 3: