@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
@@ -2,8 +2,8 @@ import React, { useState } from 'react';
2
2
  import { StyleSheet, View } from 'react-native';
3
3
  import Animated, {
4
4
  runOnJS,
5
+ useAnimatedReaction,
5
6
  useAnimatedStyle,
6
- useDerivedValue,
7
7
  } from 'react-native-reanimated';
8
8
  import type { DrawItem } from '../../types';
9
9
  import { hslToRgb } from './CurrentAnimatedItem';
@@ -49,15 +49,18 @@ export default function CurrentAnimatedText({
49
49
  currentItem: Animated.SharedValue<DrawItem | null>;
50
50
  onHeightChange: (height: number) => void;
51
51
  }) {
52
- const [text, setText] = useState(
53
- currentItem.value?.type === 'text' ? currentItem.value.text || '' : ''
54
- );
52
+ const [text, setText] = useState('');
55
53
 
56
- useDerivedValue(() => {
57
- runOnJS(setText)(
58
- currentItem.value?.type === 'text' ? currentItem.value.text || '' : ''
59
- );
60
- }, [currentItem.value]);
54
+ useAnimatedReaction(
55
+ () => {
56
+ return currentItem.value?.type === 'text'
57
+ ? currentItem.value.text || ''
58
+ : '';
59
+ },
60
+ (value) => {
61
+ runOnJS(setText)(value);
62
+ }
63
+ );
61
64
 
62
65
  const textAnimatedStyle = useAnimatedStyle(() => {
63
66
  return {
@@ -66,7 +69,7 @@ export default function CurrentAnimatedText({
66
69
  ? hslToRgb(currentItem.value?.color)
67
70
  : 'white',
68
71
  };
69
- }, [currentItem.value?.strokeWidth]);
72
+ });
70
73
 
71
74
  const containerStyle = useAnimatedStyle(() => {
72
75
  return {
@@ -104,7 +107,7 @@ export default function CurrentAnimatedText({
104
107
  },
105
108
  ],
106
109
  };
107
- }, [currentItem.value]);
110
+ });
108
111
 
109
112
  return (
110
113
  <Animated.View style={containerStyle}>
@@ -1,7 +1,9 @@
1
1
  import React from 'react';
2
2
  import type Animated from 'react-native-reanimated';
3
3
  import Svg, { Circle, Defs, G, Marker, Polyline, Use } from 'react-native-svg';
4
- import CurrentAnimatedItem from './CurrentAnimatedItem';
4
+ import CurrentAnimatedItem, {
5
+ DoubleArrowsTextInput,
6
+ } from './CurrentAnimatedItem';
5
7
  import CurrentAnimatedText from './CurrentAnimatedText';
6
8
  import Item from './Item';
7
9
  import type { DrawItem } from '../../types';
@@ -107,6 +109,7 @@ const DrawPad = ({
107
109
  currentItem={currentItem}
108
110
  onHeightChange={onTextHeightChange}
109
111
  />
112
+ <DoubleArrowsTextInput />
110
113
  </>
111
114
  );
112
115
  };
@@ -107,7 +107,7 @@ type Context = {
107
107
  | 'OUT';
108
108
  };
109
109
 
110
- const drawNewItem = (
110
+ function drawNewItem(
111
111
  mode: Animated.SharedValue<DrawItemType>,
112
112
  currentItem: Animated.SharedValue<DrawItem | null>,
113
113
  addDoneItem: (item: DrawItem) => void,
@@ -117,7 +117,7 @@ const drawNewItem = (
117
117
  strokeWidth: Animated.SharedValue<number>;
118
118
  color: Animated.SharedValue<hslColor>;
119
119
  }
120
- ) => {
120
+ ) {
121
121
  'worklet';
122
122
  if (currentItem.value) {
123
123
  runOnJS(addDoneItem)(currentItem.value);
@@ -195,13 +195,13 @@ const drawNewItem = (
195
195
  };
196
196
  break;
197
197
  }
198
- };
198
+ }
199
199
 
200
- const onTextHeightUpdate = (
200
+ function onTextHeightUpdate(
201
201
  currentItem: Animated.SharedValue<DrawItem | null>,
202
202
  textBaseHeight: Animated.SharedValue<number | null>,
203
203
  height: number
204
- ) => {
204
+ ) {
205
205
  'worklet';
206
206
  if (currentItem.value?.type === 'text') {
207
207
  textBaseHeight.value = textBaseHeight.value || height;
@@ -217,7 +217,7 @@ const onTextHeightUpdate = (
217
217
  text: currentItem.value.text,
218
218
  };
219
219
  }
220
- };
220
+ }
221
221
 
222
222
  const DrawCore = ({
223
223
  image,
@@ -593,15 +593,27 @@ const DrawCore = ({
593
593
 
594
594
  break;
595
595
  case 'pen':
596
- if (
597
- currentItem.value.data.some(
598
- (p) =>
599
- startX <= p.x + THRESHOLD &&
600
- startX >= p.x - THRESHOLD &&
601
- startY <= p.y + THRESHOLD &&
602
- startY >= p.y - THRESHOLD
603
- )
596
+ let isPointSelected = false;
597
+ for (
598
+ let index = 0;
599
+ index < currentItem.value.data.length;
600
+ index += 1
604
601
  ) {
602
+ const point = currentItem.value.data[index];
603
+
604
+ if (
605
+ point &&
606
+ startX <= point.x + THRESHOLD &&
607
+ startX >= point.x - THRESHOLD &&
608
+ startY <= point.y + THRESHOLD &&
609
+ startY >= point.y - THRESHOLD
610
+ ) {
611
+ isPointSelected = true;
612
+ break;
613
+ }
614
+ }
615
+
616
+ if (isPointSelected) {
605
617
  gestureContext.value.zone = 'CENTER';
606
618
  } else {
607
619
  gestureContext.value.zone = 'OUT';
@@ -611,7 +623,7 @@ const DrawCore = ({
611
623
  default:
612
624
  gestureContext.value.zone = 'OUT';
613
625
  initialItem.value = null;
614
- if (drawState.drawingMode === 'text') {
626
+ if (mode.value === 'text') {
615
627
  gestureContext.value.newlyCreated = true;
616
628
 
617
629
  runOnJS(setTextVal)('');
@@ -658,14 +670,30 @@ const DrawCore = ({
658
670
  initialItem.value?.type === currentItem.value.type &&
659
671
  zone === 'CENTER'
660
672
  ) {
673
+ const translatedData = [];
674
+
675
+ for (
676
+ let index = 0;
677
+ index < initialItem.value.data.length;
678
+ index += 1
679
+ ) {
680
+ const point = initialItem.value.data[index];
681
+
682
+ if (!point) {
683
+ continue;
684
+ }
685
+
686
+ translatedData.push({
687
+ x: point.x + translationX,
688
+ y: point.y + translationY,
689
+ });
690
+ }
691
+
661
692
  currentItem.value = {
662
693
  type: 'pen',
663
694
  strokeWidth: currentItem.value.strokeWidth,
664
695
  color: currentItem.value.color,
665
- data: initialItem.value.data.map((p) => ({
666
- x: p.x + translationX,
667
- y: p.y + translationY,
668
- })),
696
+ data: translatedData,
669
697
  };
670
698
  } else {
671
699
  currentItem.value = {
@@ -1081,6 +1109,30 @@ const DrawCore = ({
1081
1109
  runOnJS(addScreenStates)(currentItem.value);
1082
1110
  });
1083
1111
 
1112
+ const tapGesture = Gesture.Tap()
1113
+ .onStart((event) => {
1114
+ if (mode.value === 'text') {
1115
+ const { x: startX, y: startY } = event;
1116
+
1117
+ runOnJS(setTextVal)('');
1118
+
1119
+ drawNewItem(
1120
+ mode,
1121
+ currentItem,
1122
+ addDoneItem,
1123
+ { x: startX, y: startY },
1124
+ { textBaseHeight, strokeWidth, color }
1125
+ );
1126
+
1127
+ itemIsSelected!.value = true;
1128
+ onCancelChangeWrapper && runOnJS(onCancelChangeWrapper)(true);
1129
+
1130
+ runOnJS(textFocus)();
1131
+ }
1132
+ });
1133
+
1134
+ const composedGesture = Gesture.Race(tapGesture, panGesture);
1135
+
1084
1136
  useEffect(() => {
1085
1137
  const sudDidHide = Keyboard.addListener('keyboardDidHide', () => {
1086
1138
  showTextInput.value = false;
@@ -1140,8 +1192,7 @@ const DrawCore = ({
1140
1192
  };
1141
1193
  break;
1142
1194
  }
1143
- },
1144
- [strokeWidth.value, color?.value]
1195
+ }
1145
1196
  );
1146
1197
 
1147
1198
  const onPressItem = useCallback(
@@ -1163,8 +1214,10 @@ const DrawCore = ({
1163
1214
  setTextVal(item.text ?? '');
1164
1215
  textInputRef.current?.focus();
1165
1216
  } else if (item.type === 'doubleArrows') {
1166
- //setTextVal(item.text ?? '');
1167
- //textInputRef.current?.focus();
1217
+ doubleArrowTextInput?.current?.setNativeProps({
1218
+ text: item.text ?? '',
1219
+ });
1220
+ doubleArrowTextInput?.current?.focus();
1168
1221
  } else {
1169
1222
  textInputRef.current?.blur();
1170
1223
  }
@@ -1267,7 +1320,6 @@ const DrawCore = ({
1267
1320
 
1268
1321
  const onLayout = useCallback(async () => {
1269
1322
  if (newLayoutRequested) {
1270
-
1271
1323
  const uri = await captureSnapshot();
1272
1324
  if (uri && typeof actionWithSnapShotUri === 'function') {
1273
1325
  await actionWithSnapShotUri(uri);
@@ -1294,7 +1346,7 @@ const DrawCore = ({
1294
1346
  }}
1295
1347
  >
1296
1348
  <KeyboardAvoidingView behavior="position" keyboardVerticalOffset={70}>
1297
- <GestureDetector gesture={panGesture}>
1349
+ <GestureDetector gesture={composedGesture}>
1298
1350
  <Animated.View
1299
1351
  style={{ ...(imageSize || drawRegion), opacity: opacity }}
1300
1352
  onLayout={onLayout}
@@ -50,14 +50,13 @@ const useDrawHook = () => {
50
50
  }, [currentItem, dispatchDrawStates, itemIsSelected]);
51
51
 
52
52
  const onColorStrokeChange = useCallback(() => {
53
- 'worklet';
54
53
  if (currentItem?.value) {
55
54
  dispatchDrawStates({
56
55
  type: 'ADD_SCREEN_STATE',
57
56
  currentItem: currentItem.value,
58
57
  });
59
58
  }
60
- }, [currentItem?.value, dispatchDrawStates]);
59
+ }, [currentItem, dispatchDrawStates]);
61
60
 
62
61
  return {
63
62
  drawState: drawState!,
@@ -3,11 +3,11 @@ import {
3
3
  Pressable,
4
4
  View,
5
5
  StyleSheet,
6
- ViewProps,
7
6
  ImageRequireSource,
8
7
  ImageURISource,
9
8
  Keyboard,
10
9
  } from 'react-native';
10
+ import { useAnimatedReaction, runOnJS } from 'react-native-reanimated';
11
11
  import DoubleHeadSvg from './DoubleHeadSvg';
12
12
  import CircleSvg from './CircleSvg';
13
13
  import SquareSvg from './SquareSvg';
@@ -22,6 +22,7 @@ import ThrashSvg from './ThrashSvg';
22
22
  import CancelSvg from './CancelSvg';
23
23
  import SendSvg from './SendSvg';
24
24
  import DrawProvider from '../DrawCore/DrawProvider';
25
+ import type { LinearGradientComponentProps } from '../../types';
25
26
 
26
27
  const styles = StyleSheet.create({
27
28
  container: { flex: 1 },
@@ -73,7 +74,7 @@ const styles = StyleSheet.create({
73
74
  });
74
75
 
75
76
  type DrawWithOptionsProps = {
76
- linearGradient: React.ComponentType<{ colors: any[] } & ViewProps>;
77
+ linearGradient: React.ComponentType<LinearGradientComponentProps>;
77
78
  image?: ImageRequireSource | ImageURISource;
78
79
  close?: () => void;
79
80
  actionWithSnapShotUri?: (uri: string) => Promise<void>;
@@ -97,6 +98,14 @@ function DrawWithOptionsCore({
97
98
  } = useDrawHook();
98
99
 
99
100
  const [showToolbar, setShowToolbar] = useState(true);
101
+ const [isSelected, setIsSelected] = useState(false);
102
+
103
+ useAnimatedReaction(
104
+ () => itemIsSelected.value,
105
+ (value) => {
106
+ runOnJS(setIsSelected)(value);
107
+ }
108
+ );
100
109
 
101
110
  useEffect(() => {
102
111
  const sudDidHide = Keyboard.addListener('keyboardDidHide', () => {
@@ -106,7 +115,6 @@ function DrawWithOptionsCore({
106
115
  const sudDidShow = Keyboard.addListener(
107
116
  'keyboardDidShow',
108
117
  (event: { endCoordinates: { height: number } }) => {
109
- console.log('keyboardDidShow dwo');
110
118
  // avoid events triggered by InputAccessoryView
111
119
  if (event.endCoordinates.height > 100) {
112
120
  setShowToolbar(false);
@@ -284,7 +292,7 @@ function DrawWithOptionsCore({
284
292
  <View style={{ height: 70 }}>
285
293
  {showToolbar ? (
286
294
  <View style={styles.bottomToolBar}>
287
- {itemIsSelected.value ? (
295
+ {isSelected ? (
288
296
  <View style={{ ...styles.actionButton, marginRight: 10 }}>
289
297
  <Pressable style={styles.option} onPress={deleteSelectedItem}>
290
298
  <ThrashSvg
@@ -1,19 +1,15 @@
1
1
  import { sliderStyle, TRACK_R } from './sliderStyle';
2
2
  import React, { useCallback } from 'react';
3
- import { LayoutChangeEvent, View, ViewProps } from 'react-native';
3
+ import { LayoutChangeEvent, View } from 'react-native';
4
4
 
5
- import {
6
- PanGestureHandler,
7
- PanGestureHandlerGestureEvent,
8
- } from 'react-native-gesture-handler';
5
+ import { Gesture, GestureDetector } from 'react-native-gesture-handler';
9
6
  import Animated, {
10
7
  runOnJS,
11
- useAnimatedGestureHandler,
12
8
  useAnimatedStyle,
13
9
  useDerivedValue,
14
10
  useSharedValue,
15
11
  } from 'react-native-reanimated';
16
- import type { LinearGradientType } from '../../types';
12
+ import type { LinearGradientComponentProps } from '../../types';
17
13
  import useDrawHook from '../DrawCore/useDrawHook';
18
14
 
19
15
  const gradientColors = [
@@ -36,10 +32,11 @@ const gradientEnd = { x: 1, y: 0 };
36
32
  const ColorSlider = ({
37
33
  linearGradient: LinearGradient,
38
34
  }: {
39
- linearGradient: React.ComponentType<LinearGradientType & ViewProps>;
35
+ linearGradient: React.ComponentType<LinearGradientComponentProps>;
40
36
  }) => {
41
37
  const { onColorStrokeChange, color } = useDrawHook();
42
38
  const sliderWidth = useSharedValue(0);
39
+ const gestureStartX = useSharedValue(0);
43
40
 
44
41
  const position = useDerivedValue(() => {
45
42
  const hslRegExp = new RegExp(/hsl\(([\d.]+),\s*(\d+)%,\s*([\d.]+)%\)/);
@@ -65,56 +62,51 @@ const ColorSlider = ({
65
62
  tint * ((sliderWidth.value - sliderWidth.value * 0.2) / 360)
66
63
  )
67
64
  );
68
- }, [sliderWidth.value]);
65
+ });
69
66
 
70
67
  const wrapperOnColorChange = () => {
71
68
  onColorStrokeChange();
72
69
  };
73
70
 
74
- const onGestureEvent = useAnimatedGestureHandler<
75
- PanGestureHandlerGestureEvent,
76
- { startX: number }
77
- >(
78
- {
79
- onStart: ({ x }, ctx) => {
80
- ctx.startX = x;
81
- },
82
- onActive: ({ translationX }, { startX }) => {
83
- const slidePos = Math.min(sliderWidth.value, startX + translationX);
84
-
85
- if (slidePos < 0.1 * sliderWidth.value) {
86
- color!.value = `hsl(0, 100%, ${Math.min(
87
- 100,
88
- 100 - (slidePos / (0.1 * sliderWidth.value)) * 50
89
- ).toFixed(10)}%)`;
90
- } else if (slidePos > 0.9 * sliderWidth.value) {
91
- color!.value = `hsl(0, 100%, ${Math.max(
92
- 50 -
93
- ((slidePos - 0.9 * sliderWidth.value) /
94
- (0.1 * sliderWidth.value)) *
95
- 50,
96
- 0
97
- ).toFixed(10)}%)`;
98
- } else {
99
- color!.value = `hsl(${
100
- ((slidePos - sliderWidth.value * 0.1) /
101
- (sliderWidth.value - sliderWidth.value * 0.2)) *
102
- 360
103
- }, 100%, 50%)`;
104
- }
105
- },
106
- onEnd: () => {
107
- runOnJS(wrapperOnColorChange)();
108
- },
109
- },
110
- []
111
- );
71
+ const panGesture = Gesture.Pan()
72
+ .onStart((event) => {
73
+ gestureStartX.value = event.x;
74
+ })
75
+ .onUpdate((event) => {
76
+ const slidePos = Math.min(
77
+ sliderWidth.value,
78
+ gestureStartX.value + event.translationX
79
+ );
80
+
81
+ if (slidePos < 0.1 * sliderWidth.value) {
82
+ color!.value = `hsl(0, 100%, ${Math.min(
83
+ 100,
84
+ 100 - (slidePos / (0.1 * sliderWidth.value)) * 50
85
+ ).toFixed(10)}%)`;
86
+ } else if (slidePos > 0.9 * sliderWidth.value) {
87
+ color!.value = `hsl(0, 100%, ${Math.max(
88
+ 50 -
89
+ ((slidePos - 0.9 * sliderWidth.value) / (0.1 * sliderWidth.value)) *
90
+ 50,
91
+ 0
92
+ ).toFixed(10)}%)`;
93
+ } else {
94
+ color!.value = `hsl(${
95
+ ((slidePos - sliderWidth.value * 0.1) /
96
+ (sliderWidth.value - sliderWidth.value * 0.2)) *
97
+ 360
98
+ }, 100%, 50%)`;
99
+ }
100
+ })
101
+ .onEnd(() => {
102
+ runOnJS(wrapperOnColorChange)();
103
+ });
112
104
 
113
105
  const style = useAnimatedStyle(() => {
114
106
  return {
115
107
  transform: [{ translateX: position.value - TRACK_R }],
116
108
  };
117
- }, [position.value]);
109
+ });
118
110
 
119
111
  const onLayout = useCallback(
120
112
  (event: LayoutChangeEvent) => {
@@ -125,7 +117,7 @@ const ColorSlider = ({
125
117
 
126
118
  return (
127
119
  <View style={sliderStyle.container}>
128
- <PanGestureHandler onGestureEvent={onGestureEvent}>
120
+ <GestureDetector gesture={panGesture}>
129
121
  <Animated.View style={sliderStyle.container}>
130
122
  <LinearGradient
131
123
  start={gradientStart}
@@ -136,7 +128,7 @@ const ColorSlider = ({
136
128
  />
137
129
  <Animated.View style={[sliderStyle.thumb, style]} />
138
130
  </Animated.View>
139
- </PanGestureHandler>
131
+ </GestureDetector>
140
132
  </View>
141
133
  );
142
134
  };
@@ -1,9 +1,9 @@
1
1
  import React from 'react';
2
- import { View, ViewProps } from 'react-native';
2
+ import { View } from 'react-native';
3
3
  import Animated, { useAnimatedStyle } from 'react-native-reanimated';
4
4
  import StrokeSlider from './StrokeSlider';
5
5
  import ColorSlider from './ColorSlider';
6
- import type { LinearGradientType } from '../../types';
6
+ import type { LinearGradientComponentProps } from '../../types';
7
7
  import useDrawHook from '../DrawCore/useDrawHook';
8
8
  import { StyleSheet } from 'react-native';
9
9
 
@@ -46,7 +46,7 @@ const styles = StyleSheet.create({
46
46
  const Sliders = ({
47
47
  linearGradient,
48
48
  }: {
49
- linearGradient: React.ComponentType<LinearGradientType & ViewProps>;
49
+ linearGradient: React.ComponentType<LinearGradientComponentProps>;
50
50
  }) => {
51
51
  const { strokeWidth, color } = useDrawHook();
52
52
 
@@ -55,7 +55,7 @@ const Sliders = ({
55
55
  borderWidth: strokeWidth!.value,
56
56
  borderColor: color!.value,
57
57
  };
58
- }, [strokeWidth, color]);
58
+ });
59
59
 
60
60
  return (
61
61
  <View style={styles.strokeContainer}>
@@ -1,11 +1,7 @@
1
1
  import React from 'react';
2
- import {
3
- PanGestureHandler,
4
- PanGestureHandlerGestureEvent,
5
- } from 'react-native-gesture-handler';
2
+ import { Gesture, GestureDetector } from 'react-native-gesture-handler';
6
3
  import Animated, {
7
4
  runOnJS,
8
- useAnimatedGestureHandler,
9
5
  useAnimatedStyle,
10
6
  useDerivedValue,
11
7
  useSharedValue,
@@ -37,6 +33,7 @@ const StrokeSlider = ({
37
33
  const { onColorStrokeChange, strokeWidth } = useDrawHook();
38
34
 
39
35
  const sliderWidth = useSharedValue(0);
36
+ const gestureStartX = useSharedValue(0);
40
37
 
41
38
  const position = useDerivedValue(() => {
42
39
  return (
@@ -47,41 +44,35 @@ const StrokeSlider = ({
47
44
  const wrapperOnColorStrokeChange = () => {
48
45
  onColorStrokeChange();
49
46
  };
50
- const onGestureEvent = useAnimatedGestureHandler<
51
- PanGestureHandlerGestureEvent,
52
- { startX: number }
53
- >(
54
- {
55
- onStart: ({ x }, ctx) => {
56
- ctx.startX = x;
57
- },
58
- onActive: ({ translationX }, { startX }) => {
59
- strokeWidth!.value = Math.min(
60
- maxValue,
61
- Math.max(
62
- minValue,
63
- ((startX + translationX) / sliderWidth.value) *
64
- (maxValue - minValue) +
65
- minValue
66
- )
67
- );
68
- },
69
- onEnd: () => {
70
- runOnJS(wrapperOnColorStrokeChange)();
71
- },
72
- },
73
- []
74
- );
47
+
48
+ const panGesture = Gesture.Pan()
49
+ .onStart((event) => {
50
+ gestureStartX.value = event.x;
51
+ })
52
+ .onUpdate((event) => {
53
+ strokeWidth!.value = Math.min(
54
+ maxValue,
55
+ Math.max(
56
+ minValue,
57
+ ((gestureStartX.value + event.translationX) / sliderWidth.value) *
58
+ (maxValue - minValue) +
59
+ minValue
60
+ )
61
+ );
62
+ })
63
+ .onEnd(() => {
64
+ runOnJS(wrapperOnColorStrokeChange)();
65
+ });
75
66
 
76
67
  const style = useAnimatedStyle(() => {
77
68
  return {
78
69
  transform: [{ translateX: position.value - TRACK_R }],
79
70
  };
80
- }, [position.value]);
71
+ });
81
72
 
82
73
  return (
83
74
  <View style={sliderStyle.container}>
84
- <PanGestureHandler onGestureEvent={onGestureEvent}>
75
+ <GestureDetector gesture={panGesture}>
85
76
  <Animated.View style={sliderStyle.container}>
86
77
  <View
87
78
  onLayout={(event) => {
@@ -97,7 +88,7 @@ const StrokeSlider = ({
97
88
  </View>
98
89
  <Animated.View style={[sliderStyle.thumb, style]} />
99
90
  </Animated.View>
100
- </PanGestureHandler>
91
+ </GestureDetector>
101
92
  </View>
102
93
  );
103
94
  };
package/src/types.d.ts CHANGED
@@ -55,6 +55,11 @@ export type LinearGradientType = {
55
55
  end?: { x: number; y: number };
56
56
  };
57
57
 
58
+ export type LinearGradientComponentProps = LinearGradientType & {
59
+ style?: any;
60
+ onLayout?: (...args: any[]) => void;
61
+ };
62
+
58
63
  export type Action =
59
64
  | { type: 'ADD_DONE_ITEM'; item: DrawItem }
60
65
  | { type: 'DELETE_DONE_ITEM'; indice: number }