Skip to content

Commit e6a27f8

Browse files
authored
feat: FeDropShadow (#2514)
# Summary Continuation of #2362 introducing highly requested ✨ `FeDropShadow` ✨ filter. This addition is straightforward since it's essentially a shorthand (as specified in the spec) for filters that are already implemented: https://www.w3.org/TR/filter-effects-1/#feDropShadowElement <img width="532" alt="image" src="https://github.com/user-attachments/assets/b221ee4c-d8b0-469b-acb0-71224fb2b1e0"> ## Test Plan Example app -> Filters -> FeDropShadow ## Compatibility | OS | Implemented | | ------- | :---------: | | iOS | ✅ | | macOS | ✅ | | Android | ✅ | | Web | ✅ |
1 parent 36ca5c4 commit e6a27f8

File tree

4 files changed

+88
-5
lines changed

4 files changed

+88
-5
lines changed

USAGE.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,9 @@ Filter effects are a way of processing an element’s rendering before it is dis
13011301
The following filters have been implemented:
13021302

13031303
- FeBlend
1304+
- FeComposite
13041305
- FeColorMatrix
1306+
- FeDropShadow
13051307
- FeFlood
13061308
- FeGaussianBlur
13071309
- FeMerge
@@ -1310,11 +1312,9 @@ The following filters have been implemented:
13101312
Not supported yet:
13111313

13121314
- FeComponentTransfer
1313-
- FeComposite
13141315
- FeConvolveMatrix
13151316
- FeDiffuseLighting
13161317
- FeDisplacementMap
1317-
- FeDropShadow
13181318
- FeFuncA
13191319
- FeFuncB
13201320
- FeFuncG
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import React from 'react';
2+
import {
3+
Circle,
4+
FeDropShadow,
5+
FeFlood,
6+
Filter,
7+
Rect,
8+
Svg,
9+
} from 'react-native-svg';
10+
11+
BasicMDN.title = 'Basic MDN example';
12+
function BasicMDN() {
13+
return (
14+
<Svg viewBox="0 0 30 10" width="300" height="100">
15+
<Filter id="shadow">
16+
<FeDropShadow dx="0.2" dy="0.4" stdDeviation="0.2" />
17+
</Filter>
18+
<Filter id="shadow2">
19+
<FeDropShadow dx="0" dy="0" stdDeviation="5" floodColor="cyan" />
20+
</Filter>
21+
<Filter id="shadow3">
22+
<FeDropShadow
23+
dx="-0.8"
24+
dy="-0.8"
25+
stdDeviation="0"
26+
floodColor="pink"
27+
floodOpacity="0.5"
28+
/>
29+
</Filter>
30+
<Circle cx="5" cy="50%" r="4" fill="pink" filter="url(#shadow)" />
31+
<Circle cx="15" cy="50%" r="4" fill="pink" filter="url(#shadow2)" />
32+
<Circle cx="25" cy="50%" r="4" fill="pink" filter="url(#shadow3)" />
33+
</Svg>
34+
);
35+
}
36+
37+
const icon = (
38+
<Svg height="30" width="30" viewBox="0 0 140 140">
39+
<Filter
40+
id="floodFilterIcon"
41+
x="50%"
42+
filterUnits="userSpaceOnUse"
43+
primitiveUnits="userSpaceOnUse">
44+
<FeFlood
45+
y="-10%"
46+
x="10%"
47+
width="50%"
48+
height="50%"
49+
floodColor="yellow"
50+
floodOpacity="0.5"
51+
/>
52+
</Filter>
53+
<Rect x="0" y="0" width="100" height="100" fill="blue" />
54+
<Circle cx="50" cy="50" r="40" filter="url(#floodFilterIcon)" />
55+
</Svg>
56+
);
57+
const samples = [BasicMDN];
58+
59+
export {icon, samples};

apps/common/example/examples/Filters/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Svg, {Circle} from 'react-native-svg';
33
import * as FeBlend from './FeBlend';
44
import * as FeColorMatrix from './FeColorMatrix';
55
import * as FeComposite from './FeComposite';
6+
import * as FeDropShadow from './FeDropShadow';
67
import * as FeFlood from './FeFlood';
78
import * as FeGaussianBlur from './FeGaussianBlur';
89
import * as FeMerge from './FeMerge';
@@ -13,6 +14,7 @@ const samples = {
1314
FeBlend,
1415
FeColorMatrix,
1516
FeComposite,
17+
FeDropShadow,
1618
FeFlood,
1719
FeGaussianBlur,
1820
FeMerge,

src/elements/filters/FeDropShadow.tsx

+25-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1+
import { ColorValue } from 'react-native';
12
import { NumberArray, NumberProp } from '../../lib/extract/types';
2-
import { warnUnimplementedFilter } from '../../lib/util';
3+
import FeFlood from './FeFlood';
4+
import FeGaussianBlur from './FeGaussianBlur';
5+
import FeMerge from './FeMerge';
6+
import FeMergeNode from './FeMergeNode';
7+
import FeOffset from './FeOffset';
38
import FilterPrimitive from './FilterPrimitive';
9+
import FeComposite from './FeComposite';
410

511
export interface FeDropShadowProps {
612
in?: string;
713
stdDeviation?: NumberArray;
814
dx?: NumberProp;
915
dy?: NumberProp;
16+
floodColor?: ColorValue;
17+
floodOpacity?: NumberProp;
1018
}
1119

1220
export default class FeDropShadow extends FilterPrimitive<FeDropShadowProps> {
@@ -17,7 +25,21 @@ export default class FeDropShadow extends FilterPrimitive<FeDropShadowProps> {
1725
};
1826

1927
render() {
20-
warnUnimplementedFilter();
21-
return null;
28+
const { stdDeviation, in: in1 = 'SourceGraphic', dx, dy } = this.props;
29+
return (
30+
<>
31+
<FeGaussianBlur in={in1} stdDeviation={stdDeviation} />
32+
<FeOffset dx={dx} dy={dy} result="offsetblur" />
33+
<FeFlood
34+
floodColor={this.props.floodColor}
35+
floodOpacity={this.props.floodOpacity}
36+
/>
37+
<FeComposite in2="offsetblur" operator="in" />
38+
<FeMerge>
39+
<FeMergeNode />
40+
<FeMergeNode in={in1} />
41+
</FeMerge>
42+
</>
43+
);
2244
}
2345
}

0 commit comments

Comments
 (0)