@archireport/react-native-svg-draw 3.1.2 → 3.2.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 (62) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +9 -2
  3. package/lib/commonjs/components/DrawCore/CurrentAnimatedItem.js +159 -148
  4. package/lib/commonjs/components/DrawCore/CurrentAnimatedItem.js.map +1 -1
  5. package/lib/commonjs/components/DrawCore/CurrentAnimatedText.js +18 -17
  6. package/lib/commonjs/components/DrawCore/CurrentAnimatedText.js.map +1 -1
  7. package/lib/commonjs/components/DrawCore/DrawPad.js +2 -2
  8. package/lib/commonjs/components/DrawCore/DrawPad.js.map +1 -1
  9. package/lib/commonjs/components/DrawCore/index.js +54 -14
  10. package/lib/commonjs/components/DrawCore/index.js.map +1 -1
  11. package/lib/commonjs/components/DrawCore/useDrawHook.js +1 -3
  12. package/lib/commonjs/components/DrawCore/useDrawHook.js.map +1 -1
  13. package/lib/commonjs/components/DrawWithOptions/index.js +6 -2
  14. package/lib/commonjs/components/DrawWithOptions/index.js.map +1 -1
  15. package/lib/commonjs/components/Slider/ColorSlider.js +18 -30
  16. package/lib/commonjs/components/Slider/ColorSlider.js.map +1 -1
  17. package/lib/commonjs/components/Slider/Sliders.js +1 -1
  18. package/lib/commonjs/components/Slider/Sliders.js.map +1 -1
  19. package/lib/commonjs/components/Slider/StrokeSlider.js +11 -23
  20. package/lib/commonjs/components/Slider/StrokeSlider.js.map +1 -1
  21. package/lib/module/components/DrawCore/CurrentAnimatedItem.js +158 -148
  22. package/lib/module/components/DrawCore/CurrentAnimatedItem.js.map +1 -1
  23. package/lib/module/components/DrawCore/CurrentAnimatedText.js +19 -18
  24. package/lib/module/components/DrawCore/CurrentAnimatedText.js.map +1 -1
  25. package/lib/module/components/DrawCore/DrawPad.js +2 -2
  26. package/lib/module/components/DrawCore/DrawPad.js.map +1 -1
  27. package/lib/module/components/DrawCore/index.js +54 -14
  28. package/lib/module/components/DrawCore/index.js.map +1 -1
  29. package/lib/module/components/DrawCore/useDrawHook.js +1 -3
  30. package/lib/module/components/DrawCore/useDrawHook.js.map +1 -1
  31. package/lib/module/components/DrawWithOptions/index.js +6 -2
  32. package/lib/module/components/DrawWithOptions/index.js.map +1 -1
  33. package/lib/module/components/Slider/ColorSlider.js +20 -32
  34. package/lib/module/components/Slider/ColorSlider.js.map +1 -1
  35. package/lib/module/components/Slider/Sliders.js +1 -1
  36. package/lib/module/components/Slider/Sliders.js.map +1 -1
  37. package/lib/module/components/Slider/StrokeSlider.js +13 -25
  38. package/lib/module/components/Slider/StrokeSlider.js.map +1 -1
  39. package/lib/typescript/components/DrawCore/CurrentAnimatedItem.d.ts +1 -0
  40. package/lib/typescript/components/DrawCore/CurrentAnimatedItem.d.ts.map +1 -1
  41. package/lib/typescript/components/DrawCore/CurrentAnimatedText.d.ts.map +1 -1
  42. package/lib/typescript/components/DrawCore/DrawPad.d.ts.map +1 -1
  43. package/lib/typescript/components/DrawCore/index.d.ts.map +1 -1
  44. package/lib/typescript/components/DrawCore/useDrawHook.d.ts.map +1 -1
  45. package/lib/typescript/components/DrawWithOptions/index.d.ts +3 -4
  46. package/lib/typescript/components/DrawWithOptions/index.d.ts.map +1 -1
  47. package/lib/typescript/components/Slider/ColorSlider.d.ts +2 -3
  48. package/lib/typescript/components/Slider/ColorSlider.d.ts.map +1 -1
  49. package/lib/typescript/components/Slider/Sliders.d.ts +2 -3
  50. package/lib/typescript/components/Slider/Sliders.d.ts.map +1 -1
  51. package/lib/typescript/components/Slider/StrokeSlider.d.ts.map +1 -1
  52. package/package.json +1 -1
  53. package/src/components/DrawCore/CurrentAnimatedItem.tsx +285 -333
  54. package/src/components/DrawCore/CurrentAnimatedText.tsx +14 -11
  55. package/src/components/DrawCore/DrawPad.tsx +4 -1
  56. package/src/components/DrawCore/index.tsx +77 -25
  57. package/src/components/DrawCore/useDrawHook.tsx +1 -2
  58. package/src/components/DrawWithOptions/index.tsx +12 -4
  59. package/src/components/Slider/ColorSlider.tsx +42 -50
  60. package/src/components/Slider/Sliders.tsx +4 -4
  61. package/src/components/Slider/StrokeSlider.tsx +24 -33
  62. package/src/types.d.ts +5 -0
@@ -1,10 +1,9 @@
1
- import React from 'react';
1
+ import React, { useState } from 'react';
2
2
  import Animated, {
3
- createAnimatedPropAdapter,
4
- processColor,
5
3
  runOnJS,
6
4
  useAnimatedProps,
7
5
  useAnimatedReaction,
6
+ useAnimatedStyle,
8
7
  } from 'react-native-reanimated';
9
8
  import { Path, Ellipse, Rect, Line, G } from 'react-native-svg';
10
9
  import type { hslColor, Point } from '../../types';
@@ -23,8 +22,6 @@ const AnimatedLine = Animated.createAnimatedComponent(Line);
23
22
 
24
23
  //const AnimatedText = Animated.createAnimatedComponent(Text);
25
24
 
26
- const AnimatedTextInput = Animated.createAnimatedComponent(TextInput);
27
-
28
25
  // properties of a line
29
26
  const line = (pointA: Point, pointB: Point) => {
30
27
  'worklet';
@@ -87,15 +84,26 @@ const bezierCommand = (point: Point, i: number, a: Point[]) => {
87
84
 
88
85
  export const pointsToPath = (points: Point[]) => {
89
86
  'worklet';
90
- return points.length > 0
91
- ? points.reduce(
92
- (acc, point, i, a) =>
93
- i === 0
94
- ? `M ${point.x},${point.y}`
95
- : `${acc} ${bezierCommand(point, i, a)}`,
96
- ''
97
- )
98
- : '';
87
+ if (points.length === 0) {
88
+ return '';
89
+ }
90
+
91
+ let path = '';
92
+
93
+ for (let index = 0; index < points.length; index += 1) {
94
+ const point = points[index];
95
+
96
+ if (!point) {
97
+ continue;
98
+ }
99
+
100
+ path =
101
+ index === 0
102
+ ? `M ${point.x},${point.y}`
103
+ : `${path} ${bezierCommand(point, index, points)}`;
104
+ }
105
+
106
+ return path;
99
107
  };
100
108
 
101
109
  function hue2rgb(p: number, q: number, t: number) {
@@ -145,26 +153,8 @@ export function hslToRgb(col: hslColor) {
145
153
  )})`;
146
154
  }
147
155
 
148
- const propAdapter = createAnimatedPropAdapter(
149
- (props: Record<string, unknown>) => {
150
- if (
151
- Object.keys(props).includes('fill') &&
152
- (typeof props.fill === 'string' || typeof props.fill === 'number')
153
- ) {
154
- props.fill = { type: 0, payload: processColor(props.fill as string) };
155
- }
156
- if (
157
- Object.keys(props).includes('stroke') &&
158
- (typeof props.stroke === 'string' || typeof props.stroke === 'number')
159
- ) {
160
- props.stroke = { type: 0, payload: processColor(props.stroke as string) };
161
- }
162
- },
163
- ['fill', 'stroke']
164
- );
165
-
166
156
  export default function CurrentAnimatedItem() {
167
- const { currentItem, doubleArrowTextInput } = useDrawHook();
157
+ const { currentItem } = useDrawHook();
168
158
 
169
159
  const getTextLength = () => {
170
160
  'worklet';
@@ -175,83 +165,74 @@ export default function CurrentAnimatedItem() {
175
165
  return textLength;
176
166
  };
177
167
 
178
- const ellipseAnimatedProps = useAnimatedProps(
179
- () => {
180
- const coordinates =
168
+ const ellipseAnimatedProps = useAnimatedProps(() => {
169
+ 'worklet';
170
+ const coordinates =
171
+ currentItem.value?.type === 'ellipse'
172
+ ? currentItem.value.data
173
+ : { cx: -10, cy: -10, rx: 0, ry: 0 };
174
+
175
+ return {
176
+ cx: coordinates.cx,
177
+ cy: coordinates.cy,
178
+ rx: coordinates.rx,
179
+ ry: coordinates.ry,
180
+ fill: 'transparent',
181
+ stroke: hslToRgb(currentItem.value?.color || 'hsl(0, 0%, 0%)'),
182
+ opacity: currentItem.value?.type === 'ellipse' ? 1 : 0,
183
+ strokeWidth:
181
184
  currentItem.value?.type === 'ellipse'
182
- ? currentItem.value.data
183
- : { cx: -10, cy: -10, rx: 0, ry: 0 };
184
-
185
- return {
186
- cx: coordinates.cx,
187
- cy: coordinates.cy,
188
- rx: coordinates.rx,
189
- ry: coordinates.ry,
190
- fill: 'transparent',
191
- //stroke: hslToRgb(currentItem.value?.color || 'hsl(0, 0%, 0%)'),
192
- opacity: currentItem.value?.type === 'ellipse' ? 1 : 0,
193
- strokeWidth:
194
- currentItem.value?.type === 'ellipse'
195
- ? currentItem.value.strokeWidth
196
- : 0,
197
- marker: 'url(#selection)',
198
- };
199
- },
200
- null,
201
- propAdapter
202
- );
185
+ ? currentItem.value.strokeWidth
186
+ : 0,
187
+ marker: 'url(#selection)',
188
+ };
189
+ });
203
190
 
204
- const singleHeadAnimatedProps = useAnimatedProps(
205
- () => {
206
- const coordinates =
191
+ const singleHeadAnimatedProps = useAnimatedProps(() => {
192
+ 'worklet';
193
+ const coordinates =
194
+ currentItem.value?.type === 'singleHead'
195
+ ? currentItem.value.data
196
+ : { x1: -10, y1: -10, x2: -10, y2: -10 };
197
+ return {
198
+ x1: coordinates.x1,
199
+ y1: coordinates.y1,
200
+ x2: coordinates.x2,
201
+ y2: coordinates.y2,
202
+ fill: 'transparent',
203
+ stroke: hslToRgb(currentItem.value?.color || 'hsl(0, 0%, 0%)'),
204
+ opacity: currentItem.value?.type === 'singleHead' ? 1 : 0,
205
+ strokeWidth:
207
206
  currentItem.value?.type === 'singleHead'
208
- ? currentItem.value.data
209
- : { x1: -10, y1: -10, x2: -10, y2: -10 };
210
- return {
211
- x1: coordinates.x1,
212
- y1: coordinates.y1,
213
- x2: coordinates.x2,
214
- y2: coordinates.y2,
215
- fill: 'transparent',
216
- //stroke: hslToRgb(currentItem.value?.color || 'hsl(0, 0%, 0%)'),
217
- opacity: currentItem.value?.type === 'singleHead' ? 1 : 0,
218
- strokeWidth:
219
- currentItem.value?.type === 'singleHead'
220
- ? currentItem.value.strokeWidth
221
- : 0,
222
- markerEnd: 'arrowhead',
223
- };
224
- },
225
- null,
226
- propAdapter
227
- );
207
+ ? currentItem.value.strokeWidth
208
+ : 0,
209
+ markerEnd: 'arrowhead',
210
+ };
211
+ });
228
212
 
229
- const doubleHeadAnimatedProps = useAnimatedProps(
230
- () => {
231
- const coordinates =
213
+ const doubleHeadAnimatedProps = useAnimatedProps(() => {
214
+ 'worklet';
215
+ const coordinates =
216
+ currentItem.value?.type === 'doubleHead'
217
+ ? currentItem.value.data
218
+ : { x1: -10, y1: -10, x2: -10, y2: -10 };
219
+
220
+ return {
221
+ x1: coordinates.x1,
222
+ y1: coordinates.y1,
223
+ x2: coordinates.x2,
224
+ y2: coordinates.y2,
225
+ fill: 'transparent',
226
+ stroke: hslToRgb(currentItem.value?.color || 'hsl(0, 0%, 0%)'),
227
+ opacity: currentItem.value?.type === 'doubleHead' ? 1 : 0,
228
+ strokeWidth:
232
229
  currentItem.value?.type === 'doubleHead'
233
- ? currentItem.value.data
234
- : { x1: -10, y1: -10, x2: -10, y2: -10 };
235
-
236
- return {
237
- x1: coordinates.x1,
238
- y1: coordinates.y1,
239
- x2: coordinates.x2,
240
- y2: coordinates.y2,
241
- fill: 'transparent',
242
- //stroke: hslToRgb(currentItem.value?.color || 'hsl(0, 0%, 0%)'),
243
- opacity: currentItem.value?.type === 'doubleHead' ? 1 : 0,
244
- strokeWidth:
245
- currentItem.value?.type === 'doubleHead'
246
- ? currentItem.value.strokeWidth
247
- : 0,
248
- markerStart: 'side',
249
- markerEnd: 'side',
250
- };
251
- },
252
- null,
253
- propAdapter
254
- );
230
+ ? currentItem.value.strokeWidth
231
+ : 0,
232
+ markerStart: 'side',
233
+ markerEnd: 'side',
234
+ };
235
+ });
255
236
  const distance = (x1: number, y1: number, x2: number, y2: number) => {
256
237
  'worklet';
257
238
  return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
@@ -334,85 +315,157 @@ export default function CurrentAnimatedItem() {
334
315
  return [newX1, newY1, newX2, newY2];
335
316
  };
336
317
 
337
- const doubleArrowsAnimatedPropsFirst = useAnimatedProps(
338
- () => {
339
- let x1, y1, x2, y2;
318
+ const doubleArrowsAnimatedPropsFirst = useAnimatedProps(() => {
319
+ 'worklet';
320
+ let x1, y1, x2, y2;
340
321
 
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
- }
322
+ if (currentItem.value?.type !== 'doubleArrows') {
323
+ x1 = -10;
324
+ y1 = -10;
325
+ x2 = -10;
326
+ y2 = -10;
327
+ } else {
328
+ const coordinates = currentItem.value.data;
329
+ [x1, y1, x2, y2] = getGetcoordinateValue({
330
+ x1: Number(coordinates.x1),
331
+ y1: Number(coordinates.y1),
332
+ x2: Number(coordinates.x2),
333
+ y2: Number(coordinates.y2),
334
+ first: true,
335
+ //text: currentItem.value?.text,
336
+ });
337
+ }
357
338
 
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
- );
339
+ return {
340
+ x1,
341
+ y1,
342
+ x2,
343
+ y2,
344
+ fill: 'transparent',
345
+ stroke: hslToRgb(currentItem.value?.color || 'hsl(0, 0%, 0%)'),
346
+ opacity: currentItem.value?.type === 'doubleArrows' ? 1 : 0,
347
+ strokeWidth:
348
+ currentItem.value?.type === 'doubleArrows'
349
+ ? currentItem.value.strokeWidth
350
+ : 0,
351
+ markerStart: 'arrowheadStart',
352
+ };
353
+ });
354
+
355
+ const doubleArrowsAnimatedPropsLast = useAnimatedProps(() => {
356
+ 'worklet';
357
+ let x1, y1, x2, y2;
376
358
 
377
- const doubleArrowsAnimatedPropsLast = useAnimatedProps(
378
- () => {
379
- let x1, y1, x2, y2;
359
+ if (currentItem.value?.type !== 'doubleArrows') {
360
+ x1 = -10;
361
+ y1 = -10;
362
+ x2 = -10;
363
+ y2 = -10;
364
+ } else {
365
+ const coordinates = currentItem.value.data;
366
+ [x1, y1, x2, y2] = getGetcoordinateValue({
367
+ x1: Number(coordinates.x1),
368
+ y1: Number(coordinates.y1),
369
+ x2: Number(coordinates.x2),
370
+ y2: Number(coordinates.y2),
371
+ first: false,
372
+ //text: currentItem.value?.text,
373
+ });
374
+ }
380
375
 
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
- }
376
+ return {
377
+ x1,
378
+ y1,
379
+ x2,
380
+ y2,
381
+ fill: 'transparent',
382
+ stroke: hslToRgb(currentItem.value?.color || 'hsl(0, 0%, 0%)'),
383
+ opacity: currentItem.value?.type === 'doubleArrows' ? 1 : 0,
384
+ strokeWidth:
385
+ currentItem.value?.type === 'doubleArrows'
386
+ ? currentItem.value.strokeWidth
387
+ : 0,
388
+ markerEnd: 'arrowhead',
389
+ };
390
+ });
391
+
392
+ const rectangleAnimatedProps = useAnimatedProps(() => {
393
+ 'worklet';
394
+ const coordinates =
395
+ currentItem.value?.type === 'rectangle'
396
+ ? currentItem.value.data
397
+ : { x: -10, y: -10, width: 0, height: 0 };
398
+ return {
399
+ x: coordinates.x,
400
+ y: coordinates.y,
401
+ width: coordinates.width,
402
+ height: coordinates.height,
403
+ fill: 'transparent',
404
+ stroke: hslToRgb(currentItem.value?.color || 'hsl(0, 0%, 0%)'),
405
+ opacity: currentItem.value?.type === 'rectangle' ? 1 : 0,
406
+ strokeWidth:
407
+ currentItem.value?.type === 'rectangle'
408
+ ? currentItem.value.strokeWidth
409
+ : 0,
397
410
 
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
411
+ marker: 'url(#selection)',
412
+ };
413
+ });
414
+
415
+ const penAnimatedProps = useAnimatedProps(() => {
416
+ 'worklet';
417
+ const d = pointsToPath(
418
+ currentItem.value?.type === 'pen'
419
+ ? currentItem.value.data
420
+ : [{ x: -10, y: -10 }]
421
+ );
422
+ return {
423
+ d: d,
424
+ opacity: currentItem.value?.type === 'pen' ? 1 : 0,
425
+ stroke: hslToRgb(currentItem.value?.color || 'hsl(0, 0%, 0%)'),
426
+ strokeWidth:
427
+ currentItem.value?.type === 'pen' ? currentItem.value.strokeWidth : 0,
428
+ fill: 'transparent',
429
+ markerStart: 'selection',
430
+ markerEnd: 'selection',
431
+ };
432
+ });
433
+
434
+ return (
435
+ <>
436
+ <AnimatedEllipse animatedProps={ellipseAnimatedProps} />
437
+ <G markerStart="url(#selection)" markerEnd="url(#selection)">
438
+ <AnimatedLine animatedProps={singleHeadAnimatedProps} />
439
+ </G>
440
+ <G markerStart="url(#selection)" markerEnd="url(#selection)">
441
+ <AnimatedLine animatedProps={doubleHeadAnimatedProps} />
442
+ </G>
443
+ <G markerStart="url(#selection)" markerEnd="url(#selection)">
444
+ <AnimatedLine animatedProps={doubleArrowsAnimatedPropsFirst} />
445
+
446
+ <AnimatedLine animatedProps={doubleArrowsAnimatedPropsLast} />
447
+ </G>
448
+ <AnimatedRectangle animatedProps={rectangleAnimatedProps} />
449
+ <AnimatedPath animatedProps={penAnimatedProps} />
450
+ </>
415
451
  );
452
+ }
453
+
454
+ export function DoubleArrowsTextInput() {
455
+ const { currentItem, doubleArrowTextInput } = useDrawHook();
456
+
457
+ const getTextLength = () => {
458
+ 'worklet';
459
+ const text =
460
+ currentItem.value?.type === 'doubleArrows' ? currentItem.value?.text : '';
461
+ const textLength = text && text.length > 5 ? text.length * 10 : 50;
462
+ return textLength;
463
+ };
464
+
465
+ const distance = (x1: number, y1: number, x2: number, y2: number) => {
466
+ 'worklet';
467
+ return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
468
+ };
416
469
 
417
470
  const getTextValues = ({
418
471
  x1,
@@ -448,174 +501,73 @@ export default function CurrentAnimatedItem() {
448
501
 
449
502
  return [newX, newY, angle];
450
503
  };
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
504
 
505
+ const containerStyle = useAnimatedStyle(() => {
506
+ let x = 0,
507
+ y = 0,
508
+ angle = 0;
509
+
510
+ if (currentItem.value?.type !== 'doubleArrows') {
511
+ x = -50;
512
+ y = -50;
513
+ angle = 0;
514
+ } else {
515
+ const coordinates = currentItem.value.data;
516
+ [x, y, angle] = getTextValues({
517
+ x1: Number(coordinates.x1),
518
+ y1: Number(coordinates.y1),
519
+ x2: Number(coordinates.x2),
520
+ y2: Number(coordinates.y2),
521
+ });
522
+ }
523
+
524
+ return {
525
+ position: 'absolute' as const,
526
+ top: y - 25,
527
+ left: x - getTextLength() / 2,
528
+ transform: [{ rotateZ: `${angle}deg` }],
529
+ width: getTextLength(),
530
+ height: 50,
531
+ };
532
+ });
533
+
534
+ const [textStyle, setTextStyle] = useState<{
535
+ fontSize: number;
536
+ color: string;
537
+ }>({
538
+ fontSize: 12,
539
+ color: 'white',
540
+ });
541
+
542
+ useAnimatedReaction(
543
+ () => {
471
544
  return {
472
- top: y - 25,
473
- left: x - getTextLength() / 2,
474
545
  fontSize: 10 + (currentItem.value?.strokeWidth ?? 0) * 2,
475
546
  color: currentItem.value?.color
476
547
  ? hslToRgb(currentItem.value?.color)
477
548
  : 'white',
478
- transform: [{ rotateZ: `${angle}deg` }],
479
- //backgroundColor: 'red',
480
- width: getTextLength(),
481
- height: 50,
482
- };
483
- },
484
- null,
485
- propAdapter
486
- );
487
-
488
- const rectangleAnimatedProps = useAnimatedProps(
489
- () => {
490
- const coordinates =
491
- currentItem.value?.type === 'rectangle'
492
- ? currentItem.value.data
493
- : { x: -10, y: -10, width: 0, height: 0 };
494
- return {
495
- x: coordinates.x,
496
- y: coordinates.y,
497
- width: coordinates.width,
498
- height: coordinates.height,
499
- fill: 'transparent',
500
- //stroke: hslToRgb(currentItem.value?.color || 'hsl(0, 0%, 0%)'),
501
- opacity: currentItem.value?.type === 'rectangle' ? 1 : 0,
502
- strokeWidth:
503
- currentItem.value?.type === 'rectangle'
504
- ? currentItem.value.strokeWidth
505
- : 0,
506
-
507
- marker: 'url(#selection)',
508
- };
509
- },
510
- null,
511
- propAdapter
512
- );
513
-
514
- const penAnimatedProps = useAnimatedProps(
515
- () => {
516
- const d = pointsToPath(
517
- currentItem.value?.type === 'pen'
518
- ? currentItem.value.data
519
- : [{ x: -10, y: -10 }]
520
- );
521
- return {
522
- d: d,
523
- //opacity: 1,
524
- opacity: currentItem.value?.type === 'pen' ? 1 : 0,
525
- //stroke: currentItem.value?.color || "black",
526
- strokeWidth:
527
- currentItem.value?.type === 'pen' ? currentItem.value.strokeWidth : 0,
528
- fill: 'transparent',
529
- markerStart: 'selection',
530
- markerEnd: 'selection',
531
549
  };
532
550
  },
533
- null,
534
- propAdapter
535
- );
536
-
537
- const updateText = (value: string) => {
538
- if (!doubleArrowTextInput?.current) return;
539
- doubleArrowTextInput.current.setNativeProps({
540
- text: value,
541
- });
542
- };
543
- useAnimatedReaction(
544
- () => {
545
- return currentItem.value?.type === 'doubleArrows'
546
- ? currentItem.value?.text || ''
547
- : '';
548
- },
549
551
  (value) => {
550
- if (updateText) runOnJS(updateText)(value);
551
- },
552
- [updateText, doubleArrowTextInput]
552
+ runOnJS(setTextStyle)(value);
553
+ }
553
554
  );
554
555
 
555
556
  return (
556
- <>
557
- <AnimatedEllipse
558
- animatedProps={ellipseAnimatedProps}
559
- stroke={currentItem.value?.color || 'black'}
560
- />
561
- <G markerStart="url(#selection)" markerEnd="url(#selection)">
562
- <AnimatedLine
563
- animatedProps={singleHeadAnimatedProps}
564
- stroke={currentItem.value?.color || 'black'}
565
- />
566
- </G>
567
- <G markerStart="url(#selection)" markerEnd="url(#selection)">
568
- <AnimatedLine
569
- animatedProps={doubleHeadAnimatedProps}
570
- stroke={currentItem.value?.color || 'black'}
571
- />
572
- </G>
573
- <G markerStart="url(#selection)" markerEnd="url(#selection)">
574
- <AnimatedLine
575
- animatedProps={doubleArrowsAnimatedPropsFirst}
576
- stroke={currentItem.value?.color || 'black'}
577
- />
578
-
579
- <AnimatedTextInput
580
- animatedProps={{
581
- ...(doubleArrowsAnimatedPropsText as any), // Type cast to bypass the type error
582
- // Ensure other relevant props if needed
583
- }}
584
- value={
585
- currentItem.value?.type === 'doubleArrows'
586
- ? currentItem.value.text
587
- : ''
557
+ <Animated.View style={containerStyle}>
558
+ <TextInput
559
+ ref={doubleArrowTextInput}
560
+ underlineColorAndroid={'transparent'}
561
+ onChangeText={(text) => {
562
+ if (currentItem.value?.type === 'doubleArrows') {
563
+ currentItem.value = {
564
+ ...currentItem.value,
565
+ text,
566
+ };
588
567
  }
589
- ref={doubleArrowTextInput}
590
- underlineColorAndroid={'transparent'}
591
- onChangeText={(text) => {
592
- if (currentItem.value?.type === 'doubleArrows') {
593
- currentItem.value = {
594
- ...currentItem.value,
595
- text,
596
- };
597
- }
598
- }}
599
- style={{
600
- color: 'black',
601
- fontSize: 24,
602
- position: 'absolute',
603
- }}
604
- />
605
-
606
- <AnimatedLine
607
- animatedProps={doubleArrowsAnimatedPropsLast}
608
- stroke={currentItem.value?.color || 'black'}
609
- />
610
- </G>
611
- <AnimatedRectangle
612
- animatedProps={rectangleAnimatedProps}
613
- stroke={currentItem.value?.color || 'black'}
614
- />
615
- <AnimatedPath
616
- animatedProps={penAnimatedProps}
617
- stroke={currentItem.value?.color || 'black'}
568
+ }}
569
+ style={textStyle}
618
570
  />
619
- </>
571
+ </Animated.View>
620
572
  );
621
573
  }