@archireport/react-native-svg-draw 2.3.2 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -35
- package/lib/commonjs/components/DrawCore/DrawContext.js +4 -1
- package/lib/commonjs/components/DrawCore/DrawContext.js.map +1 -1
- package/lib/commonjs/components/DrawCore/DrawPad.js +9 -3
- package/lib/commonjs/components/DrawCore/DrawPad.js.map +1 -1
- package/lib/commonjs/components/DrawCore/DrawProvider.js +16 -2
- package/lib/commonjs/components/DrawCore/DrawProvider.js.map +1 -1
- package/lib/commonjs/components/DrawCore/Item.js +12 -35
- package/lib/commonjs/components/DrawCore/Item.js.map +1 -1
- package/lib/commonjs/components/DrawCore/index.js +574 -576
- package/lib/commonjs/components/DrawCore/index.js.map +1 -1
- package/lib/commonjs/components/DrawCore/useDrawHook.js +15 -13
- package/lib/commonjs/components/DrawCore/useDrawHook.js.map +1 -1
- package/lib/commonjs/components/DrawWithOptions/index.js +7 -11
- package/lib/commonjs/components/DrawWithOptions/index.js.map +1 -1
- package/lib/module/components/DrawCore/DrawContext.js +4 -1
- package/lib/module/components/DrawCore/DrawContext.js.map +1 -1
- package/lib/module/components/DrawCore/DrawPad.js +10 -4
- package/lib/module/components/DrawCore/DrawPad.js.map +1 -1
- package/lib/module/components/DrawCore/DrawProvider.js +17 -3
- package/lib/module/components/DrawCore/DrawProvider.js.map +1 -1
- package/lib/module/components/DrawCore/Item.js +14 -37
- package/lib/module/components/DrawCore/Item.js.map +1 -1
- package/lib/module/components/DrawCore/index.js +575 -577
- package/lib/module/components/DrawCore/index.js.map +1 -1
- package/lib/module/components/DrawCore/useDrawHook.js +15 -13
- package/lib/module/components/DrawCore/useDrawHook.js.map +1 -1
- package/lib/module/components/DrawWithOptions/index.js +8 -12
- package/lib/module/components/DrawWithOptions/index.js.map +1 -1
- package/lib/typescript/components/DrawCore/DrawContext.d.ts +3 -0
- package/lib/typescript/components/DrawCore/DrawContext.d.ts.map +1 -1
- package/lib/typescript/components/DrawCore/DrawPad.d.ts +2 -1
- package/lib/typescript/components/DrawCore/DrawPad.d.ts.map +1 -1
- package/lib/typescript/components/DrawCore/DrawProvider.d.ts.map +1 -1
- package/lib/typescript/components/DrawCore/Item.d.ts.map +1 -1
- package/lib/typescript/components/DrawCore/index.d.ts +2 -1
- package/lib/typescript/components/DrawCore/index.d.ts.map +1 -1
- package/lib/typescript/components/DrawCore/useDrawHook.d.ts +4 -1
- package/lib/typescript/components/DrawCore/useDrawHook.d.ts.map +1 -1
- package/lib/typescript/components/DrawWithOptions/index.d.ts +1 -1
- package/lib/typescript/components/DrawWithOptions/index.d.ts.map +1 -1
- package/package.json +5 -1
- package/src/components/DrawCore/DrawContext.tsx +6 -0
- package/src/components/DrawCore/DrawPad.tsx +76 -67
- package/src/components/DrawCore/DrawProvider.tsx +23 -1
- package/src/components/DrawCore/Item.tsx +15 -47
- package/src/components/DrawCore/index.tsx +109 -114
- package/src/components/DrawCore/useDrawHook.tsx +12 -7
- package/src/components/DrawWithOptions/index.tsx +10 -11
- package/src/types.d.ts +5 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type Animated from 'react-native-reanimated';
|
|
3
|
-
import Svg, { Circle, Defs, Marker, Polyline, Use } from 'react-native-svg';
|
|
3
|
+
import Svg, { Circle, Defs, G, Marker, Polyline, Use } from 'react-native-svg';
|
|
4
4
|
import CurrentAnimatedItem from './CurrentAnimatedItem';
|
|
5
5
|
import CurrentAnimatedText from './CurrentAnimatedText';
|
|
6
6
|
import Item from './Item';
|
|
@@ -13,86 +13,95 @@ const DrawPad = ({
|
|
|
13
13
|
onPressItem,
|
|
14
14
|
onTextHeightChange,
|
|
15
15
|
addBackground = false,
|
|
16
|
+
ratioImage = 1,
|
|
16
17
|
}: {
|
|
17
18
|
currentItem: Animated.SharedValue<DrawItem | null>;
|
|
18
19
|
doneItems: Array<DrawItem>;
|
|
19
20
|
onPressItem: (item: DrawItem, index: number) => () => void;
|
|
20
21
|
onTextHeightChange: (height: number) => void;
|
|
21
22
|
addBackground?: boolean;
|
|
23
|
+
ratioImage?: number;
|
|
22
24
|
}) => {
|
|
23
25
|
return (
|
|
24
26
|
<>
|
|
25
|
-
<Svg
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
orient="auto"
|
|
42
|
-
>
|
|
43
|
-
<Polyline
|
|
44
|
-
points="-2,-2 0,0 -2,2 0,0"
|
|
45
|
-
stroke="context-stroke"
|
|
46
|
-
strokeLinecap="round"
|
|
47
|
-
strokeLinejoin="round"
|
|
27
|
+
<Svg
|
|
28
|
+
style={addBackground ? { backgroundColor: 'white' } : null}
|
|
29
|
+
preserveAspectRatio="xMinYMin slice"
|
|
30
|
+
height="100%"
|
|
31
|
+
width="100%"
|
|
32
|
+
>
|
|
33
|
+
<G scale={ratioImage}>
|
|
34
|
+
<Defs>
|
|
35
|
+
<Circle
|
|
36
|
+
id="selectionIndicator"
|
|
37
|
+
fill="#3a6cff"
|
|
38
|
+
r={10}
|
|
39
|
+
cx={0}
|
|
40
|
+
cy={0}
|
|
41
|
+
strokeWidth={1}
|
|
42
|
+
stroke="black"
|
|
48
43
|
/>
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
44
|
+
<Marker
|
|
45
|
+
id="arrowhead"
|
|
46
|
+
markerUnits={'strokeWidth' as MarkerUnits}
|
|
47
|
+
refX="0"
|
|
48
|
+
refY="0"
|
|
49
|
+
orient="auto"
|
|
50
|
+
>
|
|
51
|
+
<Polyline
|
|
52
|
+
points="-2,-2 0,0 -2,2 0,0"
|
|
53
|
+
stroke="context-stroke"
|
|
54
|
+
strokeLinecap="round"
|
|
55
|
+
strokeLinejoin="round"
|
|
56
|
+
/>
|
|
57
|
+
</Marker>
|
|
58
|
+
<Marker
|
|
59
|
+
id="arrowheadStart"
|
|
60
|
+
markerUnits={'strokeWidth' as MarkerUnits}
|
|
61
|
+
refX="0"
|
|
62
|
+
refY="0"
|
|
63
|
+
orient="auto"
|
|
64
|
+
>
|
|
65
|
+
<Polyline
|
|
66
|
+
points="2,-2 0,0 2,2 0,0"
|
|
67
|
+
stroke="context-stroke"
|
|
68
|
+
strokeLinecap="round"
|
|
69
|
+
strokeLinejoin="round"
|
|
70
|
+
/>
|
|
71
|
+
</Marker>
|
|
64
72
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
73
|
+
<Marker
|
|
74
|
+
id="side"
|
|
75
|
+
markerUnits={'strokeWidth' as MarkerUnits}
|
|
76
|
+
refX="0"
|
|
77
|
+
refY="0"
|
|
78
|
+
orient="auto"
|
|
79
|
+
>
|
|
80
|
+
<Polyline
|
|
81
|
+
stroke="context-stroke"
|
|
82
|
+
points="0,-2 0,2 0,0"
|
|
83
|
+
strokeLinecap="round"
|
|
84
|
+
strokeLinejoin="round"
|
|
85
|
+
/>
|
|
86
|
+
</Marker>
|
|
79
87
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
<Marker
|
|
89
|
+
id="selection"
|
|
90
|
+
markerUnits={'userSpaceOnUse' as MarkerUnits}
|
|
91
|
+
refX="0"
|
|
92
|
+
refY="0"
|
|
93
|
+
orient="auto"
|
|
94
|
+
>
|
|
95
|
+
<Use href="#selectionIndicator" />
|
|
96
|
+
</Marker>
|
|
97
|
+
</Defs>
|
|
90
98
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
99
|
+
{doneItems.map((item, index) => (
|
|
100
|
+
<Item key={index} item={item} onPress={onPressItem(item, index)} />
|
|
101
|
+
))}
|
|
94
102
|
|
|
95
|
-
|
|
103
|
+
<CurrentAnimatedItem />
|
|
104
|
+
</G>
|
|
96
105
|
</Svg>
|
|
97
106
|
<CurrentAnimatedText
|
|
98
107
|
currentItem={currentItem}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { DrawContext } from './DrawContext';
|
|
2
|
-
import React, {
|
|
2
|
+
import React, {
|
|
3
|
+
ReactElement,
|
|
4
|
+
useCallback,
|
|
5
|
+
useMemo,
|
|
6
|
+
useReducer,
|
|
7
|
+
useRef,
|
|
8
|
+
useState,
|
|
9
|
+
} from 'react';
|
|
3
10
|
import type { Action, DrawItem, DrawState, hslColor } from '../../types';
|
|
4
11
|
import { useSharedValue } from 'react-native-reanimated';
|
|
5
12
|
import type ViewShot from 'react-native-view-shot';
|
|
@@ -92,10 +99,19 @@ const DrawProvider = ({ children }: { children: ReactElement }) => {
|
|
|
92
99
|
const viewShot = useRef<ViewShot>(null);
|
|
93
100
|
const doubleArrowTextInput = useRef<TextInput>(null);
|
|
94
101
|
|
|
102
|
+
const [snapShotRequested, setSnapShotRequested] = useState(false);
|
|
103
|
+
|
|
95
104
|
const [drawState, dispatchDrawStates] = useReducer(
|
|
96
105
|
reducerDrawStates,
|
|
97
106
|
initialState
|
|
98
107
|
);
|
|
108
|
+
const doSnapshot = useCallback(() => {
|
|
109
|
+
if (currentItem?.value) {
|
|
110
|
+
dispatchDrawStates({ type: 'ADD_DONE_ITEM', item: currentItem.value });
|
|
111
|
+
currentItem.value = null;
|
|
112
|
+
}
|
|
113
|
+
setSnapShotRequested(true);
|
|
114
|
+
}, [currentItem, dispatchDrawStates]);
|
|
99
115
|
|
|
100
116
|
const contextValue = useMemo(
|
|
101
117
|
() => ({
|
|
@@ -107,6 +123,9 @@ const DrawProvider = ({ children }: { children: ReactElement }) => {
|
|
|
107
123
|
itemIsSelected,
|
|
108
124
|
viewShot,
|
|
109
125
|
doubleArrowTextInput,
|
|
126
|
+
doSnapshot,
|
|
127
|
+
snapShotRequested,
|
|
128
|
+
setSnapShotRequested,
|
|
110
129
|
}),
|
|
111
130
|
[
|
|
112
131
|
drawState,
|
|
@@ -117,6 +136,9 @@ const DrawProvider = ({ children }: { children: ReactElement }) => {
|
|
|
117
136
|
itemIsSelected,
|
|
118
137
|
viewShot,
|
|
119
138
|
doubleArrowTextInput,
|
|
139
|
+
doSnapshot,
|
|
140
|
+
snapShotRequested,
|
|
141
|
+
setSnapShotRequested,
|
|
120
142
|
]
|
|
121
143
|
);
|
|
122
144
|
|
|
@@ -1,31 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { View, Text, StyleSheet } from 'react-native';
|
|
3
2
|
import {
|
|
4
3
|
G,
|
|
5
4
|
Line,
|
|
6
5
|
Ellipse,
|
|
7
6
|
Rect,
|
|
8
7
|
Path,
|
|
9
|
-
ForeignObject,
|
|
10
8
|
Text as SvgText,
|
|
11
9
|
} from 'react-native-svg';
|
|
12
10
|
import type { DrawItem } from '../../types';
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
const styles = StyleSheet.create({
|
|
16
|
-
textZone: {
|
|
17
|
-
paddingHorizontal: 10,
|
|
18
|
-
},
|
|
19
|
-
textContainer: {
|
|
20
|
-
//backgroundColor: 'rgba(0, 0, 0, 0.6)',
|
|
21
|
-
//borderRadius: 10,
|
|
22
|
-
paddingVertical: 13,
|
|
23
|
-
paddingHorizontal: 18,
|
|
24
|
-
},
|
|
25
|
-
text: {
|
|
26
|
-
color: 'white',
|
|
27
|
-
},
|
|
28
|
-
});
|
|
11
|
+
import { pointsToPath } from './CurrentAnimatedItem';
|
|
29
12
|
|
|
30
13
|
export const distance = (x1: number, y1: number, x2: number, y2: number) => {
|
|
31
14
|
return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
|
|
@@ -263,38 +246,23 @@ export default function Item({
|
|
|
263
246
|
/>
|
|
264
247
|
);
|
|
265
248
|
case 'text':
|
|
249
|
+
//console.log('Rendering text item:', JSON.stringify(item, null, 2));
|
|
266
250
|
return (
|
|
267
|
-
<G onPress={onPress}>
|
|
268
|
-
<
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
y={item.data.y}
|
|
272
|
-
width={item.data.width}
|
|
273
|
-
key={item.text}
|
|
251
|
+
<G onPress={onPress} fill={'red'}>
|
|
252
|
+
<G
|
|
253
|
+
x={String(item.data.x)}
|
|
254
|
+
y={String(Number(item.data.y ?? 0) + 2 * item.strokeWidth + 13)}
|
|
274
255
|
>
|
|
275
|
-
<
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
]}
|
|
256
|
+
<SvgText
|
|
257
|
+
stroke={item.color}
|
|
258
|
+
fill={item.color}
|
|
259
|
+
textAnchor="start"
|
|
260
|
+
fontSize={2 * item.strokeWidth + 10}
|
|
261
|
+
onPress={onPress}
|
|
282
262
|
>
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
styles.text,
|
|
287
|
-
{
|
|
288
|
-
fontSize: 10 + item.strokeWidth * 2,
|
|
289
|
-
color: item.color ? hslToRgb(item.color) : 'white',
|
|
290
|
-
},
|
|
291
|
-
]}
|
|
292
|
-
>
|
|
293
|
-
{item.text}
|
|
294
|
-
</Text>
|
|
295
|
-
</View>
|
|
296
|
-
</View>
|
|
297
|
-
</ForeignObject>
|
|
263
|
+
{item.text}
|
|
264
|
+
</SvgText>
|
|
265
|
+
</G>
|
|
298
266
|
</G>
|
|
299
267
|
);
|
|
300
268
|
|