@archireport/react-native-svg-draw 2.2.0 → 2.3.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.
Files changed (59) hide show
  1. package/lib/commonjs/components/DrawCore/CurrentAnimatedItem.js +284 -29
  2. package/lib/commonjs/components/DrawCore/CurrentAnimatedItem.js.map +1 -1
  3. package/lib/commonjs/components/DrawCore/CurrentAnimatedText.js +12 -11
  4. package/lib/commonjs/components/DrawCore/CurrentAnimatedText.js.map +1 -1
  5. package/lib/commonjs/components/DrawCore/DrawContext.js.map +1 -1
  6. package/lib/commonjs/components/DrawCore/DrawPad.js +21 -7
  7. package/lib/commonjs/components/DrawCore/DrawPad.js.map +1 -1
  8. package/lib/commonjs/components/DrawCore/DrawProvider.js +6 -2
  9. package/lib/commonjs/components/DrawCore/DrawProvider.js.map +1 -1
  10. package/lib/commonjs/components/DrawCore/Item.js +154 -7
  11. package/lib/commonjs/components/DrawCore/Item.js.map +1 -1
  12. package/lib/commonjs/components/DrawCore/index.js +175 -83
  13. package/lib/commonjs/components/DrawCore/index.js.map +1 -1
  14. package/lib/commonjs/components/DrawCore/useDrawHook.js +4 -2
  15. package/lib/commonjs/components/DrawCore/useDrawHook.js.map +1 -1
  16. package/lib/commonjs/components/DrawWithOptions/index.js +14 -0
  17. package/lib/commonjs/components/DrawWithOptions/index.js.map +1 -1
  18. package/lib/module/components/DrawCore/CurrentAnimatedItem.js +286 -31
  19. package/lib/module/components/DrawCore/CurrentAnimatedItem.js.map +1 -1
  20. package/lib/module/components/DrawCore/CurrentAnimatedText.js +12 -11
  21. package/lib/module/components/DrawCore/CurrentAnimatedText.js.map +1 -1
  22. package/lib/module/components/DrawCore/DrawContext.js.map +1 -1
  23. package/lib/module/components/DrawCore/DrawPad.js +21 -7
  24. package/lib/module/components/DrawCore/DrawPad.js.map +1 -1
  25. package/lib/module/components/DrawCore/DrawProvider.js +6 -2
  26. package/lib/module/components/DrawCore/DrawProvider.js.map +1 -1
  27. package/lib/module/components/DrawCore/Item.js +150 -9
  28. package/lib/module/components/DrawCore/Item.js.map +1 -1
  29. package/lib/module/components/DrawCore/index.js +176 -84
  30. package/lib/module/components/DrawCore/index.js.map +1 -1
  31. package/lib/module/components/DrawCore/useDrawHook.js +4 -2
  32. package/lib/module/components/DrawCore/useDrawHook.js.map +1 -1
  33. package/lib/module/components/DrawWithOptions/index.js +14 -0
  34. package/lib/module/components/DrawWithOptions/index.js.map +1 -1
  35. package/lib/typescript/components/DrawCore/CurrentAnimatedItem.d.ts +3 -5
  36. package/lib/typescript/components/DrawCore/CurrentAnimatedItem.d.ts.map +1 -1
  37. package/lib/typescript/components/DrawCore/CurrentAnimatedText.d.ts.map +1 -1
  38. package/lib/typescript/components/DrawCore/DrawContext.d.ts +2 -0
  39. package/lib/typescript/components/DrawCore/DrawContext.d.ts.map +1 -1
  40. package/lib/typescript/components/DrawCore/DrawPad.d.ts +2 -1
  41. package/lib/typescript/components/DrawCore/DrawPad.d.ts.map +1 -1
  42. package/lib/typescript/components/DrawCore/DrawProvider.d.ts.map +1 -1
  43. package/lib/typescript/components/DrawCore/Item.d.ts +27 -0
  44. package/lib/typescript/components/DrawCore/Item.d.ts.map +1 -1
  45. package/lib/typescript/components/DrawCore/index.d.ts.map +1 -1
  46. package/lib/typescript/components/DrawCore/useDrawHook.d.ts +1 -0
  47. package/lib/typescript/components/DrawCore/useDrawHook.d.ts.map +1 -1
  48. package/lib/typescript/components/DrawWithOptions/index.d.ts.map +1 -1
  49. package/package.json +1 -1
  50. package/src/components/DrawCore/CurrentAnimatedItem.tsx +307 -7
  51. package/src/components/DrawCore/CurrentAnimatedText.tsx +5 -2
  52. package/src/components/DrawCore/DrawContext.tsx +2 -0
  53. package/src/components/DrawCore/DrawPad.tsx +20 -4
  54. package/src/components/DrawCore/DrawProvider.tsx +6 -0
  55. package/src/components/DrawCore/Item.tsx +188 -7
  56. package/src/components/DrawCore/index.tsx +243 -120
  57. package/src/components/DrawCore/useDrawHook.tsx +2 -0
  58. package/src/components/DrawWithOptions/index.tsx +18 -0
  59. package/src/types.d.ts +7 -0
@@ -1,16 +1,24 @@
1
1
  import React from 'react';
2
2
  import { View, Text, StyleSheet } from 'react-native';
3
- import { G, Line, Ellipse, Rect, Path, ForeignObject } from 'react-native-svg';
3
+ import {
4
+ G,
5
+ Line,
6
+ Ellipse,
7
+ Rect,
8
+ Path,
9
+ ForeignObject,
10
+ Text as SvgText,
11
+ } from 'react-native-svg';
4
12
  import type { DrawItem } from '../../types';
5
- import { pointsToPath } from './CurrentAnimatedItem';
13
+ import { hslToRgb, pointsToPath } from './CurrentAnimatedItem';
6
14
 
7
15
  const styles = StyleSheet.create({
8
16
  textZone: {
9
17
  paddingHorizontal: 10,
10
18
  },
11
19
  textContainer: {
12
- backgroundColor: 'rgba(0, 0, 0, 0.6)',
13
- borderRadius: 10,
20
+ //backgroundColor: 'rgba(0, 0, 0, 0.6)',
21
+ //borderRadius: 10,
14
22
  paddingVertical: 13,
15
23
  paddingHorizontal: 18,
16
24
  },
@@ -19,6 +27,139 @@ const styles = StyleSheet.create({
19
27
  },
20
28
  });
21
29
 
30
+ export const distance = (x1: number, y1: number, x2: number, y2: number) => {
31
+ return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
32
+ };
33
+
34
+ export const getGetcoordinateValue = ({
35
+ x1,
36
+ y1,
37
+ x2,
38
+ y2,
39
+ first = true,
40
+ text = '',
41
+ }: {
42
+ x1: number;
43
+ y1: number;
44
+ x2: number;
45
+ y2: number;
46
+ first: boolean;
47
+ text: string;
48
+ }) => {
49
+ const dist = distance(x1, y1, x2, y2);
50
+ const textLength = text && text.length > 5 ? text.length * 10 : 50;
51
+ //const isShortArrow = textLength > dist;
52
+ const newDist = (!textLength ? dist : dist - textLength) / 2;
53
+
54
+ const ratio = newDist / dist;
55
+ let newX1 = x1;
56
+ let newY1 = y1;
57
+ let newX2 = x2;
58
+ let newY2 = y2;
59
+
60
+ if (newDist > 10) {
61
+ [newX1, newX2] = getCoordinatesWithRatio({
62
+ c1: x1,
63
+ c2: x2,
64
+ ratio,
65
+ first,
66
+ });
67
+ [newY1, newY2] = getCoordinatesWithRatio({
68
+ c1: y1,
69
+ c2: y2,
70
+ ratio,
71
+ first,
72
+ });
73
+ }
74
+ return [newX1, newY1, newX2, newY2];
75
+ };
76
+
77
+ export const getCoordinatesWithRatio = ({
78
+ c1,
79
+ c2,
80
+ ratio,
81
+ first = true,
82
+ }: {
83
+ c1: number;
84
+ c2: number;
85
+ ratio: number;
86
+ first?: boolean;
87
+ }): [number, number] => {
88
+ let newC1 = c1;
89
+ let newC2 = c2;
90
+
91
+ if (c1 > c2) {
92
+ if (first) {
93
+ newC2 = c1 - (c1 - c2) * ratio;
94
+ } else {
95
+ newC1 = c2 + (c1 - c2) * ratio;
96
+ }
97
+ } else {
98
+ if (first) {
99
+ newC2 = c1 + (c2 - c1) * ratio;
100
+ } else {
101
+ newC1 = c2 - (c2 - c1) * ratio;
102
+ }
103
+ }
104
+
105
+ return [newC1 as number, newC2 as number];
106
+ };
107
+
108
+ export const doubleArrowsProps = (item: DrawItem, first: boolean) => {
109
+ const coordinates =
110
+ item.type === 'doubleArrows'
111
+ ? item.data
112
+ : { x1: -10, y1: -10, x2: -10, y2: -10 };
113
+
114
+ const [x1, y1, x2, y2] = getGetcoordinateValue({
115
+ x1: Number(coordinates.x1),
116
+ y1: Number(coordinates.y1),
117
+ x2: Number(coordinates.x2),
118
+ y2: Number(coordinates.y2),
119
+ first: first,
120
+ text: item.type === 'doubleArrows' && item.text ? item.text : '',
121
+ });
122
+ return {
123
+ x1: String(x1),
124
+ y1: String(y1),
125
+ x2: String(x2),
126
+ y2: String(y2),
127
+ };
128
+ };
129
+
130
+ export const getTextValues = ({
131
+ x1,
132
+ y1,
133
+ x2,
134
+ y2,
135
+ }: {
136
+ x1: number;
137
+ y1: number;
138
+ x2: number;
139
+ y2: number;
140
+ }) => {
141
+ const dist = distance(x1, y1, x2, y2);
142
+ const ratio = 0.5;
143
+ const newX = (x1 + x2) * ratio;
144
+ const newY = (y1 + y2) * ratio;
145
+
146
+ let angle = 0;
147
+ if (x1 > x2) {
148
+ if (y1 > y2) {
149
+ angle = Math.acos((x1 - x2) / dist) * (180 / Math.PI);
150
+ } else {
151
+ angle = 180 - Math.acos((x1 - x2) / dist) * (180 / Math.PI) + 180;
152
+ }
153
+ } else {
154
+ if (y1 > y2) {
155
+ angle = 180 - Math.acos((x2 - x1) / dist) * (180 / Math.PI) + 180;
156
+ } else {
157
+ angle = Math.acos((x2 - x1) / dist) * (180 / Math.PI);
158
+ }
159
+ }
160
+
161
+ return [newX, newY, angle];
162
+ };
22
163
  export default function Item({
23
164
  item,
24
165
  onPress,
@@ -29,7 +170,7 @@ export default function Item({
29
170
  switch (item.type) {
30
171
  case 'singleHead':
31
172
  return (
32
- <G onPressIn={onPress}>
173
+ <G onPress={onPress}>
33
174
  <Line
34
175
  {...item.data}
35
176
  fill="none"
@@ -41,7 +182,7 @@ export default function Item({
41
182
  );
42
183
  case 'doubleHead':
43
184
  return (
44
- <G onPressIn={onPress}>
185
+ <G onPress={onPress}>
45
186
  <Line
46
187
  {...item.data}
47
188
  fill="none"
@@ -52,6 +193,45 @@ export default function Item({
52
193
  />
53
194
  </G>
54
195
  );
196
+ case 'doubleArrows':
197
+ const [textX, textY, angle] = getTextValues({
198
+ x1: Number(item.data.x1),
199
+ y1: Number(item.data.y1),
200
+ x2: Number(item.data.x2),
201
+ y2: Number(item.data.y2),
202
+ });
203
+ return (
204
+ <G>
205
+ <Line
206
+ {...doubleArrowsProps(item, true)}
207
+ fill="none"
208
+ stroke={item.color}
209
+ strokeWidth={item.strokeWidth}
210
+ markerStart="url(#arrowheadStart)"
211
+ onPress={onPress}
212
+ />
213
+ <G x={String(textX)} y={String(textY)} rotation={String(angle)}>
214
+ <SvgText
215
+ stroke={item.color}
216
+ fill={item.color}
217
+ textAnchor="middle"
218
+ fontSize={item.strokeWidth + 10}
219
+ onPress={onPress}
220
+ >
221
+ {item.text}
222
+ </SvgText>
223
+ </G>
224
+
225
+ <Line
226
+ {...doubleArrowsProps(item, false)}
227
+ fill="none"
228
+ stroke={item.color}
229
+ strokeWidth={item.strokeWidth}
230
+ markerEnd="url(#arrowhead)"
231
+ onPress={onPress}
232
+ />
233
+ </G>
234
+ );
55
235
  case 'ellipse':
56
236
  return (
57
237
  <Ellipse
@@ -105,7 +285,8 @@ export default function Item({
105
285
  style={[
106
286
  styles.text,
107
287
  {
108
- fontSize: 14 + item.strokeWidth,
288
+ fontSize: 10 + item.strokeWidth * 2,
289
+ color: item.color ? hslToRgb(item.color) : 'white',
109
290
  },
110
291
  ]}
111
292
  >