Skip to content

Commit e2e5b03

Browse files
bohdanprogjakex7
authored andcommitted
fix: extractBrush parameter type (#2670)
Update type in method `extractBrush` A color value should never be undefined or null. There is a check implemented like this: `!fill && typeof fill !== 'number'` You can easily run an example application with Test2670, which I've created. | OS | Implemented | | ------- | :---------: | | iOS | ✅ | | MacOS | ✅ | | Android | ✅ | | Web | ✅ | ---------
1 parent 51abb13 commit e2e5b03

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

apps/common/test/Test2670.tsx

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import React, {useState} from 'react';
2+
import {View, Button, Text} from 'react-native';
3+
import {Svg, Path} from 'react-native-svg';
4+
5+
const PathChangingFillFromValueToUndefined = () => {
6+
const [fill, setFill] = useState<string | undefined>(undefined);
7+
8+
const changeFill = () => {
9+
setFill(prevFill => (prevFill ? undefined : 'red'));
10+
};
11+
12+
return (
13+
<View
14+
style={{
15+
width: 200,
16+
margin: 50,
17+
aspectRatio: 1,
18+
alignItems: 'center',
19+
justifyContent: 'center',
20+
}}>
21+
<Text>Path which on a button click sets or resets fill to undefined</Text>
22+
<Button onPress={changeFill} title="Change fill" />
23+
<Svg height="100" width="100">
24+
<Path
25+
d="M25 10 L98 65 L70 25 L16 77 L11 30 L0 4 L90 50 L50 10 L11 22 L77 95 L20 25"
26+
fill={fill}
27+
/>
28+
</Svg>
29+
</View>
30+
);
31+
};
32+
33+
const PathChangingFillFromValueToFillNone = () => {
34+
const [fill, setFill] = useState<string | 'none'>('none');
35+
36+
const changeFill = () => {
37+
setFill(prevFill => (prevFill !== 'none' ? 'none' : 'red'));
38+
};
39+
40+
return (
41+
<View
42+
style={{
43+
width: 200,
44+
margin: 50,
45+
aspectRatio: 1,
46+
alignItems: 'center',
47+
justifyContent: 'center',
48+
}}>
49+
<Text>
50+
Path which on a button click sets or resets fill to none value
51+
</Text>
52+
<Button onPress={changeFill} title="Change fill" />
53+
<Svg height="100" width="100">
54+
<Path
55+
d="M25 10 L98 65 L70 25 L16 77 L11 30 L0 4 L90 50 L50 10 L11 22 L77 95 L20 25"
56+
fill={fill}
57+
/>
58+
</Svg>
59+
</View>
60+
);
61+
};
62+
63+
export default function App() {
64+
return (
65+
<View style={{justifyContent: 'center', alignItems: 'center', flex: 1}}>
66+
<PathChangingFillFromValueToUndefined />
67+
<PathChangingFillFromValueToFillNone />
68+
</View>
69+
);
70+
}

apps/common/test/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import Test2417 from './Test2417';
3535
import Test2455 from './Test2455';
3636
import Test2471 from './Test2471';
3737
import Test2520 from './Test2520';
38+
import Test2670 from './Test2670';
3839

3940
export default function App() {
4041
return <ColorTest />;

src/lib/extract/extractBrush.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ const currentColorBrush = { type: 2 };
88
const contextFillBrush = { type: 3 };
99
const contextStrokeBrush = { type: 4 };
1010

11-
export default function extractBrush(color?: ColorValue) {
12-
if (!color || color === 'none') {
11+
export default function extractBrush(color: ColorValue) {
12+
if (color === 'none') {
1313
return null;
1414
}
1515

0 commit comments

Comments
 (0)