@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.
Files changed (50) hide show
  1. package/README.md +34 -35
  2. package/lib/commonjs/components/DrawCore/DrawContext.js +4 -1
  3. package/lib/commonjs/components/DrawCore/DrawContext.js.map +1 -1
  4. package/lib/commonjs/components/DrawCore/DrawPad.js +9 -3
  5. package/lib/commonjs/components/DrawCore/DrawPad.js.map +1 -1
  6. package/lib/commonjs/components/DrawCore/DrawProvider.js +16 -2
  7. package/lib/commonjs/components/DrawCore/DrawProvider.js.map +1 -1
  8. package/lib/commonjs/components/DrawCore/Item.js +12 -35
  9. package/lib/commonjs/components/DrawCore/Item.js.map +1 -1
  10. package/lib/commonjs/components/DrawCore/index.js +574 -576
  11. package/lib/commonjs/components/DrawCore/index.js.map +1 -1
  12. package/lib/commonjs/components/DrawCore/useDrawHook.js +15 -13
  13. package/lib/commonjs/components/DrawCore/useDrawHook.js.map +1 -1
  14. package/lib/commonjs/components/DrawWithOptions/index.js +7 -11
  15. package/lib/commonjs/components/DrawWithOptions/index.js.map +1 -1
  16. package/lib/module/components/DrawCore/DrawContext.js +4 -1
  17. package/lib/module/components/DrawCore/DrawContext.js.map +1 -1
  18. package/lib/module/components/DrawCore/DrawPad.js +10 -4
  19. package/lib/module/components/DrawCore/DrawPad.js.map +1 -1
  20. package/lib/module/components/DrawCore/DrawProvider.js +17 -3
  21. package/lib/module/components/DrawCore/DrawProvider.js.map +1 -1
  22. package/lib/module/components/DrawCore/Item.js +14 -37
  23. package/lib/module/components/DrawCore/Item.js.map +1 -1
  24. package/lib/module/components/DrawCore/index.js +575 -577
  25. package/lib/module/components/DrawCore/index.js.map +1 -1
  26. package/lib/module/components/DrawCore/useDrawHook.js +15 -13
  27. package/lib/module/components/DrawCore/useDrawHook.js.map +1 -1
  28. package/lib/module/components/DrawWithOptions/index.js +8 -12
  29. package/lib/module/components/DrawWithOptions/index.js.map +1 -1
  30. package/lib/typescript/components/DrawCore/DrawContext.d.ts +3 -0
  31. package/lib/typescript/components/DrawCore/DrawContext.d.ts.map +1 -1
  32. package/lib/typescript/components/DrawCore/DrawPad.d.ts +2 -1
  33. package/lib/typescript/components/DrawCore/DrawPad.d.ts.map +1 -1
  34. package/lib/typescript/components/DrawCore/DrawProvider.d.ts.map +1 -1
  35. package/lib/typescript/components/DrawCore/Item.d.ts.map +1 -1
  36. package/lib/typescript/components/DrawCore/index.d.ts +2 -1
  37. package/lib/typescript/components/DrawCore/index.d.ts.map +1 -1
  38. package/lib/typescript/components/DrawCore/useDrawHook.d.ts +4 -1
  39. package/lib/typescript/components/DrawCore/useDrawHook.d.ts.map +1 -1
  40. package/lib/typescript/components/DrawWithOptions/index.d.ts +1 -1
  41. package/lib/typescript/components/DrawWithOptions/index.d.ts.map +1 -1
  42. package/package.json +5 -1
  43. package/src/components/DrawCore/DrawContext.tsx +6 -0
  44. package/src/components/DrawCore/DrawPad.tsx +76 -67
  45. package/src/components/DrawCore/DrawProvider.tsx +23 -1
  46. package/src/components/DrawCore/Item.tsx +15 -47
  47. package/src/components/DrawCore/index.tsx +109 -114
  48. package/src/components/DrawCore/useDrawHook.tsx +12 -7
  49. package/src/components/DrawWithOptions/index.tsx +10 -11
  50. package/src/types.d.ts +5 -3
@@ -12,15 +12,11 @@ import {
12
12
  } from 'react-native';
13
13
  import Animated, {
14
14
  runOnJS,
15
- useAnimatedGestureHandler,
16
15
  useAnimatedKeyboard,
17
16
  useAnimatedReaction,
18
17
  useSharedValue,
19
18
  } from 'react-native-reanimated';
20
- import {
21
- PanGestureHandler,
22
- PanGestureHandlerGestureEvent,
23
- } from 'react-native-gesture-handler';
19
+ import { Gesture, GestureDetector } from 'react-native-gesture-handler';
24
20
 
25
21
  import type { DrawItem, DrawItemType, hslColor, Size } from '../../types';
26
22
  import DrawPad from './DrawPad';
@@ -226,9 +222,11 @@ const onTextHeightUpdate = (
226
222
  const DrawCore = ({
227
223
  image,
228
224
  backgroundColor,
225
+ actionWithSnapShotUri,
229
226
  }: {
230
227
  image?: ImageRequireSource | ImageURISource;
231
228
  backgroundColor?: string;
229
+ actionWithSnapShotUri?: (uri: string) => Promise<void>;
232
230
  }) => {
233
231
  const {
234
232
  drawState,
@@ -239,27 +237,59 @@ const DrawCore = ({
239
237
  itemIsSelected,
240
238
  viewShot,
241
239
  doubleArrowTextInput,
240
+ captureSnapshot,
241
+ snapShotRequested,
242
+ setSnapShotRequested,
242
243
  } = useDrawHook();
243
244
 
245
+ const [drawRegion, setDrawRegion] = useState<Size | null>(null);
246
+ const [imageSize, setImageSize] = useState<Size | null>(null);
247
+ const [originalImageSize, setOriginalImageSize] = useState<Size | null>(null);
248
+
249
+ useEffect(() => {
250
+ if (snapShotRequested) {
251
+ setSnapShotRequested(false);
252
+ setNewLayoutRequested(true);
253
+ if (
254
+ imageSize?.height &&
255
+ originalImageSize?.height &&
256
+ originalImageSize?.width &&
257
+ image
258
+ ) {
259
+ setOpacity(0);
260
+ setRatioImage(originalImageSize.height / imageSize?.height);
261
+ setImageSize(originalImageSize);
262
+ } else if (!image && drawRegion?.height) {
263
+ const width = 1500;
264
+ const height = width / 1.3333333;
265
+ setOpacity(0);
266
+ setRatioImage(height / drawRegion.height);
267
+ setImageSize({ width, height });
268
+ }
269
+ }
270
+ }, [
271
+ snapShotRequested,
272
+ drawRegion?.height,
273
+ image,
274
+ imageSize?.height,
275
+ originalImageSize,
276
+ setSnapShotRequested,
277
+ ]);
278
+
244
279
  const onCancelChangeWrapper = (arg: boolean) => {
245
280
  dispatchDrawStates({ type: 'SET_CANCEL_ENABLED', cancelEnabled: arg });
246
281
  };
247
282
 
248
283
  const mode = useSharedValue<DrawItemType>('pen');
249
-
250
- const [drawRegion, setDrawRegion] = useState<Size | null>(null);
251
-
252
- const [originalImageSize, setOriginalImageSize] = useState<Size | null>(null);
253
-
254
- const [imageSize, setImageSize] = useState<Size | null>(null);
255
-
256
284
  const drawContainer = useRef<View>(null);
257
-
258
285
  const [textVal, setTextVal] = useState<string>('');
259
-
260
286
  const initialItem = useSharedValue<DrawItem | null>(null);
261
-
262
287
  const textBaseHeight = useSharedValue<number | null>(null);
288
+ const gestureContext = useSharedValue<Context>({
289
+ startX: 0,
290
+ startY: 0,
291
+ newlyCreated: false,
292
+ });
263
293
 
264
294
  const addDoneItem = useCallback(
265
295
  (item: DrawItem) => {
@@ -297,19 +327,16 @@ const DrawCore = ({
297
327
  const showTextInput = useSharedValue(false); //TODO: remove
298
328
 
299
329
  const textFocusState = useCallback(() => {
300
- //setShowTextInputState(true);
301
- console.log('textFocusState');
302
330
  doubleArrowTextInput?.current?.focus();
303
331
  }, [doubleArrowTextInput]);
304
332
 
305
333
  const textFocus = useCallback(() => {
306
- console.log('textFocus');
307
334
  textInputRef.current?.focus();
308
335
  }, []);
309
336
 
310
337
  useEffect(() => {
311
338
  if (currentItem.value?.type === 'text') {
312
- console.log('use effect text');
339
+ console.log('Updating text value:');
313
340
  showTextInput.value = true;
314
341
  textFocus();
315
342
  currentItem.value = {
@@ -322,18 +349,11 @@ const DrawCore = ({
322
349
  }
323
350
  }, [currentItem, showTextInput, textFocus, textVal]);
324
351
 
325
- const onGestureEvent = useAnimatedGestureHandler<
326
- PanGestureHandlerGestureEvent,
327
- Context
328
- >({
329
- onStart: ({ x: startX, y: startY }, ctx) => {
330
- ctx.startX = startX;
331
- ctx.startY = startY;
332
- ctx.newlyCreated = false;
333
- console.log('**********************************');
334
- console.log('onGestureEvent');
335
- //panPosition.value = withTiming(RIGHT_PANE_WIDTH);
336
- console.log('onStart', currentItem.value?.type);
352
+ const panGesture = Gesture.Pan()
353
+ .onStart((event) => {
354
+ const { x: startX, y: startY } = event;
355
+ gestureContext.value = { startX, startY, newlyCreated: false };
356
+
337
357
  initialItem.value = currentItem.value;
338
358
  switch (currentItem.value?.type) {
339
359
  case 'ellipse':
@@ -360,37 +380,37 @@ const DrawCore = ({
360
380
  startY <= cy - ry + THRESHOLD &&
361
381
  startY >= cy - ry - THRESHOLD
362
382
  ) {
363
- ctx.zone = 'TOP';
383
+ gestureContext.value.zone = 'TOP';
364
384
  } else if (
365
385
  startX <= cx + THRESHOLD &&
366
386
  startX >= cx - THRESHOLD &&
367
387
  startY <= cy + ry + THRESHOLD &&
368
388
  startY >= cy + ry - THRESHOLD
369
389
  ) {
370
- ctx.zone = 'BOTTOM';
390
+ gestureContext.value.zone = 'BOTTOM';
371
391
  } else if (
372
392
  startY <= cy + THRESHOLD &&
373
393
  startY >= cy - THRESHOLD &&
374
394
  startX <= cx - rx + THRESHOLD &&
375
395
  startX >= cx - rx - THRESHOLD
376
396
  ) {
377
- ctx.zone = 'LEFT';
397
+ gestureContext.value.zone = 'LEFT';
378
398
  } else if (
379
399
  startY <= cy + THRESHOLD &&
380
400
  startY >= cy - THRESHOLD &&
381
401
  startX <= cx + rx + THRESHOLD &&
382
402
  startX >= cx + rx - THRESHOLD
383
403
  ) {
384
- ctx.zone = 'RIGHT';
404
+ gestureContext.value.zone = 'RIGHT';
385
405
  } else if (
386
406
  ((rx > 0 && startX > cx - rx && startX < cx + rx) ||
387
407
  (rx < 0 && startX < cx - rx && startX > cx + rx)) &&
388
408
  ((ry > 0 && startY > cy - ry && startY < cy + ry) ||
389
409
  (ry < 0 && startY < cy - ry && startY > cy + ry))
390
410
  ) {
391
- ctx.zone = 'CENTER';
411
+ gestureContext.value.zone = 'CENTER';
392
412
  } else {
393
- ctx.zone = 'OUT';
413
+ gestureContext.value.zone = 'OUT';
394
414
  initialItem.value = null;
395
415
  }
396
416
 
@@ -415,24 +435,24 @@ const DrawCore = ({
415
435
 
416
436
  if (startX <= x + THRESHOLD && startX >= x - THRESHOLD) {
417
437
  if (startY <= y + THRESHOLD && startY >= y - THRESHOLD) {
418
- ctx.zone = 'TOP_LEFT';
438
+ gestureContext.value.zone = 'TOP_LEFT';
419
439
  } else if (
420
440
  startY <= y + height + THRESHOLD &&
421
441
  startY >= y + height - THRESHOLD
422
442
  ) {
423
- ctx.zone = 'BOTTOM_LEFT';
443
+ gestureContext.value.zone = 'BOTTOM_LEFT';
424
444
  }
425
445
  } else if (
426
446
  startX <= x + width + THRESHOLD &&
427
447
  startX >= x + width - THRESHOLD
428
448
  ) {
429
449
  if (startY <= y + THRESHOLD && startY >= y - THRESHOLD) {
430
- ctx.zone = 'TOP_RIGHT';
450
+ gestureContext.value.zone = 'TOP_RIGHT';
431
451
  } else if (
432
452
  startY <= y + height + THRESHOLD &&
433
453
  startY >= y + height - THRESHOLD
434
454
  ) {
435
- ctx.zone = 'BOTTOM_RIGHT';
455
+ gestureContext.value.zone = 'BOTTOM_RIGHT';
436
456
  }
437
457
  } else if (
438
458
  ((width > 0 && startX > x && startX < x + width) ||
@@ -440,9 +460,9 @@ const DrawCore = ({
440
460
  ((height > 0 && startY > y && startY < y + height) ||
441
461
  (height < 0 && startY < y && startY > y + height))
442
462
  ) {
443
- ctx.zone = 'CENTER';
463
+ gestureContext.value.zone = 'CENTER';
444
464
  } else {
445
- ctx.zone = 'OUT';
465
+ gestureContext.value.zone = 'OUT';
446
466
  initialItem.value = null;
447
467
  }
448
468
 
@@ -473,23 +493,23 @@ const DrawCore = ({
473
493
  startY <= y1 + THRESHOLD &&
474
494
  startY >= y1 - THRESHOLD
475
495
  ) {
476
- ctx.zone = 'TOP';
496
+ gestureContext.value.zone = 'TOP';
477
497
  } else if (
478
498
  startX <= x2 + THRESHOLD &&
479
499
  startX >= x2 - THRESHOLD &&
480
500
  startY - THRESHOLD <= y2 + THRESHOLD &&
481
501
  startY + THRESHOLD >= y2 - THRESHOLD
482
502
  ) {
483
- ctx.zone = 'BOTTOM';
503
+ gestureContext.value.zone = 'BOTTOM';
484
504
  } else if (
485
505
  pDistance({ x: startX, y: startY }, { x1, x2, y1, y2 }) <=
486
506
  THRESHOLD &&
487
507
  ((startX > x1 && startX < x2) || (startX < x1 && startX > x2)) &&
488
508
  ((startY > y1 && startY < y2) || (startY < y1 && startY > y2))
489
509
  ) {
490
- ctx.zone = 'CENTER';
510
+ gestureContext.value.zone = 'CENTER';
491
511
  } else {
492
- ctx.zone = 'OUT';
512
+ gestureContext.value.zone = 'OUT';
493
513
  initialItem.value = null;
494
514
  }
495
515
 
@@ -511,22 +531,21 @@ const DrawCore = ({
511
531
  typeof currentItem.value.data.height === 'string'
512
532
  ? parseFloat(currentItem.value.data.height)
513
533
  : currentItem.value.data.height || 0;
514
- console.log(heightText);
515
- console.log(widthText);
534
+
516
535
  if (
517
536
  startX <= xText + THRESHOLD &&
518
537
  startX >= xText - THRESHOLD &&
519
538
  startY <= yText + heightText / 2 + THRESHOLD &&
520
539
  startY >= yText + heightText / 2 - THRESHOLD
521
540
  ) {
522
- ctx.zone = 'LEFT';
541
+ gestureContext.value.zone = 'LEFT';
523
542
  } else if (
524
543
  startX <= xText + widthText + THRESHOLD &&
525
544
  startX >= xText + widthText - THRESHOLD &&
526
545
  startY <= yText + heightText / 2 + THRESHOLD &&
527
546
  startY >= yText + heightText / 2 - THRESHOLD
528
547
  ) {
529
- ctx.zone = 'RIGHT';
548
+ gestureContext.value.zone = 'RIGHT';
530
549
  } else if (
531
550
  ((widthText > 0 && startX > xText && startX < xText + widthText) ||
532
551
  (widthText < 0 &&
@@ -537,14 +556,12 @@ const DrawCore = ({
537
556
  startY < yText + heightText) ||
538
557
  (heightText < 0 && startY < yText && startY > yText + heightText))
539
558
  ) {
540
- ctx.zone = 'CENTER';
541
- console.log('on active center');
559
+ gestureContext.value.zone = 'CENTER';
542
560
  } else {
543
- ctx.zone = 'OUT';
544
- console.log('on active out');
561
+ gestureContext.value.zone = 'OUT';
545
562
  initialItem.value = null;
546
563
 
547
- ctx.newlyCreated = true;
564
+ gestureContext.value.newlyCreated = true;
548
565
  runOnJS(setTextVal)('');
549
566
  drawNewItem(
550
567
  mode,
@@ -571,19 +588,17 @@ const DrawCore = ({
571
588
  startY >= p.y - THRESHOLD
572
589
  )
573
590
  ) {
574
- ctx.zone = 'CENTER';
591
+ gestureContext.value.zone = 'CENTER';
575
592
  } else {
576
- ctx.zone = 'OUT';
593
+ gestureContext.value.zone = 'OUT';
577
594
  initialItem.value = null;
578
595
  }
579
596
  break;
580
597
  default:
581
- ctx.zone = 'OUT';
598
+ gestureContext.value.zone = 'OUT';
582
599
  initialItem.value = null;
583
600
  if (drawState.drawingMode === 'text') {
584
- /* NEW GEOFF */
585
- console.log('on active out');
586
- ctx.newlyCreated = true;
601
+ gestureContext.value.newlyCreated = true;
587
602
 
588
603
  runOnJS(setTextVal)('');
589
604
 
@@ -602,15 +617,12 @@ const DrawCore = ({
602
617
  }
603
618
  break;
604
619
  }
605
- },
606
- onActive: (
607
- { x: currentX, y: currentY, translationX, translationY },
608
- ctx
609
- ) => {
610
- const { startX, startY, zone, newlyCreated } = ctx;
620
+ })
621
+ .onUpdate((event) => {
622
+ const { x: currentX, y: currentY, translationX, translationY } = event;
623
+ const { startX, startY, zone, newlyCreated } = gestureContext.value;
611
624
  if (zone === 'OUT' && newlyCreated === false && mode.value !== 'text') {
612
- console.log('on active out');
613
- ctx.newlyCreated = true;
625
+ gestureContext.value.newlyCreated = true;
614
626
  /*
615
627
  if (mode.value === 'text') {
616
628
  runOnJS(setTextVal)('');
@@ -956,7 +968,6 @@ const DrawCore = ({
956
968
  }
957
969
  break;
958
970
  case 'text':
959
- console.log('on active text');
960
971
  if (initialItem.value?.type === currentItem.value.type) {
961
972
  const xText =
962
973
  typeof initialItem.value?.data.x === 'string'
@@ -1034,8 +1045,8 @@ const DrawCore = ({
1034
1045
  };
1035
1046
  }
1036
1047
  }
1037
- },
1038
- onEnd: (_event) => {
1048
+ })
1049
+ .onEnd(() => {
1039
1050
  if (currentItem.value?.type === 'doubleArrows') {
1040
1051
  runOnJS(textFocusState)();
1041
1052
  }
@@ -1054,8 +1065,7 @@ const DrawCore = ({
1054
1065
  };
1055
1066
  }
1056
1067
  runOnJS(addScreenStates)(currentItem.value);
1057
- },
1058
- });
1068
+ });
1059
1069
 
1060
1070
  useEffect(() => {
1061
1071
  const sudDidHide = Keyboard.addListener('keyboardDidHide', () => {
@@ -1064,7 +1074,6 @@ const DrawCore = ({
1064
1074
 
1065
1075
  const sudDidShow = Keyboard.addListener('keyboardDidShow', (event) => {
1066
1076
  // avoid events triggered by InputAccessoryView
1067
- console.log('keyboardDidShow dc');
1068
1077
  if (event.endCoordinates.height > 100) {
1069
1078
  showTextInput.value = true;
1070
1079
  }
@@ -1123,14 +1132,11 @@ const DrawCore = ({
1123
1132
 
1124
1133
  const onPressItem = useCallback(
1125
1134
  (item: DrawItem, index: number) => () => {
1126
- console.log('onPressItem');
1127
- itemIsSelected.value = true;
1128
-
1129
1135
  const previousItem = currentItem.value;
1130
1136
 
1137
+ itemIsSelected.value = true;
1131
1138
  strokeWidth.value = item.strokeWidth;
1132
1139
  color.value = item.color;
1133
- console.log('item', item);
1134
1140
  currentItem.value = item;
1135
1141
 
1136
1142
  deleteDoneItem(index);
@@ -1201,9 +1207,8 @@ const DrawCore = ({
1201
1207
 
1202
1208
  const calculateSizes = useCallback(
1203
1209
  (imageWidth: number, imageHeight: number) => {
1210
+ setOriginalImageSize({ width: imageWidth, height: imageHeight });
1204
1211
  if (drawRegion) {
1205
- setOriginalImageSize({ width: imageWidth, height: imageHeight });
1206
-
1207
1212
  const ratioImageHeight =
1208
1213
  Math.round(((imageHeight * drawRegion.width) / imageWidth) * 100) /
1209
1214
  100;
@@ -1244,36 +1249,21 @@ const DrawCore = ({
1244
1249
  // do not remove keyboard will appear over the drawing frame and not shift it
1245
1250
  useAnimatedKeyboard();
1246
1251
 
1247
- /*
1248
- const onEndEditingTextInput = useCallback(() => {
1249
- console.log('onEndEditingTextInput');
1250
- setShowTextInputState(false);
1251
- if (currentItem.value && currentItem.value.type === 'doubleArrows') {
1252
- console.log(currentItem.value.text);
1253
- addScreenStates(currentItem.value);
1252
+ const [newLayoutRequested, setNewLayoutRequested] = useState(false);
1253
+
1254
+ const onLayout = useCallback(async () => {
1255
+ if (newLayoutRequested) {
1256
+ setNewLayoutRequested(false);
1257
+ const uri = await captureSnapshot();
1258
+ if (uri && typeof actionWithSnapShotUri === 'function') {
1259
+ await actionWithSnapShotUri(uri);
1260
+ }
1254
1261
  }
1255
- }, [currentItem, addScreenStates]);
1262
+ }, [actionWithSnapShotUri, newLayoutRequested, captureSnapshot]);
1256
1263
 
1257
- const onChangeText = useCallback(
1258
- (value: string) => {
1259
- if (
1260
- value &&
1261
- currentItem.value &&
1262
- currentItem.value.type === 'doubleArrows'
1263
- ) {
1264
- console.log('******************');
1265
- console.log(value);
1266
- console.log(currentItem.value);
1264
+ const [ratioImage, setRatioImage] = useState<number>(1);
1265
+ const [opacity, setOpacity] = useState<number>(1);
1267
1266
 
1268
- currentItem.value = {
1269
- ...currentItem.value,
1270
- text: value,
1271
- };
1272
- }
1273
- },
1274
- [currentItem]
1275
- );
1276
- */
1277
1267
  return (
1278
1268
  <View style={styles.container}>
1279
1269
  <View
@@ -1289,8 +1279,11 @@ const DrawCore = ({
1289
1279
  }}
1290
1280
  >
1291
1281
  <KeyboardAvoidingView behavior="position" keyboardVerticalOffset={70}>
1292
- <PanGestureHandler onGestureEvent={onGestureEvent}>
1293
- <Animated.View style={imageSize || drawRegion}>
1282
+ <GestureDetector gesture={panGesture}>
1283
+ <Animated.View
1284
+ style={{ ...(imageSize || drawRegion), opacity: opacity }}
1285
+ onLayout={onLayout}
1286
+ >
1294
1287
  <View ref={drawContainer}>
1295
1288
  {image ? (
1296
1289
  imageSize && originalImageSize ? (
@@ -1308,6 +1301,7 @@ const DrawCore = ({
1308
1301
  doneItems={drawState.doneItems}
1309
1302
  onPressItem={onPressItem}
1310
1303
  onTextHeightChange={onTextHeightChange}
1304
+ ratioImage={ratioImage}
1311
1305
  />
1312
1306
  </ImageBackground>
1313
1307
  </ViewShot>
@@ -1318,9 +1312,9 @@ const DrawCore = ({
1318
1312
  options={{
1319
1313
  format: 'jpg',
1320
1314
  quality: 1,
1321
- ...drawRegion,
1315
+ ...(imageSize || drawRegion),
1322
1316
  }}
1323
- style={drawRegion}
1317
+ style={imageSize || drawRegion}
1324
1318
  >
1325
1319
  <DrawPad
1326
1320
  addBackground
@@ -1328,12 +1322,13 @@ const DrawCore = ({
1328
1322
  doneItems={drawState.doneItems}
1329
1323
  onPressItem={onPressItem}
1330
1324
  onTextHeightChange={onTextHeightChange}
1325
+ ratioImage={ratioImage}
1331
1326
  />
1332
1327
  </ViewShot>
1333
1328
  ) : null}
1334
1329
  </View>
1335
1330
  </Animated.View>
1336
- </PanGestureHandler>
1331
+ </GestureDetector>
1337
1332
 
1338
1333
  <TextInput
1339
1334
  ref={textInputRef}
@@ -11,15 +11,17 @@ const useDrawHook = () => {
11
11
  itemIsSelected,
12
12
  viewShot,
13
13
  doubleArrowTextInput,
14
+ doSnapshot,
15
+ snapShotRequested,
16
+ setSnapShotRequested,
14
17
  } = useContext(DrawContext);
15
18
 
16
- const takeSnapshot = useCallback(async () => {
17
- if (currentItem?.value) {
18
- dispatchDrawStates({ type: 'ADD_DONE_ITEM', item: currentItem.value });
19
- currentItem.value = null;
19
+ const captureSnapshot = useCallback(async () => {
20
+ if (viewShot) {
21
+ return await viewShot.current?.capture?.();
20
22
  }
21
- return viewShot!.current?.capture?.();
22
- }, [currentItem, dispatchDrawStates, viewShot]);
23
+ return null;
24
+ }, [viewShot]);
23
25
 
24
26
  const cancelLastAction = useCallback(() => {
25
27
  itemIsSelected!.value = false;
@@ -62,10 +64,13 @@ const useDrawHook = () => {
62
64
  onColorStrokeChange,
63
65
  itemIsSelected: itemIsSelected!,
64
66
  cancelLastAction,
65
- takeSnapshot: takeSnapshot!,
67
+ captureSnapshot: captureSnapshot!,
66
68
  viewShot: viewShot!,
67
69
  deleteSelectedItem,
68
70
  doubleArrowTextInput,
71
+ snapShotRequested,
72
+ doSnapshot,
73
+ setSnapShotRequested,
69
74
  };
70
75
  };
71
76
 
@@ -1,4 +1,4 @@
1
- import React, { useCallback, useEffect, useState } from 'react';
1
+ import React, { useEffect, useState } from 'react';
2
2
  import {
3
3
  Pressable,
4
4
  View,
@@ -76,7 +76,7 @@ type DrawWithOptionsProps = {
76
76
  linearGradient: React.ComponentType<{ colors: any[] } & ViewProps>;
77
77
  image?: ImageRequireSource | ImageURISource;
78
78
  close?: () => void;
79
- takeSnapshot?: (snap: Promise<string | undefined>) => void;
79
+ actionWithSnapShotUri?: (uri: string) => Promise<void>;
80
80
  backgroundColor?: string;
81
81
  };
82
82
 
@@ -84,16 +84,16 @@ function DrawWithOptionsCore({
84
84
  linearGradient,
85
85
  image,
86
86
  close,
87
- takeSnapshot,
88
87
  backgroundColor,
88
+ actionWithSnapShotUri,
89
89
  }: DrawWithOptionsProps) {
90
90
  const {
91
91
  itemIsSelected,
92
92
  cancelLastAction,
93
- takeSnapshot: takeSnapshotAction,
94
93
  deleteSelectedItem,
95
94
  dispatchDrawStates,
96
95
  drawState,
96
+ doSnapshot,
97
97
  } = useDrawHook();
98
98
 
99
99
  const [showToolbar, setShowToolbar] = useState(true);
@@ -121,11 +121,6 @@ function DrawWithOptionsCore({
121
121
  };
122
122
  }, []);
123
123
 
124
- const takeSnapshotAndGetUri = useCallback(async () => {
125
- if (takeSnapshot) {
126
- takeSnapshot(takeSnapshotAction());
127
- }
128
- }, [takeSnapshot, takeSnapshotAction]);
129
124
  return (
130
125
  <View style={styles.container}>
131
126
  <View style={styles.toolbar}>
@@ -266,7 +261,7 @@ function DrawWithOptionsCore({
266
261
  </View>
267
262
 
268
263
  <View style={styles.actionButton}>
269
- <Pressable onPress={takeSnapshotAndGetUri}>
264
+ <Pressable onPress={doSnapshot}>
270
265
  <SendSvg height={20} width={20} fill="#ffffff" />
271
266
  </Pressable>
272
267
  </View>
@@ -277,7 +272,11 @@ function DrawWithOptionsCore({
277
272
  flex: 1,
278
273
  }}
279
274
  >
280
- <DrawCore image={image} backgroundColor={backgroundColor} />
275
+ <DrawCore
276
+ image={image}
277
+ backgroundColor={backgroundColor}
278
+ actionWithSnapShotUri={actionWithSnapShotUri}
279
+ />
281
280
  </View>
282
281
 
283
282
  <Sliders linearGradient={linearGradient} />
package/src/types.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- import React from 'react';
2
- import { View } from 'react-native';
3
1
  import {
4
2
  ForeignObjectProps,
5
3
  EllipseProps,
@@ -33,12 +31,16 @@ export type DrawItem = (
33
31
 
34
32
  export type DrawItemType = DrawItem['type'];
35
33
 
34
+ export type DrawCoreProps = {
35
+ takeSnapshotAction: () => void;
36
+ };
37
+ /*
36
38
  export type DrawCoreProps = {
37
39
  drawingContainer: React.Ref<View>;
38
40
  deleteSelectedItem: () => void;
39
41
  cancelLastAction: () => void;
40
42
  takeSnapshot: () => Promise<string | undefined>;
41
- };
43
+ };*/
42
44
 
43
45
  export type DrawState = {
44
46
  doneItems: DrawItem[];