@archireport/react-native-svg-draw 2.2.1 → 2.3.1
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/lib/commonjs/components/DrawCore/CurrentAnimatedItem.js +293 -31
- package/lib/commonjs/components/DrawCore/CurrentAnimatedItem.js.map +1 -1
- package/lib/commonjs/components/DrawCore/CurrentAnimatedText.js +12 -11
- package/lib/commonjs/components/DrawCore/CurrentAnimatedText.js.map +1 -1
- package/lib/commonjs/components/DrawCore/DrawContext.js.map +1 -1
- package/lib/commonjs/components/DrawCore/DrawPad.js +14 -5
- package/lib/commonjs/components/DrawCore/DrawPad.js.map +1 -1
- package/lib/commonjs/components/DrawCore/DrawProvider.js +6 -2
- package/lib/commonjs/components/DrawCore/DrawProvider.js.map +1 -1
- package/lib/commonjs/components/DrawCore/Item.js +156 -8
- package/lib/commonjs/components/DrawCore/Item.js.map +1 -1
- package/lib/commonjs/components/DrawCore/index.js +163 -76
- package/lib/commonjs/components/DrawCore/index.js.map +1 -1
- package/lib/commonjs/components/DrawCore/useDrawHook.js +4 -2
- package/lib/commonjs/components/DrawCore/useDrawHook.js.map +1 -1
- package/lib/commonjs/components/DrawWithOptions/ArrowSvg.js.map +1 -1
- package/lib/commonjs/components/DrawWithOptions/CancelSvg.js.map +1 -1
- package/lib/commonjs/components/DrawWithOptions/CircleSvg.js.map +1 -1
- package/lib/commonjs/components/DrawWithOptions/CloseSvg.js.map +1 -1
- package/lib/commonjs/components/DrawWithOptions/DoubleHeadSvg.js.map +1 -1
- package/lib/commonjs/components/DrawWithOptions/PenSvg.js.map +1 -1
- package/lib/commonjs/components/DrawWithOptions/SendSvg.js.map +1 -1
- package/lib/commonjs/components/DrawWithOptions/SliderSvg.js.map +1 -1
- package/lib/commonjs/components/DrawWithOptions/SquareSvg.js.map +1 -1
- package/lib/commonjs/components/DrawWithOptions/TextSvg.js.map +1 -1
- package/lib/commonjs/components/DrawWithOptions/ThrashSvg.js.map +1 -1
- package/lib/commonjs/components/DrawWithOptions/index.js +14 -0
- package/lib/commonjs/components/DrawWithOptions/index.js.map +1 -1
- package/lib/commonjs/components/Slider/ColorSlider.js.map +1 -1
- package/lib/commonjs/components/Slider/Sliders.js.map +1 -1
- package/lib/commonjs/components/Slider/StrokeSlider.js.map +1 -1
- package/lib/commonjs/components/Slider/sliderStyle.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/components/DrawCore/CurrentAnimatedItem.js +295 -33
- package/lib/module/components/DrawCore/CurrentAnimatedItem.js.map +1 -1
- package/lib/module/components/DrawCore/CurrentAnimatedText.js +12 -11
- package/lib/module/components/DrawCore/CurrentAnimatedText.js.map +1 -1
- package/lib/module/components/DrawCore/DrawContext.js.map +1 -1
- package/lib/module/components/DrawCore/DrawPad.js +14 -5
- package/lib/module/components/DrawCore/DrawPad.js.map +1 -1
- package/lib/module/components/DrawCore/DrawProvider.js +6 -2
- package/lib/module/components/DrawCore/DrawProvider.js.map +1 -1
- package/lib/module/components/DrawCore/Item.js +152 -10
- package/lib/module/components/DrawCore/Item.js.map +1 -1
- package/lib/module/components/DrawCore/index.js +164 -77
- package/lib/module/components/DrawCore/index.js.map +1 -1
- package/lib/module/components/DrawCore/useDrawHook.js +4 -2
- package/lib/module/components/DrawCore/useDrawHook.js.map +1 -1
- package/lib/module/components/DrawWithOptions/ArrowSvg.js.map +1 -1
- package/lib/module/components/DrawWithOptions/CancelSvg.js.map +1 -1
- package/lib/module/components/DrawWithOptions/CircleSvg.js.map +1 -1
- package/lib/module/components/DrawWithOptions/CloseSvg.js.map +1 -1
- package/lib/module/components/DrawWithOptions/DoubleHeadSvg.js.map +1 -1
- package/lib/module/components/DrawWithOptions/PenSvg.js.map +1 -1
- package/lib/module/components/DrawWithOptions/SendSvg.js.map +1 -1
- package/lib/module/components/DrawWithOptions/SliderSvg.js.map +1 -1
- package/lib/module/components/DrawWithOptions/SquareSvg.js.map +1 -1
- package/lib/module/components/DrawWithOptions/TextSvg.js.map +1 -1
- package/lib/module/components/DrawWithOptions/ThrashSvg.js.map +1 -1
- package/lib/module/components/DrawWithOptions/index.js +14 -0
- package/lib/module/components/DrawWithOptions/index.js.map +1 -1
- package/lib/module/components/Slider/ColorSlider.js.map +1 -1
- package/lib/module/components/Slider/Sliders.js.map +1 -1
- package/lib/module/components/Slider/StrokeSlider.js.map +1 -1
- package/lib/typescript/components/DrawCore/CurrentAnimatedItem.d.ts +3 -6
- package/lib/typescript/components/DrawCore/CurrentAnimatedItem.d.ts.map +1 -1
- package/lib/typescript/components/DrawCore/CurrentAnimatedText.d.ts +0 -1
- package/lib/typescript/components/DrawCore/CurrentAnimatedText.d.ts.map +1 -1
- package/lib/typescript/components/DrawCore/DrawContext.d.ts +2 -0
- package/lib/typescript/components/DrawCore/DrawContext.d.ts.map +1 -1
- package/lib/typescript/components/DrawCore/DrawPad.d.ts +0 -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 +27 -1
- package/lib/typescript/components/DrawCore/Item.d.ts.map +1 -1
- package/lib/typescript/components/DrawCore/index.d.ts +0 -1
- package/lib/typescript/components/DrawCore/index.d.ts.map +1 -1
- package/lib/typescript/components/DrawCore/useDrawHook.d.ts +1 -1
- package/lib/typescript/components/DrawCore/useDrawHook.d.ts.map +1 -1
- package/lib/typescript/components/DrawWithOptions/ArrowSvg.d.ts +0 -1
- package/lib/typescript/components/DrawWithOptions/ArrowSvg.d.ts.map +1 -1
- package/lib/typescript/components/DrawWithOptions/CancelSvg.d.ts +0 -1
- package/lib/typescript/components/DrawWithOptions/CancelSvg.d.ts.map +1 -1
- package/lib/typescript/components/DrawWithOptions/CircleSvg.d.ts +0 -1
- package/lib/typescript/components/DrawWithOptions/CircleSvg.d.ts.map +1 -1
- package/lib/typescript/components/DrawWithOptions/CloseSvg.d.ts +0 -1
- package/lib/typescript/components/DrawWithOptions/CloseSvg.d.ts.map +1 -1
- package/lib/typescript/components/DrawWithOptions/DoubleHeadSvg.d.ts +0 -1
- package/lib/typescript/components/DrawWithOptions/DoubleHeadSvg.d.ts.map +1 -1
- package/lib/typescript/components/DrawWithOptions/PenSvg.d.ts +0 -1
- package/lib/typescript/components/DrawWithOptions/PenSvg.d.ts.map +1 -1
- package/lib/typescript/components/DrawWithOptions/SendSvg.d.ts +0 -1
- package/lib/typescript/components/DrawWithOptions/SendSvg.d.ts.map +1 -1
- package/lib/typescript/components/DrawWithOptions/SliderSvg.d.ts +0 -1
- package/lib/typescript/components/DrawWithOptions/SliderSvg.d.ts.map +1 -1
- package/lib/typescript/components/DrawWithOptions/SquareSvg.d.ts +0 -1
- package/lib/typescript/components/DrawWithOptions/SquareSvg.d.ts.map +1 -1
- package/lib/typescript/components/DrawWithOptions/TextSvg.d.ts +0 -1
- package/lib/typescript/components/DrawWithOptions/TextSvg.d.ts.map +1 -1
- package/lib/typescript/components/DrawWithOptions/ThrashSvg.d.ts +0 -1
- package/lib/typescript/components/DrawWithOptions/ThrashSvg.d.ts.map +1 -1
- package/lib/typescript/components/DrawWithOptions/index.d.ts.map +1 -1
- package/lib/typescript/components/Slider/StrokeSlider.d.ts +0 -1
- package/lib/typescript/components/Slider/StrokeSlider.d.ts.map +1 -1
- package/lib/typescript/components/Slider/sliderStyle.d.ts +2 -2
- package/package.json +5 -5
- package/src/components/DrawCore/CurrentAnimatedItem.tsx +340 -20
- package/src/components/DrawCore/CurrentAnimatedText.tsx +13 -6
- package/src/components/DrawCore/DrawContext.tsx +2 -0
- package/src/components/DrawCore/DrawPad.tsx +17 -3
- package/src/components/DrawCore/DrawProvider.tsx +6 -0
- package/src/components/DrawCore/Item.tsx +190 -9
- package/src/components/DrawCore/index.tsx +219 -100
- package/src/components/DrawCore/useDrawHook.tsx +2 -0
- package/src/components/DrawWithOptions/index.tsx +18 -0
- package/src/types.d.ts +7 -0
|
@@ -2,10 +2,16 @@ import React from 'react';
|
|
|
2
2
|
import Animated, {
|
|
3
3
|
createAnimatedPropAdapter,
|
|
4
4
|
processColor,
|
|
5
|
+
runOnJS,
|
|
5
6
|
useAnimatedProps,
|
|
7
|
+
useAnimatedReaction,
|
|
6
8
|
} from 'react-native-reanimated';
|
|
7
9
|
import { Path, Ellipse, Rect, Line, G } from 'react-native-svg';
|
|
8
|
-
import type {
|
|
10
|
+
import type { hslColor, Point } from '../../types';
|
|
11
|
+
import { TextInput } from 'react-native';
|
|
12
|
+
import useDrawHook from './useDrawHook';
|
|
13
|
+
|
|
14
|
+
//import { TextInput } from 'react-native-gesture-handler';
|
|
9
15
|
|
|
10
16
|
const AnimatedPath = Animated.createAnimatedComponent(Path);
|
|
11
17
|
|
|
@@ -15,6 +21,10 @@ const AnimatedRectangle = Animated.createAnimatedComponent(Rect);
|
|
|
15
21
|
|
|
16
22
|
const AnimatedLine = Animated.createAnimatedComponent(Line);
|
|
17
23
|
|
|
24
|
+
//const AnimatedText = Animated.createAnimatedComponent(Text);
|
|
25
|
+
|
|
26
|
+
const AnimatedTextInput = Animated.createAnimatedComponent(TextInput);
|
|
27
|
+
|
|
18
28
|
// properties of a line
|
|
19
29
|
const line = (pointA: Point, pointB: Point) => {
|
|
20
30
|
'worklet';
|
|
@@ -109,7 +119,7 @@ function hue2rgb(p: number, q: number, t: number) {
|
|
|
109
119
|
}
|
|
110
120
|
|
|
111
121
|
// see https://github.com/software-mansion/react-native-reanimated/issues/1909
|
|
112
|
-
function hslToRgb(col: hslColor) {
|
|
122
|
+
export function hslToRgb(col: hslColor) {
|
|
113
123
|
'worklet';
|
|
114
124
|
const hslRegExp = new RegExp(/hsl\(([\d.]+),\s*(\d+)%,\s*([\d.]+)%\)/);
|
|
115
125
|
const res = hslRegExp.exec(col);
|
|
@@ -141,23 +151,30 @@ const propAdapter = createAnimatedPropAdapter(
|
|
|
141
151
|
Object.keys(props).includes('fill') &&
|
|
142
152
|
(typeof props.fill === 'string' || typeof props.fill === 'number')
|
|
143
153
|
) {
|
|
144
|
-
props.fill = { type: 0, payload: processColor(props.fill) };
|
|
154
|
+
props.fill = { type: 0, payload: processColor(props.fill as string) };
|
|
145
155
|
}
|
|
146
156
|
if (
|
|
147
157
|
Object.keys(props).includes('stroke') &&
|
|
148
158
|
(typeof props.stroke === 'string' || typeof props.stroke === 'number')
|
|
149
159
|
) {
|
|
150
|
-
props.stroke = { type: 0, payload: processColor(props.stroke) };
|
|
160
|
+
props.stroke = { type: 0, payload: processColor(props.stroke as string) };
|
|
151
161
|
}
|
|
152
162
|
},
|
|
153
163
|
['fill', 'stroke']
|
|
154
164
|
);
|
|
155
165
|
|
|
156
|
-
export default function CurrentAnimatedItem({
|
|
157
|
-
currentItem,
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
166
|
+
export default function CurrentAnimatedItem() {
|
|
167
|
+
const { currentItem, doubleArrowTextInput } = useDrawHook();
|
|
168
|
+
|
|
169
|
+
const getTextLength = () => {
|
|
170
|
+
'worklet';
|
|
171
|
+
const text =
|
|
172
|
+
currentItem.value?.type === 'doubleArrows' ? currentItem.value?.text : '';
|
|
173
|
+
|
|
174
|
+
const textLength = text && text.length > 5 ? text.length * 10 : 50;
|
|
175
|
+
return textLength;
|
|
176
|
+
};
|
|
177
|
+
|
|
161
178
|
const ellipseAnimatedProps = useAnimatedProps(
|
|
162
179
|
() => {
|
|
163
180
|
const coordinates =
|
|
@@ -171,7 +188,7 @@ export default function CurrentAnimatedItem({
|
|
|
171
188
|
rx: coordinates.rx,
|
|
172
189
|
ry: coordinates.ry,
|
|
173
190
|
fill: 'transparent',
|
|
174
|
-
stroke: hslToRgb(currentItem.value?.color || 'hsl(0, 0%, 0%)'),
|
|
191
|
+
//stroke: hslToRgb(currentItem.value?.color || 'hsl(0, 0%, 0%)'),
|
|
175
192
|
opacity: currentItem.value?.type === 'ellipse' ? 1 : 0,
|
|
176
193
|
strokeWidth:
|
|
177
194
|
currentItem.value?.type === 'ellipse'
|
|
@@ -196,7 +213,7 @@ export default function CurrentAnimatedItem({
|
|
|
196
213
|
x2: coordinates.x2,
|
|
197
214
|
y2: coordinates.y2,
|
|
198
215
|
fill: 'transparent',
|
|
199
|
-
stroke: hslToRgb(currentItem.value?.color || 'hsl(0, 0%, 0%)'),
|
|
216
|
+
//stroke: hslToRgb(currentItem.value?.color || 'hsl(0, 0%, 0%)'),
|
|
200
217
|
opacity: currentItem.value?.type === 'singleHead' ? 1 : 0,
|
|
201
218
|
strokeWidth:
|
|
202
219
|
currentItem.value?.type === 'singleHead'
|
|
@@ -222,7 +239,7 @@ export default function CurrentAnimatedItem({
|
|
|
222
239
|
x2: coordinates.x2,
|
|
223
240
|
y2: coordinates.y2,
|
|
224
241
|
fill: 'transparent',
|
|
225
|
-
stroke: hslToRgb(currentItem.value?.color || 'hsl(0, 0%, 0%)'),
|
|
242
|
+
//stroke: hslToRgb(currentItem.value?.color || 'hsl(0, 0%, 0%)'),
|
|
226
243
|
opacity: currentItem.value?.type === 'doubleHead' ? 1 : 0,
|
|
227
244
|
strokeWidth:
|
|
228
245
|
currentItem.value?.type === 'doubleHead'
|
|
@@ -235,6 +252,237 @@ export default function CurrentAnimatedItem({
|
|
|
235
252
|
null,
|
|
236
253
|
propAdapter
|
|
237
254
|
);
|
|
255
|
+
const distance = (x1: number, y1: number, x2: number, y2: number) => {
|
|
256
|
+
'worklet';
|
|
257
|
+
return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
const getCoordinatesWithRatio = ({
|
|
261
|
+
c1,
|
|
262
|
+
c2,
|
|
263
|
+
ratio,
|
|
264
|
+
first = true,
|
|
265
|
+
}: {
|
|
266
|
+
c1: number;
|
|
267
|
+
c2: number;
|
|
268
|
+
ratio: number;
|
|
269
|
+
first?: boolean;
|
|
270
|
+
}): [number, number] => {
|
|
271
|
+
'worklet';
|
|
272
|
+
let newC1 = c1;
|
|
273
|
+
let newC2 = c2;
|
|
274
|
+
|
|
275
|
+
if (c1 > c2) {
|
|
276
|
+
if (first) {
|
|
277
|
+
newC1 = c1;
|
|
278
|
+
newC2 = c1 - (c1 - c2) * ratio;
|
|
279
|
+
} else {
|
|
280
|
+
newC1 = c2 + (c1 - c2) * ratio;
|
|
281
|
+
newC2 = c2;
|
|
282
|
+
}
|
|
283
|
+
} else {
|
|
284
|
+
if (first) {
|
|
285
|
+
newC1 = c1;
|
|
286
|
+
newC2 = c1 + (c2 - c1) * ratio;
|
|
287
|
+
} else {
|
|
288
|
+
newC1 = c2 - (c2 - c1) * ratio;
|
|
289
|
+
newC2 = c2;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return [newC1 as number, newC2 as number];
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
const getGetcoordinateValue = ({
|
|
297
|
+
x1,
|
|
298
|
+
y1,
|
|
299
|
+
x2,
|
|
300
|
+
y2,
|
|
301
|
+
first = true,
|
|
302
|
+
}: {
|
|
303
|
+
x1: number;
|
|
304
|
+
y1: number;
|
|
305
|
+
x2: number;
|
|
306
|
+
y2: number;
|
|
307
|
+
first: boolean;
|
|
308
|
+
}) => {
|
|
309
|
+
'worklet';
|
|
310
|
+
const dist = distance(x1, y1, x2, y2);
|
|
311
|
+
const textLength = getTextLength();
|
|
312
|
+
const newDist = (!textLength ? dist : dist - textLength) / 2;
|
|
313
|
+
|
|
314
|
+
let newX1 = x1;
|
|
315
|
+
let newY1 = y1;
|
|
316
|
+
let newX2 = x2;
|
|
317
|
+
let newY2 = y2;
|
|
318
|
+
|
|
319
|
+
//if (newDist > textLength / 2 && !isShortArrow) {
|
|
320
|
+
const ratio = newDist / dist;
|
|
321
|
+
[newX1, newX2] = getCoordinatesWithRatio({
|
|
322
|
+
c1: x1,
|
|
323
|
+
c2: x2,
|
|
324
|
+
ratio,
|
|
325
|
+
first,
|
|
326
|
+
});
|
|
327
|
+
[newY1, newY2] = getCoordinatesWithRatio({
|
|
328
|
+
c1: y1,
|
|
329
|
+
c2: y2,
|
|
330
|
+
ratio,
|
|
331
|
+
first,
|
|
332
|
+
});
|
|
333
|
+
//}
|
|
334
|
+
return [newX1, newY1, newX2, newY2];
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
const doubleArrowsAnimatedPropsFirst = useAnimatedProps(
|
|
338
|
+
() => {
|
|
339
|
+
let x1, y1, x2, y2;
|
|
340
|
+
|
|
341
|
+
if (currentItem.value?.type !== 'doubleArrows') {
|
|
342
|
+
x1 = -10;
|
|
343
|
+
y1 = -10;
|
|
344
|
+
x2 = -10;
|
|
345
|
+
y2 = -10;
|
|
346
|
+
} else {
|
|
347
|
+
const coordinates = currentItem.value.data;
|
|
348
|
+
[x1, y1, x2, y2] = getGetcoordinateValue({
|
|
349
|
+
x1: Number(coordinates.x1),
|
|
350
|
+
y1: Number(coordinates.y1),
|
|
351
|
+
x2: Number(coordinates.x2),
|
|
352
|
+
y2: Number(coordinates.y2),
|
|
353
|
+
first: true,
|
|
354
|
+
//text: currentItem.value?.text,
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
return {
|
|
359
|
+
x1,
|
|
360
|
+
y1,
|
|
361
|
+
x2,
|
|
362
|
+
y2,
|
|
363
|
+
fill: 'transparent',
|
|
364
|
+
//stroke: hslToRgb(currentItem.value?.color || 'hsl(0, 0%, 0%)'),
|
|
365
|
+
opacity: currentItem.value?.type === 'doubleArrows' ? 1 : 0,
|
|
366
|
+
strokeWidth:
|
|
367
|
+
currentItem.value?.type === 'doubleArrows'
|
|
368
|
+
? currentItem.value.strokeWidth
|
|
369
|
+
: 0,
|
|
370
|
+
markerStart: 'arrowheadStart',
|
|
371
|
+
};
|
|
372
|
+
},
|
|
373
|
+
null,
|
|
374
|
+
propAdapter
|
|
375
|
+
);
|
|
376
|
+
|
|
377
|
+
const doubleArrowsAnimatedPropsLast = useAnimatedProps(
|
|
378
|
+
() => {
|
|
379
|
+
let x1, y1, x2, y2;
|
|
380
|
+
|
|
381
|
+
if (currentItem.value?.type !== 'doubleArrows') {
|
|
382
|
+
x1 = -10;
|
|
383
|
+
y1 = -10;
|
|
384
|
+
x2 = -10;
|
|
385
|
+
y2 = -10;
|
|
386
|
+
} else {
|
|
387
|
+
const coordinates = currentItem.value.data;
|
|
388
|
+
[x1, y1, x2, y2] = getGetcoordinateValue({
|
|
389
|
+
x1: Number(coordinates.x1),
|
|
390
|
+
y1: Number(coordinates.y1),
|
|
391
|
+
x2: Number(coordinates.x2),
|
|
392
|
+
y2: Number(coordinates.y2),
|
|
393
|
+
first: false,
|
|
394
|
+
//text: currentItem.value?.text,
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
return {
|
|
399
|
+
x1,
|
|
400
|
+
y1,
|
|
401
|
+
x2,
|
|
402
|
+
y2,
|
|
403
|
+
fill: 'transparent',
|
|
404
|
+
//stroke: hslToRgb(currentItem.value?.color || 'hsl(0, 0%, 0%)'),
|
|
405
|
+
opacity: currentItem.value?.type === 'doubleArrows' ? 1 : 0,
|
|
406
|
+
strokeWidth:
|
|
407
|
+
currentItem.value?.type === 'doubleArrows'
|
|
408
|
+
? currentItem.value.strokeWidth
|
|
409
|
+
: 0,
|
|
410
|
+
markerEnd: 'arrowhead',
|
|
411
|
+
};
|
|
412
|
+
},
|
|
413
|
+
null,
|
|
414
|
+
propAdapter
|
|
415
|
+
);
|
|
416
|
+
|
|
417
|
+
const getTextValues = ({
|
|
418
|
+
x1,
|
|
419
|
+
y1,
|
|
420
|
+
x2,
|
|
421
|
+
y2,
|
|
422
|
+
}: {
|
|
423
|
+
x1: number;
|
|
424
|
+
y1: number;
|
|
425
|
+
x2: number;
|
|
426
|
+
y2: number;
|
|
427
|
+
}): [number, number, number] => {
|
|
428
|
+
'worklet';
|
|
429
|
+
const dist = distance(x1, y1, x2, y2);
|
|
430
|
+
const ratio = 0.5;
|
|
431
|
+
const newX = (x1 + x2) * ratio;
|
|
432
|
+
const newY = (y1 + y2) * ratio;
|
|
433
|
+
|
|
434
|
+
let angle = 0;
|
|
435
|
+
if (x1 > x2) {
|
|
436
|
+
if (y1 > y2) {
|
|
437
|
+
angle = Math.acos((x1 - x2) / dist) * (180 / Math.PI);
|
|
438
|
+
} else {
|
|
439
|
+
angle = 180 - Math.acos((x1 - x2) / dist) * (180 / Math.PI) + 180;
|
|
440
|
+
}
|
|
441
|
+
} else {
|
|
442
|
+
if (y1 > y2) {
|
|
443
|
+
angle = 180 - Math.acos((x2 - x1) / dist) * (180 / Math.PI) + 180;
|
|
444
|
+
} else {
|
|
445
|
+
angle = Math.acos((x2 - x1) / dist) * (180 / Math.PI);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
return [newX, newY, angle];
|
|
450
|
+
};
|
|
451
|
+
const doubleArrowsAnimatedPropsText = useAnimatedProps(
|
|
452
|
+
() => {
|
|
453
|
+
let x = 0,
|
|
454
|
+
y = 0,
|
|
455
|
+
angle = 0;
|
|
456
|
+
|
|
457
|
+
if (currentItem.value?.type !== 'doubleArrows') {
|
|
458
|
+
x = -50;
|
|
459
|
+
y = -50;
|
|
460
|
+
angle = 0;
|
|
461
|
+
} else {
|
|
462
|
+
const coordinates = currentItem.value.data;
|
|
463
|
+
[x, y, angle] = getTextValues({
|
|
464
|
+
x1: Number(coordinates.x1),
|
|
465
|
+
y1: Number(coordinates.y1),
|
|
466
|
+
x2: Number(coordinates.x2),
|
|
467
|
+
y2: Number(coordinates.y2),
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
return {
|
|
472
|
+
top: y - 25,
|
|
473
|
+
left: x - getTextLength() / 2,
|
|
474
|
+
fontSize: 10 + (currentItem.value?.strokeWidth ?? 0) * 2,
|
|
475
|
+
color: currentItem.value?.color
|
|
476
|
+
? hslToRgb(currentItem.value?.color)
|
|
477
|
+
: 'white',
|
|
478
|
+
transform: [{ rotateZ: `${angle}deg` }],
|
|
479
|
+
//backgroundColor: 'red',
|
|
480
|
+
width: getTextLength(),
|
|
481
|
+
};
|
|
482
|
+
},
|
|
483
|
+
null,
|
|
484
|
+
propAdapter
|
|
485
|
+
);
|
|
238
486
|
|
|
239
487
|
const rectangleAnimatedProps = useAnimatedProps(
|
|
240
488
|
() => {
|
|
@@ -248,7 +496,7 @@ export default function CurrentAnimatedItem({
|
|
|
248
496
|
width: coordinates.width,
|
|
249
497
|
height: coordinates.height,
|
|
250
498
|
fill: 'transparent',
|
|
251
|
-
stroke: hslToRgb(currentItem.value?.color || 'hsl(0, 0%, 0%)'),
|
|
499
|
+
//stroke: hslToRgb(currentItem.value?.color || 'hsl(0, 0%, 0%)'),
|
|
252
500
|
opacity: currentItem.value?.type === 'rectangle' ? 1 : 0,
|
|
253
501
|
strokeWidth:
|
|
254
502
|
currentItem.value?.type === 'rectangle'
|
|
@@ -271,10 +519,11 @@ export default function CurrentAnimatedItem({
|
|
|
271
519
|
);
|
|
272
520
|
return {
|
|
273
521
|
d: d,
|
|
522
|
+
//opacity: 1,
|
|
523
|
+
opacity: currentItem.value?.type === 'pen' ? 1 : 0,
|
|
524
|
+
//stroke: currentItem.value?.color || "black",
|
|
274
525
|
strokeWidth:
|
|
275
526
|
currentItem.value?.type === 'pen' ? currentItem.value.strokeWidth : 0,
|
|
276
|
-
stroke: hslToRgb(currentItem.value?.color || 'hsl(0, 0%, 0%)'),
|
|
277
|
-
opacity: currentItem.value?.type === 'pen' ? 1 : 0,
|
|
278
527
|
fill: 'transparent',
|
|
279
528
|
markerStart: 'selection',
|
|
280
529
|
markerEnd: 'selection',
|
|
@@ -284,17 +533,88 @@ export default function CurrentAnimatedItem({
|
|
|
284
533
|
propAdapter
|
|
285
534
|
);
|
|
286
535
|
|
|
536
|
+
const updateText = (value: string) => {
|
|
537
|
+
if (!doubleArrowTextInput?.current) return;
|
|
538
|
+
doubleArrowTextInput.current.setNativeProps({
|
|
539
|
+
text: value,
|
|
540
|
+
});
|
|
541
|
+
};
|
|
542
|
+
useAnimatedReaction(
|
|
543
|
+
() => {
|
|
544
|
+
return currentItem.value?.type === 'doubleArrows'
|
|
545
|
+
? currentItem.value?.text || ''
|
|
546
|
+
: '';
|
|
547
|
+
},
|
|
548
|
+
(value) => {
|
|
549
|
+
if (updateText) runOnJS(updateText)(value);
|
|
550
|
+
},
|
|
551
|
+
[updateText, doubleArrowTextInput]
|
|
552
|
+
);
|
|
553
|
+
|
|
287
554
|
return (
|
|
288
555
|
<>
|
|
289
|
-
<AnimatedEllipse
|
|
556
|
+
<AnimatedEllipse
|
|
557
|
+
animatedProps={ellipseAnimatedProps}
|
|
558
|
+
stroke={currentItem.value?.color || 'black'}
|
|
559
|
+
/>
|
|
560
|
+
<G markerStart="url(#selection)" markerEnd="url(#selection)">
|
|
561
|
+
<AnimatedLine
|
|
562
|
+
animatedProps={singleHeadAnimatedProps}
|
|
563
|
+
stroke={currentItem.value?.color || 'black'}
|
|
564
|
+
/>
|
|
565
|
+
</G>
|
|
290
566
|
<G markerStart="url(#selection)" markerEnd="url(#selection)">
|
|
291
|
-
<AnimatedLine
|
|
567
|
+
<AnimatedLine
|
|
568
|
+
animatedProps={doubleHeadAnimatedProps}
|
|
569
|
+
stroke={currentItem.value?.color || 'black'}
|
|
570
|
+
/>
|
|
292
571
|
</G>
|
|
293
572
|
<G markerStart="url(#selection)" markerEnd="url(#selection)">
|
|
294
|
-
<AnimatedLine
|
|
573
|
+
<AnimatedLine
|
|
574
|
+
animatedProps={doubleArrowsAnimatedPropsFirst}
|
|
575
|
+
stroke={currentItem.value?.color || 'black'}
|
|
576
|
+
/>
|
|
577
|
+
|
|
578
|
+
<AnimatedTextInput
|
|
579
|
+
animatedProps={{
|
|
580
|
+
...(doubleArrowsAnimatedPropsText as any), // Type cast to bypass the type error
|
|
581
|
+
// Ensure other relevant props if needed
|
|
582
|
+
}}
|
|
583
|
+
value={
|
|
584
|
+
currentItem.value?.type === 'doubleArrows'
|
|
585
|
+
? currentItem.value.text
|
|
586
|
+
: ''
|
|
587
|
+
}
|
|
588
|
+
ref={doubleArrowTextInput}
|
|
589
|
+
underlineColorAndroid={'transparent'}
|
|
590
|
+
onChangeText={(text) => {
|
|
591
|
+
if (currentItem.value?.type === 'doubleArrows') {
|
|
592
|
+
currentItem.value = {
|
|
593
|
+
...currentItem.value,
|
|
594
|
+
text,
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
}}
|
|
598
|
+
style={{
|
|
599
|
+
color: 'black',
|
|
600
|
+
fontSize: 24,
|
|
601
|
+
position: 'absolute',
|
|
602
|
+
}}
|
|
603
|
+
/>
|
|
604
|
+
|
|
605
|
+
<AnimatedLine
|
|
606
|
+
animatedProps={doubleArrowsAnimatedPropsLast}
|
|
607
|
+
stroke={currentItem.value?.color || 'black'}
|
|
608
|
+
/>
|
|
295
609
|
</G>
|
|
296
|
-
<AnimatedRectangle
|
|
297
|
-
|
|
610
|
+
<AnimatedRectangle
|
|
611
|
+
animatedProps={rectangleAnimatedProps}
|
|
612
|
+
stroke={currentItem.value?.color || 'black'}
|
|
613
|
+
/>
|
|
614
|
+
<AnimatedPath
|
|
615
|
+
animatedProps={penAnimatedProps}
|
|
616
|
+
stroke={currentItem.value?.color || 'black'}
|
|
617
|
+
/>
|
|
298
618
|
</>
|
|
299
619
|
);
|
|
300
620
|
}
|
|
@@ -6,6 +6,7 @@ import Animated, {
|
|
|
6
6
|
useDerivedValue,
|
|
7
7
|
} from 'react-native-reanimated';
|
|
8
8
|
import type { DrawItem } from '../../types';
|
|
9
|
+
import { hslToRgb } from './CurrentAnimatedItem';
|
|
9
10
|
|
|
10
11
|
const styles = StyleSheet.create({
|
|
11
12
|
textBackground: {
|
|
@@ -60,8 +61,10 @@ export default function CurrentAnimatedText({
|
|
|
60
61
|
|
|
61
62
|
const textAnimatedStyle = useAnimatedStyle(() => {
|
|
62
63
|
return {
|
|
63
|
-
fontSize:
|
|
64
|
-
color:
|
|
64
|
+
fontSize: 10 + (currentItem.value?.strokeWidth ?? 0) * 2,
|
|
65
|
+
color: currentItem.value?.color
|
|
66
|
+
? hslToRgb(currentItem.value?.color)
|
|
67
|
+
: 'white',
|
|
65
68
|
};
|
|
66
69
|
}, [currentItem.value?.strokeWidth]);
|
|
67
70
|
|
|
@@ -83,16 +86,20 @@ export default function CurrentAnimatedText({
|
|
|
83
86
|
translateX:
|
|
84
87
|
(currentItem.value?.type === 'text' &&
|
|
85
88
|
(typeof currentItem.value.data.x === 'string'
|
|
86
|
-
? parseFloat(currentItem.value.data.x)
|
|
87
|
-
: currentItem.value.data.x
|
|
89
|
+
? parseFloat(currentItem.value.data.x) - 28
|
|
90
|
+
: currentItem.value.data.x
|
|
91
|
+
? currentItem.value.data.x - 28
|
|
92
|
+
: 0)) ||
|
|
88
93
|
0,
|
|
89
94
|
},
|
|
90
95
|
{
|
|
91
96
|
translateY:
|
|
92
97
|
(currentItem.value?.type === 'text' &&
|
|
93
98
|
(typeof currentItem.value.data.y === 'string'
|
|
94
|
-
? parseFloat(currentItem.value.data.y)
|
|
95
|
-
: currentItem.value.data.y
|
|
99
|
+
? parseFloat(currentItem.value.data.y) - 12
|
|
100
|
+
: currentItem.value.data.y
|
|
101
|
+
? currentItem.value.data.y - 12
|
|
102
|
+
: 0)) ||
|
|
96
103
|
0,
|
|
97
104
|
},
|
|
98
105
|
],
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { DrawItem, hslColor, DrawState, Action } from '../../types';
|
|
2
2
|
import { createContext, RefObject } from 'react';
|
|
3
|
+
import { TextInput } from 'react-native';
|
|
3
4
|
import type { SharedValue } from 'react-native-reanimated';
|
|
4
5
|
import type ViewShot from 'react-native-view-shot';
|
|
5
6
|
|
|
@@ -11,6 +12,7 @@ export const DrawContext = createContext<{
|
|
|
11
12
|
currentItem?: SharedValue<DrawItem | null>;
|
|
12
13
|
itemIsSelected?: SharedValue<boolean>;
|
|
13
14
|
viewShot?: RefObject<ViewShot>;
|
|
15
|
+
doubleArrowTextInput?: RefObject<TextInput>;
|
|
14
16
|
}>({
|
|
15
17
|
drawState: {
|
|
16
18
|
doneItems: [],
|
|
@@ -27,11 +27,11 @@ const DrawPad = ({
|
|
|
27
27
|
<Circle
|
|
28
28
|
id="selectionIndicator"
|
|
29
29
|
fill="#3a6cff"
|
|
30
|
-
r={
|
|
30
|
+
r={10}
|
|
31
31
|
cx={0}
|
|
32
32
|
cy={0}
|
|
33
33
|
strokeWidth={1}
|
|
34
|
-
stroke="
|
|
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
|
|
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
|
|