feat: implement mask-type property (#2152)

# Summary

"mask-type: alpha" is not supported. 
resolve issue: #1790  

## Explanation

svg example:
```
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100" fill="none">
<g clip-path="url(#clip0_8_3)">
<rect width="100" height="100" fill="white"/>
<mask id="mask0_8_3" mask-type="alpha" maskUnits="userSpaceOnUse" x="0" y="0" width="100" height="100">
<circle cx="50" cy="50" r="50" fill="#000000"/>
</mask>
<g mask="url(#mask0_8_3)">
<rect x="-26" y="-78" width="209" height="263" fill="#252E74"/>
</g>
</g>
<defs>
<clipPath id="clip0_8_3">
<rect width="100" height="100" fill="white"/>
</clipPath>
</defs>
</svg>
```

Current behavior: 

![image](https://github.com/software-mansion/react-native-svg/assets/17138397/2dca6f46-fe8f-48f3-80f9-799563911e8b)

Expected behavior:

![image](https://github.com/software-mansion/react-native-svg/assets/17138397/fb49cf0b-d677-491f-8215-9c9b1d69080f)

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| iOS     |        |
| Android |        |

## Checklist

<!-- Check completed item, when applicable, via: [X] -->

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

---------

Co-authored-by: Sergey <s.yurkevich@logiclike.com>
Co-authored-by: Jakub Grzywacz <jakub.grzywacz@swmansion.com>
This commit is contained in:
SergeyYurkevich
2024-07-05 16:11:48 +03:00
committed by GitHub
parent 7c1602e291
commit 832522d1c1
19 changed files with 166 additions and 40 deletions
+17 -2
View File
@@ -6,8 +6,10 @@ import units from '../lib/units';
import Shape from './Shape';
import RNSVGMask from '../fabric/MaskNativeComponent';
import type { NativeMethods } from 'react-native';
import { maskType } from '../lib/maskType';
export type TMaskUnits = 'userSpaceOnUse' | 'objectBoundingBox';
export type TMaskType = 'alpha' | 'luminance';
export interface MaskProps extends CommonPathProps {
children?: ReactNode;
@@ -18,6 +20,10 @@ export interface MaskProps extends CommonPathProps {
height?: NumberProp;
maskUnits?: TMaskUnits;
maskContentUnits?: TMaskUnits;
maskType?: TMaskType;
style?: {
maskType: TMaskType;
};
}
export default class Mask extends Shape<MaskProps> {
@@ -32,8 +38,16 @@ export default class Mask extends Shape<MaskProps> {
render() {
const { props } = this;
const { x, y, width, height, maskUnits, maskContentUnits, children } =
props;
const {
x,
y,
width,
height,
maskUnits,
maskContentUnits,
children,
style,
} = props;
const maskProps = {
x,
y,
@@ -42,6 +56,7 @@ export default class Mask extends Shape<MaskProps> {
maskUnits: maskUnits !== undefined ? units[maskUnits] : 0,
maskContentUnits:
maskContentUnits !== undefined ? units[maskContentUnits] : 1,
maskType: maskType[props?.maskType || style?.maskType || 'luminance'],
};
return (
<RNSVGMask
+1
View File
@@ -64,6 +64,7 @@ interface NativeProps
width?: UnsafeMixed<NumberProp>;
maskUnits?: Int32;
maskContentUnits?: Int32;
maskType?: Int32;
}
export default codegenNativeComponent<NativeProps>('RNSVGMask');
+4
View File
@@ -0,0 +1,4 @@
export const maskType = {
luminance: 0,
alpha: 1,
} as const;