@archireport/react-native-svg-draw 2.2.1 → 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 (115) 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 +14 -5
  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 +163 -76
  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/ArrowSvg.js.map +1 -1
  17. package/lib/commonjs/components/DrawWithOptions/CancelSvg.js.map +1 -1
  18. package/lib/commonjs/components/DrawWithOptions/CircleSvg.js.map +1 -1
  19. package/lib/commonjs/components/DrawWithOptions/CloseSvg.js.map +1 -1
  20. package/lib/commonjs/components/DrawWithOptions/DoubleHeadSvg.js.map +1 -1
  21. package/lib/commonjs/components/DrawWithOptions/PenSvg.js.map +1 -1
  22. package/lib/commonjs/components/DrawWithOptions/SendSvg.js.map +1 -1
  23. package/lib/commonjs/components/DrawWithOptions/SliderSvg.js.map +1 -1
  24. package/lib/commonjs/components/DrawWithOptions/SquareSvg.js.map +1 -1
  25. package/lib/commonjs/components/DrawWithOptions/TextSvg.js.map +1 -1
  26. package/lib/commonjs/components/DrawWithOptions/ThrashSvg.js.map +1 -1
  27. package/lib/commonjs/components/DrawWithOptions/index.js +14 -0
  28. package/lib/commonjs/components/DrawWithOptions/index.js.map +1 -1
  29. package/lib/commonjs/components/Slider/ColorSlider.js.map +1 -1
  30. package/lib/commonjs/components/Slider/Sliders.js.map +1 -1
  31. package/lib/commonjs/components/Slider/StrokeSlider.js.map +1 -1
  32. package/lib/commonjs/components/Slider/sliderStyle.js.map +1 -1
  33. package/lib/commonjs/index.js.map +1 -1
  34. package/lib/module/components/DrawCore/CurrentAnimatedItem.js +286 -31
  35. package/lib/module/components/DrawCore/CurrentAnimatedItem.js.map +1 -1
  36. package/lib/module/components/DrawCore/CurrentAnimatedText.js +12 -11
  37. package/lib/module/components/DrawCore/CurrentAnimatedText.js.map +1 -1
  38. package/lib/module/components/DrawCore/DrawContext.js.map +1 -1
  39. package/lib/module/components/DrawCore/DrawPad.js +14 -5
  40. package/lib/module/components/DrawCore/DrawPad.js.map +1 -1
  41. package/lib/module/components/DrawCore/DrawProvider.js +6 -2
  42. package/lib/module/components/DrawCore/DrawProvider.js.map +1 -1
  43. package/lib/module/components/DrawCore/Item.js +150 -9
  44. package/lib/module/components/DrawCore/Item.js.map +1 -1
  45. package/lib/module/components/DrawCore/index.js +164 -77
  46. package/lib/module/components/DrawCore/index.js.map +1 -1
  47. package/lib/module/components/DrawCore/useDrawHook.js +4 -2
  48. package/lib/module/components/DrawCore/useDrawHook.js.map +1 -1
  49. package/lib/module/components/DrawWithOptions/ArrowSvg.js.map +1 -1
  50. package/lib/module/components/DrawWithOptions/CancelSvg.js.map +1 -1
  51. package/lib/module/components/DrawWithOptions/CircleSvg.js.map +1 -1
  52. package/lib/module/components/DrawWithOptions/CloseSvg.js.map +1 -1
  53. package/lib/module/components/DrawWithOptions/DoubleHeadSvg.js.map +1 -1
  54. package/lib/module/components/DrawWithOptions/PenSvg.js.map +1 -1
  55. package/lib/module/components/DrawWithOptions/SendSvg.js.map +1 -1
  56. package/lib/module/components/DrawWithOptions/SliderSvg.js.map +1 -1
  57. package/lib/module/components/DrawWithOptions/SquareSvg.js.map +1 -1
  58. package/lib/module/components/DrawWithOptions/TextSvg.js.map +1 -1
  59. package/lib/module/components/DrawWithOptions/ThrashSvg.js.map +1 -1
  60. package/lib/module/components/DrawWithOptions/index.js +14 -0
  61. package/lib/module/components/DrawWithOptions/index.js.map +1 -1
  62. package/lib/module/components/Slider/ColorSlider.js.map +1 -1
  63. package/lib/module/components/Slider/Sliders.js.map +1 -1
  64. package/lib/module/components/Slider/StrokeSlider.js.map +1 -1
  65. package/lib/typescript/components/DrawCore/CurrentAnimatedItem.d.ts +3 -6
  66. package/lib/typescript/components/DrawCore/CurrentAnimatedItem.d.ts.map +1 -1
  67. package/lib/typescript/components/DrawCore/CurrentAnimatedText.d.ts +0 -1
  68. package/lib/typescript/components/DrawCore/CurrentAnimatedText.d.ts.map +1 -1
  69. package/lib/typescript/components/DrawCore/DrawContext.d.ts +2 -0
  70. package/lib/typescript/components/DrawCore/DrawContext.d.ts.map +1 -1
  71. package/lib/typescript/components/DrawCore/DrawPad.d.ts +0 -1
  72. package/lib/typescript/components/DrawCore/DrawPad.d.ts.map +1 -1
  73. package/lib/typescript/components/DrawCore/DrawProvider.d.ts.map +1 -1
  74. package/lib/typescript/components/DrawCore/Item.d.ts +27 -1
  75. package/lib/typescript/components/DrawCore/Item.d.ts.map +1 -1
  76. package/lib/typescript/components/DrawCore/index.d.ts +0 -1
  77. package/lib/typescript/components/DrawCore/index.d.ts.map +1 -1
  78. package/lib/typescript/components/DrawCore/useDrawHook.d.ts +1 -0
  79. package/lib/typescript/components/DrawCore/useDrawHook.d.ts.map +1 -1
  80. package/lib/typescript/components/DrawWithOptions/ArrowSvg.d.ts +0 -1
  81. package/lib/typescript/components/DrawWithOptions/ArrowSvg.d.ts.map +1 -1
  82. package/lib/typescript/components/DrawWithOptions/CancelSvg.d.ts +0 -1
  83. package/lib/typescript/components/DrawWithOptions/CancelSvg.d.ts.map +1 -1
  84. package/lib/typescript/components/DrawWithOptions/CircleSvg.d.ts +0 -1
  85. package/lib/typescript/components/DrawWithOptions/CircleSvg.d.ts.map +1 -1
  86. package/lib/typescript/components/DrawWithOptions/CloseSvg.d.ts +0 -1
  87. package/lib/typescript/components/DrawWithOptions/CloseSvg.d.ts.map +1 -1
  88. package/lib/typescript/components/DrawWithOptions/DoubleHeadSvg.d.ts +0 -1
  89. package/lib/typescript/components/DrawWithOptions/DoubleHeadSvg.d.ts.map +1 -1
  90. package/lib/typescript/components/DrawWithOptions/PenSvg.d.ts +0 -1
  91. package/lib/typescript/components/DrawWithOptions/PenSvg.d.ts.map +1 -1
  92. package/lib/typescript/components/DrawWithOptions/SendSvg.d.ts +0 -1
  93. package/lib/typescript/components/DrawWithOptions/SendSvg.d.ts.map +1 -1
  94. package/lib/typescript/components/DrawWithOptions/SliderSvg.d.ts +0 -1
  95. package/lib/typescript/components/DrawWithOptions/SliderSvg.d.ts.map +1 -1
  96. package/lib/typescript/components/DrawWithOptions/SquareSvg.d.ts +0 -1
  97. package/lib/typescript/components/DrawWithOptions/SquareSvg.d.ts.map +1 -1
  98. package/lib/typescript/components/DrawWithOptions/TextSvg.d.ts +0 -1
  99. package/lib/typescript/components/DrawWithOptions/TextSvg.d.ts.map +1 -1
  100. package/lib/typescript/components/DrawWithOptions/ThrashSvg.d.ts +0 -1
  101. package/lib/typescript/components/DrawWithOptions/ThrashSvg.d.ts.map +1 -1
  102. package/lib/typescript/components/DrawWithOptions/index.d.ts.map +1 -1
  103. package/lib/typescript/components/Slider/StrokeSlider.d.ts +0 -1
  104. package/lib/typescript/components/Slider/StrokeSlider.d.ts.map +1 -1
  105. package/package.json +1 -1
  106. package/src/components/DrawCore/CurrentAnimatedItem.tsx +307 -7
  107. package/src/components/DrawCore/CurrentAnimatedText.tsx +5 -2
  108. package/src/components/DrawCore/DrawContext.tsx +2 -0
  109. package/src/components/DrawCore/DrawPad.tsx +17 -3
  110. package/src/components/DrawCore/DrawProvider.tsx +6 -0
  111. package/src/components/DrawCore/Item.tsx +188 -7
  112. package/src/components/DrawCore/index.tsx +219 -100
  113. package/src/components/DrawCore/useDrawHook.tsx +2 -0
  114. package/src/components/DrawWithOptions/index.tsx +18 -0
  115. package/src/types.d.ts +7 -0
@@ -27,11 +27,11 @@ const DrawPad = ({
27
27
  <Circle
28
28
  id="selectionIndicator"
29
29
  fill="#3a6cff"
30
- r={5}
30
+ r={10}
31
31
  cx={0}
32
32
  cy={0}
33
33
  strokeWidth={1}
34
- stroke="white"
34
+ stroke="black"
35
35
  />
36
36
  <Marker
37
37
  id="arrowhead"
@@ -47,6 +47,20 @@ const DrawPad = ({
47
47
  strokeLinejoin="round"
48
48
  />
49
49
  </Marker>
50
+ <Marker
51
+ id="arrowheadStart"
52
+ markerUnits={'strokeWidth' as MarkerUnits}
53
+ refX="0"
54
+ refY="0"
55
+ orient="auto"
56
+ >
57
+ <Polyline
58
+ points="2,-2 0,0 2,2 0,0"
59
+ stroke="context-stroke"
60
+ strokeLinecap="round"
61
+ strokeLinejoin="round"
62
+ />
63
+ </Marker>
50
64
 
51
65
  <Marker
52
66
  id="side"
@@ -78,7 +92,7 @@ const DrawPad = ({
78
92
  <Item key={index} item={item} onPress={onPressItem(item, index)} />
79
93
  ))}
80
94
 
81
- <CurrentAnimatedItem currentItem={currentItem} />
95
+ <CurrentAnimatedItem />
82
96
  </Svg>
83
97
  <CurrentAnimatedText
84
98
  currentItem={currentItem}
@@ -3,6 +3,8 @@ import React, { ReactElement, useMemo, useReducer, useRef } from 'react';
3
3
  import type { Action, DrawItem, DrawState, hslColor } from '../../types';
4
4
  import { useSharedValue } from 'react-native-reanimated';
5
5
  import type ViewShot from 'react-native-view-shot';
6
+ import { Keyboard } from 'react-native';
7
+ import { TextInput } from 'react-native-gesture-handler';
6
8
 
7
9
  const initialState: DrawState = {
8
10
  doneItems: [],
@@ -20,6 +22,7 @@ const reducerDrawStates = (drawState: DrawState, action: Action): DrawState => {
20
22
  cancelEnabled: action.cancelEnabled,
21
23
  };
22
24
  case 'SET_DRAWING_MODE':
25
+ Keyboard.dismiss();
23
26
  return {
24
27
  ...drawState,
25
28
  drawingMode: action.drawingMode,
@@ -87,6 +90,7 @@ const DrawProvider = ({ children }: { children: ReactElement }) => {
87
90
  const color = useSharedValue<hslColor>('hsl(0, 100%, 0%)');
88
91
  const currentItem = useSharedValue<DrawItem | null>(null);
89
92
  const viewShot = useRef<ViewShot>(null);
93
+ const doubleArrowTextInput = useRef<TextInput>(null);
90
94
 
91
95
  const [drawState, dispatchDrawStates] = useReducer(
92
96
  reducerDrawStates,
@@ -102,6 +106,7 @@ const DrawProvider = ({ children }: { children: ReactElement }) => {
102
106
  currentItem,
103
107
  itemIsSelected,
104
108
  viewShot,
109
+ doubleArrowTextInput,
105
110
  }),
106
111
  [
107
112
  drawState,
@@ -111,6 +116,7 @@ const DrawProvider = ({ children }: { children: ReactElement }) => {
111
116
  currentItem,
112
117
  itemIsSelected,
113
118
  viewShot,
119
+ doubleArrowTextInput,
114
120
  ]
115
121
  );
116
122
 
@@ -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
  >