@archireport/react-native-svg-draw 1.3.0 → 2.0.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.
- package/README.md +73 -27
- package/lib/commonjs/components/DrawCore/CurrentAnimatedItem.js +55 -54
- package/lib/commonjs/components/DrawCore/CurrentAnimatedItem.js.map +1 -1
- package/lib/commonjs/components/DrawCore/CurrentAnimatedText.js +3 -14
- package/lib/commonjs/components/DrawCore/CurrentAnimatedText.js.map +1 -1
- package/lib/commonjs/components/DrawCore/DrawContext.js +18 -0
- package/lib/commonjs/components/DrawCore/DrawContext.js.map +1 -0
- package/lib/commonjs/components/DrawCore/DrawPad.js +1 -13
- package/lib/commonjs/components/DrawCore/DrawPad.js.map +1 -1
- package/lib/commonjs/components/DrawCore/DrawProvider.js +103 -0
- package/lib/commonjs/components/DrawCore/DrawProvider.js.map +1 -0
- package/lib/commonjs/components/DrawCore/Item.js +0 -15
- package/lib/commonjs/components/DrawCore/Item.js.map +1 -1
- package/lib/commonjs/components/DrawCore/index.js +47 -287
- package/lib/commonjs/components/DrawCore/index.js.map +1 -1
- package/lib/commonjs/components/DrawCore/useDrawHook.js +76 -0
- package/lib/commonjs/components/DrawCore/useDrawHook.js.map +1 -0
- package/lib/commonjs/components/DrawWithOptions/ArrowSvg.js +0 -6
- package/lib/commonjs/components/DrawWithOptions/ArrowSvg.js.map +1 -1
- package/lib/commonjs/components/DrawWithOptions/CancelSvg.js +0 -6
- package/lib/commonjs/components/DrawWithOptions/CancelSvg.js.map +1 -1
- package/lib/commonjs/components/DrawWithOptions/CircleSvg.js +0 -6
- package/lib/commonjs/components/DrawWithOptions/CircleSvg.js.map +1 -1
- package/lib/commonjs/components/DrawWithOptions/CloseSvg.js +0 -6
- package/lib/commonjs/components/DrawWithOptions/CloseSvg.js.map +1 -1
- package/lib/commonjs/components/DrawWithOptions/DoubleHeadSvg.js +0 -7
- package/lib/commonjs/components/DrawWithOptions/DoubleHeadSvg.js.map +1 -1
- package/lib/commonjs/components/DrawWithOptions/PenSvg.js +0 -6
- package/lib/commonjs/components/DrawWithOptions/PenSvg.js.map +1 -1
- package/lib/commonjs/components/DrawWithOptions/SendSvg.js +0 -7
- package/lib/commonjs/components/DrawWithOptions/SendSvg.js.map +1 -1
- package/lib/commonjs/components/DrawWithOptions/SliderSvg.js +31 -0
- package/lib/commonjs/components/DrawWithOptions/SliderSvg.js.map +1 -0
- package/lib/commonjs/components/DrawWithOptions/SquareSvg.js +0 -7
- package/lib/commonjs/components/DrawWithOptions/SquareSvg.js.map +1 -1
- package/lib/commonjs/components/DrawWithOptions/TextSvg.js +0 -7
- package/lib/commonjs/components/DrawWithOptions/TextSvg.js.map +1 -1
- package/lib/commonjs/components/DrawWithOptions/ThrashSvg.js +27 -10
- package/lib/commonjs/components/DrawWithOptions/ThrashSvg.js.map +1 -1
- package/lib/commonjs/components/DrawWithOptions/index.js +126 -93
- package/lib/commonjs/components/DrawWithOptions/index.js.map +1 -1
- package/lib/commonjs/components/{DrawCore → Slider}/ColorSlider.js +47 -78
- package/lib/commonjs/components/Slider/ColorSlider.js.map +1 -0
- package/lib/commonjs/components/Slider/Sliders.js +88 -0
- package/lib/commonjs/components/Slider/Sliders.js.map +1 -0
- package/lib/commonjs/components/{DrawCore → Slider}/StrokeSlider.js +38 -57
- package/lib/commonjs/components/Slider/StrokeSlider.js.map +1 -0
- package/lib/commonjs/components/Slider/sliderStyle.js +37 -0
- package/lib/commonjs/components/Slider/sliderStyle.js.map +1 -0
- package/lib/commonjs/index.js +7 -3
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types.d.js.map +1 -1
- package/lib/module/components/DrawCore/CurrentAnimatedItem.js +56 -43
- package/lib/module/components/DrawCore/CurrentAnimatedItem.js.map +1 -1
- package/lib/module/components/DrawCore/CurrentAnimatedText.js +3 -7
- package/lib/module/components/DrawCore/CurrentAnimatedText.js.map +1 -1
- package/lib/module/components/DrawCore/DrawContext.js +11 -0
- package/lib/module/components/DrawCore/DrawContext.js.map +1 -0
- package/lib/module/components/DrawCore/DrawPad.js +1 -5
- package/lib/module/components/DrawCore/DrawPad.js.map +1 -1
- package/lib/module/components/DrawCore/DrawProvider.js +94 -0
- package/lib/module/components/DrawCore/DrawProvider.js.map +1 -0
- package/lib/module/components/DrawCore/Item.js +0 -8
- package/lib/module/components/DrawCore/Item.js.map +1 -1
- package/lib/module/components/DrawCore/index.js +49 -271
- package/lib/module/components/DrawCore/index.js.map +1 -1
- package/lib/module/components/DrawCore/useDrawHook.js +69 -0
- package/lib/module/components/DrawCore/useDrawHook.js.map +1 -0
- package/lib/module/components/DrawWithOptions/ArrowSvg.js +0 -1
- package/lib/module/components/DrawWithOptions/ArrowSvg.js.map +1 -1
- package/lib/module/components/DrawWithOptions/CancelSvg.js +0 -1
- package/lib/module/components/DrawWithOptions/CancelSvg.js.map +1 -1
- package/lib/module/components/DrawWithOptions/CircleSvg.js +0 -1
- package/lib/module/components/DrawWithOptions/CircleSvg.js.map +1 -1
- package/lib/module/components/DrawWithOptions/CloseSvg.js +0 -1
- package/lib/module/components/DrawWithOptions/CloseSvg.js.map +1 -1
- package/lib/module/components/DrawWithOptions/DoubleHeadSvg.js +0 -1
- package/lib/module/components/DrawWithOptions/DoubleHeadSvg.js.map +1 -1
- package/lib/module/components/DrawWithOptions/PenSvg.js +0 -1
- package/lib/module/components/DrawWithOptions/PenSvg.js.map +1 -1
- package/lib/module/components/DrawWithOptions/SendSvg.js +0 -3
- package/lib/module/components/DrawWithOptions/SendSvg.js.map +1 -1
- package/lib/module/components/DrawWithOptions/SliderSvg.js +22 -0
- package/lib/module/components/DrawWithOptions/SliderSvg.js.map +1 -0
- package/lib/module/components/DrawWithOptions/SquareSvg.js +0 -1
- package/lib/module/components/DrawWithOptions/SquareSvg.js.map +1 -1
- package/lib/module/components/DrawWithOptions/TextSvg.js +0 -3
- package/lib/module/components/DrawWithOptions/TextSvg.js.map +1 -1
- package/lib/module/components/DrawWithOptions/ThrashSvg.js +27 -5
- package/lib/module/components/DrawWithOptions/ThrashSvg.js.map +1 -1
- package/lib/module/components/DrawWithOptions/index.js +126 -73
- package/lib/module/components/DrawWithOptions/index.js.map +1 -1
- package/lib/module/components/Slider/ColorSlider.js +95 -0
- package/lib/module/components/Slider/ColorSlider.js.map +1 -0
- package/lib/module/components/Slider/Sliders.js +79 -0
- package/lib/module/components/Slider/Sliders.js.map +1 -0
- package/lib/module/components/Slider/StrokeSlider.js +82 -0
- package/lib/module/components/Slider/StrokeSlider.js.map +1 -0
- package/lib/module/components/Slider/sliderStyle.js +29 -0
- package/lib/module/components/Slider/sliderStyle.js.map +1 -0
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/types.d.js.map +1 -1
- package/lib/typescript/components/DrawCore/CurrentAnimatedItem.d.ts +1 -1
- package/lib/typescript/components/DrawCore/CurrentAnimatedItem.d.ts.map +1 -0
- package/lib/typescript/components/DrawCore/CurrentAnimatedText.d.ts +1 -1
- package/lib/typescript/components/DrawCore/CurrentAnimatedText.d.ts.map +1 -0
- package/lib/typescript/components/DrawCore/DrawContext.d.ts +14 -0
- package/lib/typescript/components/DrawCore/DrawContext.d.ts.map +1 -0
- package/lib/typescript/components/DrawCore/DrawPad.d.ts +1 -1
- package/lib/typescript/components/DrawCore/DrawPad.d.ts.map +1 -0
- package/lib/typescript/components/DrawCore/DrawProvider.d.ts +6 -0
- package/lib/typescript/components/DrawCore/DrawProvider.d.ts.map +1 -0
- package/lib/typescript/components/DrawCore/Item.d.ts +1 -1
- package/lib/typescript/components/DrawCore/Item.d.ts.map +1 -0
- package/lib/typescript/components/DrawCore/index.d.ts +4 -11
- package/lib/typescript/components/DrawCore/index.d.ts.map +1 -0
- package/lib/typescript/components/DrawCore/useDrawHook.d.ts +18 -0
- package/lib/typescript/components/DrawCore/useDrawHook.d.ts.map +1 -0
- package/lib/typescript/components/DrawWithOptions/ArrowSvg.d.ts +1 -1
- package/lib/typescript/components/DrawWithOptions/ArrowSvg.d.ts.map +1 -0
- package/lib/typescript/components/DrawWithOptions/CancelSvg.d.ts +1 -1
- package/lib/typescript/components/DrawWithOptions/CancelSvg.d.ts.map +1 -0
- package/lib/typescript/components/DrawWithOptions/CircleSvg.d.ts +1 -1
- package/lib/typescript/components/DrawWithOptions/CircleSvg.d.ts.map +1 -0
- package/lib/typescript/components/DrawWithOptions/CloseSvg.d.ts +1 -1
- package/lib/typescript/components/DrawWithOptions/CloseSvg.d.ts.map +1 -0
- package/lib/typescript/components/DrawWithOptions/DoubleHeadSvg.d.ts +1 -1
- package/lib/typescript/components/DrawWithOptions/DoubleHeadSvg.d.ts.map +1 -0
- package/lib/typescript/components/DrawWithOptions/PenSvg.d.ts +1 -1
- package/lib/typescript/components/DrawWithOptions/PenSvg.d.ts.map +1 -0
- package/lib/typescript/components/DrawWithOptions/SendSvg.d.ts +1 -1
- package/lib/typescript/components/DrawWithOptions/SendSvg.d.ts.map +1 -0
- package/lib/typescript/components/DrawWithOptions/SliderSvg.d.ts +4 -0
- package/lib/typescript/components/DrawWithOptions/SliderSvg.d.ts.map +1 -0
- package/lib/typescript/components/DrawWithOptions/SquareSvg.d.ts +1 -1
- package/lib/typescript/components/DrawWithOptions/SquareSvg.d.ts.map +1 -0
- package/lib/typescript/components/DrawWithOptions/TextSvg.d.ts +1 -1
- package/lib/typescript/components/DrawWithOptions/TextSvg.d.ts.map +1 -0
- package/lib/typescript/components/DrawWithOptions/ThrashSvg.d.ts +1 -1
- package/lib/typescript/components/DrawWithOptions/ThrashSvg.d.ts.map +1 -0
- package/lib/typescript/components/DrawWithOptions/index.d.ts +4 -5
- package/lib/typescript/components/DrawWithOptions/index.d.ts.map +1 -0
- package/lib/typescript/components/Slider/ColorSlider.d.ts +8 -0
- package/lib/typescript/components/Slider/ColorSlider.d.ts.map +1 -0
- package/lib/typescript/components/Slider/Sliders.d.ts +8 -0
- package/lib/typescript/components/Slider/Sliders.d.ts.map +1 -0
- package/lib/typescript/components/Slider/StrokeSlider.d.ts +6 -0
- package/lib/typescript/components/Slider/StrokeSlider.d.ts.map +1 -0
- package/lib/typescript/components/Slider/sliderStyle.d.ts +28 -0
- package/lib/typescript/components/Slider/sliderStyle.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +2 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/package.json +32 -33
- package/src/components/DrawCore/CurrentAnimatedItem.tsx +166 -106
- package/src/components/DrawCore/DrawContext.tsx +22 -0
- package/src/components/DrawCore/DrawPad.tsx +3 -10
- package/src/components/DrawCore/DrawProvider.tsx +122 -0
- package/src/components/DrawCore/index.tsx +938 -1132
- package/src/components/DrawCore/useDrawHook.tsx +70 -0
- package/src/components/DrawWithOptions/SliderSvg.tsx +24 -0
- package/src/components/DrawWithOptions/ThrashSvg.tsx +29 -2
- package/src/components/DrawWithOptions/index.tsx +199 -146
- package/src/components/Slider/ColorSlider.tsx +144 -0
- package/src/components/Slider/Sliders.tsx +75 -0
- package/src/components/Slider/StrokeSlider.tsx +104 -0
- package/src/components/Slider/sliderStyle.tsx +28 -0
- package/src/index.tsx +1 -0
- package/src/types.d.ts +35 -1
- package/lib/commonjs/components/DrawCore/ColorSlider.js.map +0 -1
- package/lib/commonjs/components/DrawCore/StrokeSlider.js.map +0 -1
- package/lib/module/components/DrawCore/ColorSlider.js +0 -119
- package/lib/module/components/DrawCore/ColorSlider.js.map +0 -1
- package/lib/module/components/DrawCore/StrokeSlider.js +0 -93
- package/lib/module/components/DrawCore/StrokeSlider.js.map +0 -1
- package/lib/typescript/components/DrawCore/ColorSlider.d.ts +0 -12
- package/lib/typescript/components/DrawCore/StrokeSlider.d.ts +0 -9
- package/src/components/DrawCore/ColorSlider.tsx +0 -169
- package/src/components/DrawCore/StrokeSlider.tsx +0 -117
|
@@ -1,50 +1,25 @@
|
|
|
1
|
-
import React, { useCallback, useEffect,
|
|
2
|
-
import { StyleSheet, TextInput, View, Keyboard, ImageBackground, Image,
|
|
1
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { StyleSheet, TextInput, View, Keyboard, ImageBackground, Image, InputAccessoryView, Platform } from 'react-native';
|
|
3
3
|
import Animated, { runOnJS, useAnimatedGestureHandler, useAnimatedReaction, useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';
|
|
4
4
|
import { PanGestureHandler } from 'react-native-gesture-handler';
|
|
5
|
-
import ColorSlider from './ColorSlider';
|
|
6
|
-
import StrokeSlider from './StrokeSlider';
|
|
7
5
|
import DrawPad from './DrawPad';
|
|
8
6
|
import ViewShot from 'react-native-view-shot';
|
|
9
|
-
|
|
7
|
+
import useDrawHook from './useDrawHook';
|
|
10
8
|
const styles = StyleSheet.create({
|
|
11
9
|
container: {
|
|
12
10
|
flex: 1
|
|
13
11
|
},
|
|
14
12
|
drawZone: {
|
|
15
13
|
flex: 1,
|
|
16
|
-
|
|
14
|
+
alignContent: 'center',
|
|
17
15
|
alignItems: 'center'
|
|
18
16
|
},
|
|
19
|
-
rightPaneBaseStyle: {
|
|
20
|
-
position: 'absolute',
|
|
21
|
-
right: 0,
|
|
22
|
-
top: 0,
|
|
23
|
-
bottom: 0,
|
|
24
|
-
backgroundColor: '#000000cc',
|
|
25
|
-
width: RIGHT_PANE_WIDTH,
|
|
26
|
-
justifyContent: 'space-evenly',
|
|
27
|
-
marginVertical: 20,
|
|
28
|
-
borderTopLeftRadius: 20,
|
|
29
|
-
borderBottomLeftRadius: 20,
|
|
30
|
-
paddingVertical: 30
|
|
31
|
-
},
|
|
32
|
-
strokeSliderContainer: {
|
|
33
|
-
flex: 1,
|
|
34
|
-
paddingBottom: 15,
|
|
35
|
-
borderBottomColor: '#000000',
|
|
36
|
-
borderBottomWidth: 2
|
|
37
|
-
},
|
|
38
|
-
colorSliderContainer: {
|
|
39
|
-
flex: 1,
|
|
40
|
-
paddingTop: 15
|
|
41
|
-
},
|
|
42
17
|
bgImage: {
|
|
43
18
|
width: '100%',
|
|
44
19
|
height: '100%'
|
|
45
20
|
},
|
|
46
21
|
textInput: {
|
|
47
|
-
backgroundColor: '#
|
|
22
|
+
backgroundColor: '#262626',
|
|
48
23
|
paddingVertical: 16,
|
|
49
24
|
paddingHorizontal: 24,
|
|
50
25
|
fontSize: 16,
|
|
@@ -52,7 +27,6 @@ const styles = StyleSheet.create({
|
|
|
52
27
|
width: '100%'
|
|
53
28
|
}
|
|
54
29
|
});
|
|
55
|
-
|
|
56
30
|
const pDistance = (point, line) => {
|
|
57
31
|
'worklet';
|
|
58
32
|
|
|
@@ -73,14 +47,11 @@ const pDistance = (point, line) => {
|
|
|
73
47
|
var dot = A * C + B * D;
|
|
74
48
|
var len_sq = C * C + D * D;
|
|
75
49
|
var param = -1;
|
|
76
|
-
|
|
77
50
|
if (len_sq !== 0) {
|
|
78
51
|
//in case of 0 length line
|
|
79
52
|
param = dot / len_sq;
|
|
80
53
|
}
|
|
81
|
-
|
|
82
54
|
var xx, yy;
|
|
83
|
-
|
|
84
55
|
if (param < 0) {
|
|
85
56
|
xx = x1;
|
|
86
57
|
yy = y1;
|
|
@@ -91,23 +62,19 @@ const pDistance = (point, line) => {
|
|
|
91
62
|
xx = x1 + param * C;
|
|
92
63
|
yy = y1 + param * D;
|
|
93
64
|
}
|
|
94
|
-
|
|
95
65
|
var dx = x - xx;
|
|
96
66
|
var dy = y - yy;
|
|
97
67
|
return Math.sqrt(dx * dx + dy * dy);
|
|
98
68
|
};
|
|
99
|
-
|
|
100
69
|
const AnimatedTextInput = Animated.createAnimatedComponent(TextInput);
|
|
101
70
|
const DEFAULT_TEXT = '';
|
|
102
71
|
const THRESHOLD = 20;
|
|
103
|
-
|
|
104
72
|
const drawNewItem = (mode, currentItem, addDoneItem, position, style) => {
|
|
105
73
|
'worklet';
|
|
106
74
|
|
|
107
75
|
if (currentItem.value) {
|
|
108
76
|
runOnJS(addDoneItem)(currentItem.value);
|
|
109
77
|
}
|
|
110
|
-
|
|
111
78
|
switch (mode.value) {
|
|
112
79
|
case 'ellipse':
|
|
113
80
|
currentItem.value = {
|
|
@@ -122,7 +89,6 @@ const drawNewItem = (mode, currentItem, addDoneItem, position, style) => {
|
|
|
122
89
|
color: style.color.value
|
|
123
90
|
};
|
|
124
91
|
break;
|
|
125
|
-
|
|
126
92
|
case 'rectangle':
|
|
127
93
|
currentItem.value = {
|
|
128
94
|
type: mode.value,
|
|
@@ -136,7 +102,6 @@ const drawNewItem = (mode, currentItem, addDoneItem, position, style) => {
|
|
|
136
102
|
color: style.color.value
|
|
137
103
|
};
|
|
138
104
|
break;
|
|
139
|
-
|
|
140
105
|
case 'singleHead':
|
|
141
106
|
case 'doubleHead':
|
|
142
107
|
currentItem.value = {
|
|
@@ -151,7 +116,6 @@ const drawNewItem = (mode, currentItem, addDoneItem, position, style) => {
|
|
|
151
116
|
color: style.color.value
|
|
152
117
|
};
|
|
153
118
|
break;
|
|
154
|
-
|
|
155
119
|
case 'text':
|
|
156
120
|
currentItem.value = {
|
|
157
121
|
type: mode.value,
|
|
@@ -166,7 +130,6 @@ const drawNewItem = (mode, currentItem, addDoneItem, position, style) => {
|
|
|
166
130
|
color: style.color.value
|
|
167
131
|
};
|
|
168
132
|
break;
|
|
169
|
-
|
|
170
133
|
case 'pen':
|
|
171
134
|
currentItem.value = {
|
|
172
135
|
type: mode.value,
|
|
@@ -177,16 +140,15 @@ const drawNewItem = (mode, currentItem, addDoneItem, position, style) => {
|
|
|
177
140
|
break;
|
|
178
141
|
}
|
|
179
142
|
};
|
|
180
|
-
|
|
181
143
|
const onTextHeightUpdate = (currentItem, textBaseHeight, height) => {
|
|
182
144
|
'worklet';
|
|
183
145
|
|
|
184
146
|
var _currentItem$value;
|
|
185
|
-
|
|
186
147
|
if (((_currentItem$value = currentItem.value) === null || _currentItem$value === void 0 ? void 0 : _currentItem$value.type) === 'text') {
|
|
187
148
|
textBaseHeight.value = textBaseHeight.value || height;
|
|
188
149
|
currentItem.value = {
|
|
189
|
-
data: {
|
|
150
|
+
data: {
|
|
151
|
+
...currentItem.value.data,
|
|
190
152
|
height: height
|
|
191
153
|
},
|
|
192
154
|
type: currentItem.value.type,
|
|
@@ -196,165 +158,68 @@ const onTextHeightUpdate = (currentItem, textBaseHeight, height) => {
|
|
|
196
158
|
};
|
|
197
159
|
}
|
|
198
160
|
};
|
|
199
|
-
|
|
200
|
-
const reducerDrawStates = (drawStates, action) => {
|
|
201
|
-
'worklet';
|
|
202
|
-
|
|
203
|
-
switch (action.type) {
|
|
204
|
-
case 'ADD_DONE_ITEM':
|
|
205
|
-
return { ...drawStates,
|
|
206
|
-
doneItems: drawStates.doneItems.concat(action.item)
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
case 'DELETE_DONE_ITEM':
|
|
210
|
-
const newDoneItems = drawStates.doneItems;
|
|
211
|
-
newDoneItems.splice(action.indice, 1);
|
|
212
|
-
return { ...drawStates,
|
|
213
|
-
doneItems: newDoneItems
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
case 'ADD_SCREEN_STATE':
|
|
217
|
-
if (action.currentItem) {
|
|
218
|
-
return { ...drawStates,
|
|
219
|
-
screenStates: drawStates.screenStates.concat([[...drawStates.doneItems, action.currentItem]])
|
|
220
|
-
};
|
|
221
|
-
} else {
|
|
222
|
-
return { ...drawStates,
|
|
223
|
-
screenStates: drawStates.screenStates.concat([[...drawStates.doneItems]])
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
case 'CANCEL':
|
|
228
|
-
const len = drawStates.screenStates.length;
|
|
229
|
-
|
|
230
|
-
if (len > 1) {
|
|
231
|
-
const newScreenStates = drawStates.screenStates;
|
|
232
|
-
newScreenStates.pop();
|
|
233
|
-
|
|
234
|
-
if (newScreenStates.length === 1) {
|
|
235
|
-
var _action$onCancelChang;
|
|
236
|
-
|
|
237
|
-
(_action$onCancelChang = action.onCancelChange) === null || _action$onCancelChang === void 0 ? void 0 : _action$onCancelChang.call(action, false);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
return {
|
|
241
|
-
doneItems: drawStates.screenStates[len - 2],
|
|
242
|
-
screenStates: newScreenStates
|
|
243
|
-
};
|
|
244
|
-
} else {
|
|
245
|
-
return drawStates;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
161
|
+
const DrawCore = _ref => {
|
|
252
162
|
var _textInputRef$current3, _textInputRef$current4;
|
|
253
|
-
|
|
254
163
|
let {
|
|
255
|
-
drawingMode,
|
|
256
164
|
image,
|
|
257
|
-
linearGradient,
|
|
258
|
-
onSelectionChange,
|
|
259
|
-
onCancelChange,
|
|
260
165
|
backgroundColor
|
|
261
166
|
} = _ref;
|
|
167
|
+
const {
|
|
168
|
+
drawState,
|
|
169
|
+
dispatchDrawStates,
|
|
170
|
+
strokeWidth,
|
|
171
|
+
color,
|
|
172
|
+
currentItem,
|
|
173
|
+
itemIsSelected,
|
|
174
|
+
viewShot
|
|
175
|
+
} = useDrawHook();
|
|
176
|
+
const onCancelChangeWrapper = arg => {
|
|
177
|
+
dispatchDrawStates({
|
|
178
|
+
type: 'SET_CANCEL_ENABLED',
|
|
179
|
+
cancelEnabled: arg
|
|
180
|
+
});
|
|
181
|
+
};
|
|
262
182
|
const mode = useSharedValue('pen');
|
|
263
183
|
const [drawRegion, setDrawRegion] = useState(null);
|
|
264
184
|
const [originalImageSize, setOriginalImageSize] = useState(null);
|
|
265
185
|
const [imageSize, setImageSize] = useState(null);
|
|
266
186
|
const drawContainer = useRef(null);
|
|
267
|
-
const viewShot = useRef(null);
|
|
268
187
|
const [textVal, setTextVal] = useState('');
|
|
269
|
-
const currentItem = useSharedValue(null);
|
|
270
188
|
const initialItem = useSharedValue(null);
|
|
271
|
-
const [drawStates, dispatchDrawStates] = useReducer(reducerDrawStates, {
|
|
272
|
-
doneItems: [],
|
|
273
|
-
screenStates: [[]]
|
|
274
|
-
});
|
|
275
189
|
const textBaseHeight = useSharedValue(null);
|
|
276
190
|
const addDoneItem = useCallback(item => {
|
|
277
191
|
dispatchDrawStates({
|
|
278
192
|
type: 'ADD_DONE_ITEM',
|
|
279
193
|
item: item
|
|
280
194
|
});
|
|
281
|
-
}, []);
|
|
195
|
+
}, [dispatchDrawStates]);
|
|
282
196
|
const deleteDoneItem = useCallback(indice => {
|
|
283
197
|
dispatchDrawStates({
|
|
284
198
|
type: 'DELETE_DONE_ITEM',
|
|
285
199
|
indice: indice
|
|
286
200
|
});
|
|
287
|
-
}, []);
|
|
201
|
+
}, [dispatchDrawStates]);
|
|
288
202
|
const addScreenStates = useCallback(item => {
|
|
289
203
|
dispatchDrawStates({
|
|
290
204
|
type: 'ADD_SCREEN_STATE',
|
|
291
205
|
currentItem: item
|
|
292
206
|
});
|
|
293
|
-
}, []);
|
|
294
|
-
const cancelAction = useCallback(() => {
|
|
295
|
-
dispatchDrawStates({
|
|
296
|
-
type: 'CANCEL',
|
|
297
|
-
onCancelChange: onCancelChange
|
|
298
|
-
});
|
|
299
|
-
}, [onCancelChange]);
|
|
300
|
-
useImperativeHandle(ref, () => ({
|
|
301
|
-
drawingContainer: drawContainer,
|
|
302
|
-
deleteSelectedItem: () => {
|
|
303
|
-
if (currentItem.value) {
|
|
304
|
-
currentItem.value = null;
|
|
305
|
-
addScreenStates(null);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange(false);
|
|
309
|
-
onCancelChange === null || onCancelChange === void 0 ? void 0 : onCancelChange(true);
|
|
310
|
-
},
|
|
311
|
-
cancelLastAction: () => {
|
|
312
|
-
onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange(false);
|
|
313
|
-
|
|
314
|
-
if (currentItem.value) {
|
|
315
|
-
currentItem.value = null;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
cancelAction();
|
|
319
|
-
},
|
|
320
|
-
takeSnapshot: async () => {
|
|
321
|
-
var _viewShot$current, _viewShot$current$cap;
|
|
322
|
-
|
|
323
|
-
if (currentItem.value) {
|
|
324
|
-
addDoneItem(currentItem.value);
|
|
325
|
-
currentItem.value = null;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
return (_viewShot$current = viewShot.current) === null || _viewShot$current === void 0 ? void 0 : (_viewShot$current$cap = _viewShot$current.capture) === null || _viewShot$current$cap === void 0 ? void 0 : _viewShot$current$cap.call(_viewShot$current);
|
|
329
|
-
}
|
|
330
|
-
}), [currentItem, onSelectionChange, onCancelChange, addScreenStates, cancelAction, addDoneItem]);
|
|
207
|
+
}, [dispatchDrawStates]);
|
|
331
208
|
useEffect(() => {
|
|
332
|
-
mode.value = drawingMode;
|
|
333
|
-
|
|
209
|
+
mode.value = drawState.drawingMode;
|
|
334
210
|
if (currentItem.value) {
|
|
335
211
|
addDoneItem(currentItem.value);
|
|
336
212
|
}
|
|
337
|
-
|
|
338
213
|
currentItem.value = null;
|
|
339
|
-
|
|
340
|
-
}, [drawingMode, mode, currentItem,
|
|
341
|
-
const strokeWidth = useSharedValue(2);
|
|
342
|
-
const color = useSharedValue('hsl(0, 100%, 0%)');
|
|
343
|
-
const panPosition = useSharedValue(0);
|
|
214
|
+
itemIsSelected.value = false;
|
|
215
|
+
}, [drawState.drawingMode, mode, currentItem, addDoneItem, itemIsSelected]);
|
|
344
216
|
const showTextInput = useSharedValue(false);
|
|
345
217
|
const textFocus = useCallback(() => {
|
|
346
218
|
var _textInputRef$current;
|
|
347
|
-
|
|
348
219
|
(_textInputRef$current = textInputRef.current) === null || _textInputRef$current === void 0 ? void 0 : _textInputRef$current.focus();
|
|
349
220
|
}, []);
|
|
350
|
-
const onColorStrokeChange = useCallback(() => {
|
|
351
|
-
if (currentItem.value) {
|
|
352
|
-
addScreenStates(currentItem.value);
|
|
353
|
-
}
|
|
354
|
-
}, [addScreenStates, currentItem.value]);
|
|
355
221
|
useEffect(() => {
|
|
356
222
|
var _currentItem$value2;
|
|
357
|
-
|
|
358
223
|
if (((_currentItem$value2 = currentItem.value) === null || _currentItem$value2 === void 0 ? void 0 : _currentItem$value2.type) === 'text') {
|
|
359
224
|
currentItem.value = {
|
|
360
225
|
data: currentItem.value.data,
|
|
@@ -368,7 +233,6 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
368
233
|
const onGestureEvent = useAnimatedGestureHandler({
|
|
369
234
|
onStart: (_ref2, ctx) => {
|
|
370
235
|
var _currentItem$value3;
|
|
371
|
-
|
|
372
236
|
let {
|
|
373
237
|
x: startX,
|
|
374
238
|
y: startY
|
|
@@ -376,16 +240,16 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
376
240
|
ctx.startX = startX;
|
|
377
241
|
ctx.startY = startY;
|
|
378
242
|
ctx.newlyCreated = false;
|
|
379
|
-
panPosition.value = withTiming(RIGHT_PANE_WIDTH);
|
|
380
|
-
initialItem.value = currentItem.value;
|
|
381
243
|
|
|
244
|
+
//panPosition.value = withTiming(RIGHT_PANE_WIDTH);
|
|
245
|
+
|
|
246
|
+
initialItem.value = currentItem.value;
|
|
382
247
|
switch ((_currentItem$value3 = currentItem.value) === null || _currentItem$value3 === void 0 ? void 0 : _currentItem$value3.type) {
|
|
383
248
|
case 'ellipse':
|
|
384
249
|
const cx = typeof currentItem.value.data.cx === 'string' ? parseFloat(currentItem.value.data.cx) : currentItem.value.data.cx || 0;
|
|
385
250
|
const cy = typeof currentItem.value.data.cy === 'string' ? parseFloat(currentItem.value.data.cy) : currentItem.value.data.cy || 0;
|
|
386
251
|
const rx = typeof currentItem.value.data.rx === 'string' ? parseFloat(currentItem.value.data.rx) : currentItem.value.data.rx || 0;
|
|
387
252
|
const ry = typeof currentItem.value.data.ry === 'string' ? parseFloat(currentItem.value.data.ry) : currentItem.value.data.ry || 0;
|
|
388
|
-
|
|
389
253
|
if (startX <= cx + THRESHOLD && startX >= cx - THRESHOLD && startY <= cy - ry + THRESHOLD && startY >= cy - ry - THRESHOLD) {
|
|
390
254
|
ctx.zone = 'TOP';
|
|
391
255
|
} else if (startX <= cx + THRESHOLD && startX >= cx - THRESHOLD && startY <= cy + ry + THRESHOLD && startY >= cy + ry - THRESHOLD) {
|
|
@@ -400,15 +264,12 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
400
264
|
ctx.zone = 'OUT';
|
|
401
265
|
initialItem.value = null;
|
|
402
266
|
}
|
|
403
|
-
|
|
404
267
|
break;
|
|
405
|
-
|
|
406
268
|
case 'rectangle':
|
|
407
269
|
const x = typeof currentItem.value.data.x === 'string' ? parseFloat(currentItem.value.data.x) : currentItem.value.data.x || 0;
|
|
408
270
|
const y = typeof currentItem.value.data.y === 'string' ? parseFloat(currentItem.value.data.y) : currentItem.value.data.y || 0;
|
|
409
271
|
const height = typeof currentItem.value.data.height === 'string' ? parseFloat(currentItem.value.data.height) : currentItem.value.data.height || 0;
|
|
410
272
|
const width = typeof currentItem.value.data.width === 'string' ? parseFloat(currentItem.value.data.width) : currentItem.value.data.width || 0;
|
|
411
|
-
|
|
412
273
|
if (startX <= x + THRESHOLD && startX >= x - THRESHOLD) {
|
|
413
274
|
if (startY <= y + THRESHOLD && startY >= y - THRESHOLD) {
|
|
414
275
|
ctx.zone = 'TOP_LEFT';
|
|
@@ -427,16 +288,13 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
427
288
|
ctx.zone = 'OUT';
|
|
428
289
|
initialItem.value = null;
|
|
429
290
|
}
|
|
430
|
-
|
|
431
291
|
break;
|
|
432
|
-
|
|
433
292
|
case 'doubleHead':
|
|
434
293
|
case 'singleHead':
|
|
435
294
|
const x1 = typeof currentItem.value.data.x1 === 'string' ? parseFloat(currentItem.value.data.x1) : currentItem.value.data.x1 || 0;
|
|
436
295
|
const y1 = typeof currentItem.value.data.y1 === 'string' ? parseFloat(currentItem.value.data.y1) : currentItem.value.data.y1 || 0;
|
|
437
296
|
const x2 = typeof currentItem.value.data.x2 === 'string' ? parseFloat(currentItem.value.data.x2) : currentItem.value.data.x2 || 0;
|
|
438
297
|
const y2 = typeof currentItem.value.data.y2 === 'string' ? parseFloat(currentItem.value.data.y2) : currentItem.value.data.y2 || 0;
|
|
439
|
-
|
|
440
298
|
if (startX <= x1 + THRESHOLD && startX >= x1 - THRESHOLD && startY <= y1 + THRESHOLD && startY >= y1 - THRESHOLD) {
|
|
441
299
|
ctx.zone = 'TOP';
|
|
442
300
|
} else if (startX <= x2 + THRESHOLD && startX >= x2 - THRESHOLD && startY - THRESHOLD <= y2 + THRESHOLD && startY + THRESHOLD >= y2 - THRESHOLD) {
|
|
@@ -455,15 +313,12 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
455
313
|
ctx.zone = 'OUT';
|
|
456
314
|
initialItem.value = null;
|
|
457
315
|
}
|
|
458
|
-
|
|
459
316
|
break;
|
|
460
|
-
|
|
461
317
|
case 'text':
|
|
462
318
|
const xText = typeof currentItem.value.data.x === 'string' ? parseFloat(currentItem.value.data.x) : currentItem.value.data.x || 0;
|
|
463
319
|
const yText = typeof currentItem.value.data.y === 'string' ? parseFloat(currentItem.value.data.y) : currentItem.value.data.y || 0;
|
|
464
320
|
const widthText = typeof currentItem.value.data.width === 'string' ? parseFloat(currentItem.value.data.width) : currentItem.value.data.width || 0;
|
|
465
321
|
const heightText = typeof currentItem.value.data.height === 'string' ? parseFloat(currentItem.value.data.height) : currentItem.value.data.height || 0;
|
|
466
|
-
|
|
467
322
|
if (startX <= xText + THRESHOLD && startX >= xText - THRESHOLD && startY <= yText + heightText / 2 + THRESHOLD && startY >= yText + heightText / 2 - THRESHOLD) {
|
|
468
323
|
ctx.zone = 'LEFT';
|
|
469
324
|
} else if (startX <= xText + widthText + THRESHOLD && startX >= xText + widthText - THRESHOLD && startY <= yText + heightText / 2 + THRESHOLD && startY >= yText + heightText / 2 - THRESHOLD) {
|
|
@@ -474,9 +329,7 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
474
329
|
ctx.zone = 'OUT';
|
|
475
330
|
initialItem.value = null;
|
|
476
331
|
}
|
|
477
|
-
|
|
478
332
|
break;
|
|
479
|
-
|
|
480
333
|
case 'pen':
|
|
481
334
|
if (currentItem.value.data.some(p => startX <= p.x + THRESHOLD && startX >= p.x - THRESHOLD && startY <= p.y + THRESHOLD && startY >= p.y - THRESHOLD)) {
|
|
482
335
|
ctx.zone = 'CENTER';
|
|
@@ -484,9 +337,7 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
484
337
|
ctx.zone = 'OUT';
|
|
485
338
|
initialItem.value = null;
|
|
486
339
|
}
|
|
487
|
-
|
|
488
340
|
break;
|
|
489
|
-
|
|
490
341
|
default:
|
|
491
342
|
ctx.zone = 'OUT';
|
|
492
343
|
initialItem.value = null;
|
|
@@ -495,7 +346,6 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
495
346
|
},
|
|
496
347
|
onActive: (_ref3, ctx) => {
|
|
497
348
|
var _currentItem$value4, _initialItem$value, _initialItem$value2, _initialItem$value4, _initialItem$value17, _initialItem$value30;
|
|
498
|
-
|
|
499
349
|
let {
|
|
500
350
|
x: currentX,
|
|
501
351
|
y: currentY,
|
|
@@ -508,14 +358,11 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
508
358
|
zone,
|
|
509
359
|
newlyCreated
|
|
510
360
|
} = ctx;
|
|
511
|
-
|
|
512
361
|
if (zone === 'OUT' && newlyCreated === false) {
|
|
513
362
|
ctx.newlyCreated = true;
|
|
514
|
-
|
|
515
363
|
if (mode.value === 'text') {
|
|
516
364
|
runOnJS(setTextVal)('');
|
|
517
365
|
}
|
|
518
|
-
|
|
519
366
|
drawNewItem(mode, currentItem, addDoneItem, {
|
|
520
367
|
x: startX,
|
|
521
368
|
y: startY
|
|
@@ -524,10 +371,9 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
524
371
|
strokeWidth,
|
|
525
372
|
color
|
|
526
373
|
});
|
|
527
|
-
|
|
528
|
-
|
|
374
|
+
itemIsSelected.value = true;
|
|
375
|
+
onCancelChangeWrapper && runOnJS(onCancelChangeWrapper)(true);
|
|
529
376
|
}
|
|
530
|
-
|
|
531
377
|
switch ((_currentItem$value4 = currentItem.value) === null || _currentItem$value4 === void 0 ? void 0 : _currentItem$value4.type) {
|
|
532
378
|
case 'pen':
|
|
533
379
|
if (((_initialItem$value = initialItem.value) === null || _initialItem$value === void 0 ? void 0 : _initialItem$value.type) === currentItem.value.type && zone === 'CENTER') {
|
|
@@ -551,18 +397,14 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
551
397
|
})
|
|
552
398
|
};
|
|
553
399
|
}
|
|
554
|
-
|
|
555
400
|
break;
|
|
556
|
-
|
|
557
401
|
case 'ellipse':
|
|
558
402
|
if (((_initialItem$value2 = initialItem.value) === null || _initialItem$value2 === void 0 ? void 0 : _initialItem$value2.type) === currentItem.value.type) {
|
|
559
403
|
var _initialItem$value3;
|
|
560
|
-
|
|
561
404
|
const rx = typeof initialItem.value.data.rx === 'string' ? parseFloat((_initialItem$value3 = initialItem.value) === null || _initialItem$value3 === void 0 ? void 0 : _initialItem$value3.data.rx) : initialItem.value.data.rx || 0;
|
|
562
405
|
const ry = typeof initialItem.value.data.ry === 'string' ? parseFloat(initialItem.value.data.ry) : initialItem.value.data.ry || 0;
|
|
563
406
|
const cx = typeof initialItem.value.data.cx === 'string' ? parseFloat(initialItem.value.data.cx) : initialItem.value.data.cx || 0;
|
|
564
407
|
const cy = typeof initialItem.value.data.cy === 'string' ? parseFloat(initialItem.value.data.cy) : initialItem.value.data.cy || 0;
|
|
565
|
-
|
|
566
408
|
switch (zone) {
|
|
567
409
|
case 'TOP':
|
|
568
410
|
currentItem.value = {
|
|
@@ -577,7 +419,6 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
577
419
|
}
|
|
578
420
|
};
|
|
579
421
|
break;
|
|
580
|
-
|
|
581
422
|
case 'BOTTOM':
|
|
582
423
|
currentItem.value = {
|
|
583
424
|
type: currentItem.value.type,
|
|
@@ -591,7 +432,6 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
591
432
|
}
|
|
592
433
|
};
|
|
593
434
|
break;
|
|
594
|
-
|
|
595
435
|
case 'LEFT':
|
|
596
436
|
currentItem.value = {
|
|
597
437
|
type: currentItem.value.type,
|
|
@@ -605,7 +445,6 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
605
445
|
}
|
|
606
446
|
};
|
|
607
447
|
break;
|
|
608
|
-
|
|
609
448
|
case 'RIGHT':
|
|
610
449
|
currentItem.value = {
|
|
611
450
|
type: currentItem.value.type,
|
|
@@ -619,7 +458,6 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
619
458
|
}
|
|
620
459
|
};
|
|
621
460
|
break;
|
|
622
|
-
|
|
623
461
|
case 'CENTER':
|
|
624
462
|
currentItem.value = {
|
|
625
463
|
type: currentItem.value.type,
|
|
@@ -647,18 +485,14 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
647
485
|
}
|
|
648
486
|
};
|
|
649
487
|
}
|
|
650
|
-
|
|
651
488
|
break;
|
|
652
|
-
|
|
653
489
|
case 'rectangle':
|
|
654
490
|
if (((_initialItem$value4 = initialItem.value) === null || _initialItem$value4 === void 0 ? void 0 : _initialItem$value4.type) === currentItem.value.type) {
|
|
655
491
|
var _initialItem$value5, _initialItem$value6, _initialItem$value7, _initialItem$value8, _initialItem$value9, _initialItem$value10, _initialItem$value11, _initialItem$value12, _initialItem$value13, _initialItem$value14, _initialItem$value15, _initialItem$value16;
|
|
656
|
-
|
|
657
492
|
const height = typeof ((_initialItem$value5 = initialItem.value) === null || _initialItem$value5 === void 0 ? void 0 : _initialItem$value5.data.height) === 'string' ? parseFloat((_initialItem$value6 = initialItem.value) === null || _initialItem$value6 === void 0 ? void 0 : _initialItem$value6.data.height) : ((_initialItem$value7 = initialItem.value) === null || _initialItem$value7 === void 0 ? void 0 : _initialItem$value7.data.height) || 0;
|
|
658
493
|
const width = typeof ((_initialItem$value8 = initialItem.value) === null || _initialItem$value8 === void 0 ? void 0 : _initialItem$value8.data.width) === 'string' ? parseFloat((_initialItem$value9 = initialItem.value) === null || _initialItem$value9 === void 0 ? void 0 : _initialItem$value9.data.width) : ((_initialItem$value10 = initialItem.value) === null || _initialItem$value10 === void 0 ? void 0 : _initialItem$value10.data.width) || 0;
|
|
659
494
|
const x = typeof ((_initialItem$value11 = initialItem.value) === null || _initialItem$value11 === void 0 ? void 0 : _initialItem$value11.data.x) === 'string' ? parseFloat((_initialItem$value12 = initialItem.value) === null || _initialItem$value12 === void 0 ? void 0 : _initialItem$value12.data.x) : ((_initialItem$value13 = initialItem.value) === null || _initialItem$value13 === void 0 ? void 0 : _initialItem$value13.data.x) || 0;
|
|
660
495
|
const y = typeof ((_initialItem$value14 = initialItem.value) === null || _initialItem$value14 === void 0 ? void 0 : _initialItem$value14.data.y) === 'string' ? parseFloat((_initialItem$value15 = initialItem.value) === null || _initialItem$value15 === void 0 ? void 0 : _initialItem$value15.data.y) : ((_initialItem$value16 = initialItem.value) === null || _initialItem$value16 === void 0 ? void 0 : _initialItem$value16.data.y) || 0;
|
|
661
|
-
|
|
662
496
|
switch (zone) {
|
|
663
497
|
case 'TOP_LEFT':
|
|
664
498
|
currentItem.value = {
|
|
@@ -673,7 +507,6 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
673
507
|
}
|
|
674
508
|
};
|
|
675
509
|
break;
|
|
676
|
-
|
|
677
510
|
case 'TOP_RIGHT':
|
|
678
511
|
currentItem.value = {
|
|
679
512
|
type: 'rectangle',
|
|
@@ -687,7 +520,6 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
687
520
|
}
|
|
688
521
|
};
|
|
689
522
|
break;
|
|
690
|
-
|
|
691
523
|
case 'BOTTOM_LEFT':
|
|
692
524
|
currentItem.value = {
|
|
693
525
|
type: 'rectangle',
|
|
@@ -701,7 +533,6 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
701
533
|
}
|
|
702
534
|
};
|
|
703
535
|
break;
|
|
704
|
-
|
|
705
536
|
case 'BOTTOM_RIGHT':
|
|
706
537
|
currentItem.value = {
|
|
707
538
|
type: 'rectangle',
|
|
@@ -715,7 +546,6 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
715
546
|
}
|
|
716
547
|
};
|
|
717
548
|
break;
|
|
718
|
-
|
|
719
549
|
case 'CENTER':
|
|
720
550
|
currentItem.value = {
|
|
721
551
|
type: 'rectangle',
|
|
@@ -743,19 +573,15 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
743
573
|
}
|
|
744
574
|
};
|
|
745
575
|
}
|
|
746
|
-
|
|
747
576
|
break;
|
|
748
|
-
|
|
749
577
|
case 'singleHead':
|
|
750
578
|
case 'doubleHead':
|
|
751
579
|
if (((_initialItem$value17 = initialItem.value) === null || _initialItem$value17 === void 0 ? void 0 : _initialItem$value17.type) === currentItem.value.type) {
|
|
752
580
|
var _initialItem$value18, _initialItem$value19, _initialItem$value20, _initialItem$value21, _initialItem$value22, _initialItem$value23, _initialItem$value24, _initialItem$value25, _initialItem$value26, _initialItem$value27, _initialItem$value28, _initialItem$value29;
|
|
753
|
-
|
|
754
581
|
const x1 = typeof ((_initialItem$value18 = initialItem.value) === null || _initialItem$value18 === void 0 ? void 0 : _initialItem$value18.data.x1) === 'string' ? parseFloat((_initialItem$value19 = initialItem.value) === null || _initialItem$value19 === void 0 ? void 0 : _initialItem$value19.data.x1) : ((_initialItem$value20 = initialItem.value) === null || _initialItem$value20 === void 0 ? void 0 : _initialItem$value20.data.x1) || 0;
|
|
755
582
|
const y1 = typeof ((_initialItem$value21 = initialItem.value) === null || _initialItem$value21 === void 0 ? void 0 : _initialItem$value21.data.y1) === 'string' ? parseFloat((_initialItem$value22 = initialItem.value) === null || _initialItem$value22 === void 0 ? void 0 : _initialItem$value22.data.y1) : ((_initialItem$value23 = initialItem.value) === null || _initialItem$value23 === void 0 ? void 0 : _initialItem$value23.data.y1) || 0;
|
|
756
583
|
const x2 = typeof ((_initialItem$value24 = initialItem.value) === null || _initialItem$value24 === void 0 ? void 0 : _initialItem$value24.data.x2) === 'string' ? parseFloat((_initialItem$value25 = initialItem.value) === null || _initialItem$value25 === void 0 ? void 0 : _initialItem$value25.data.x2) : ((_initialItem$value26 = initialItem.value) === null || _initialItem$value26 === void 0 ? void 0 : _initialItem$value26.data.x2) || 0;
|
|
757
584
|
const y2 = typeof ((_initialItem$value27 = initialItem.value) === null || _initialItem$value27 === void 0 ? void 0 : _initialItem$value27.data.y2) === 'string' ? parseFloat((_initialItem$value28 = initialItem.value) === null || _initialItem$value28 === void 0 ? void 0 : _initialItem$value28.data.y2) : ((_initialItem$value29 = initialItem.value) === null || _initialItem$value29 === void 0 ? void 0 : _initialItem$value29.data.y2) || 0;
|
|
758
|
-
|
|
759
585
|
switch (zone) {
|
|
760
586
|
case 'TOP':
|
|
761
587
|
currentItem.value = {
|
|
@@ -770,7 +596,6 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
770
596
|
}
|
|
771
597
|
};
|
|
772
598
|
break;
|
|
773
|
-
|
|
774
599
|
case 'BOTTOM':
|
|
775
600
|
currentItem.value = {
|
|
776
601
|
type: currentItem.value.type,
|
|
@@ -784,7 +609,6 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
784
609
|
}
|
|
785
610
|
};
|
|
786
611
|
break;
|
|
787
|
-
|
|
788
612
|
case 'CENTER':
|
|
789
613
|
currentItem.value = {
|
|
790
614
|
type: currentItem.value.type,
|
|
@@ -812,18 +636,14 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
812
636
|
}
|
|
813
637
|
};
|
|
814
638
|
}
|
|
815
|
-
|
|
816
639
|
break;
|
|
817
|
-
|
|
818
640
|
case 'text':
|
|
819
641
|
if (((_initialItem$value30 = initialItem.value) === null || _initialItem$value30 === void 0 ? void 0 : _initialItem$value30.type) === currentItem.value.type) {
|
|
820
642
|
var _initialItem$value31, _initialItem$value32, _initialItem$value33, _initialItem$value34, _initialItem$value35, _initialItem$value36, _initialItem$value37, _initialItem$value38, _initialItem$value39, _initialItem$value40, _initialItem$value41, _initialItem$value42;
|
|
821
|
-
|
|
822
643
|
const xText = typeof ((_initialItem$value31 = initialItem.value) === null || _initialItem$value31 === void 0 ? void 0 : _initialItem$value31.data.x) === 'string' ? parseFloat((_initialItem$value32 = initialItem.value) === null || _initialItem$value32 === void 0 ? void 0 : _initialItem$value32.data.x) : ((_initialItem$value33 = initialItem.value) === null || _initialItem$value33 === void 0 ? void 0 : _initialItem$value33.data.x) || 0;
|
|
823
644
|
const yText = typeof ((_initialItem$value34 = initialItem.value) === null || _initialItem$value34 === void 0 ? void 0 : _initialItem$value34.data.y) === 'string' ? parseFloat((_initialItem$value35 = initialItem.value) === null || _initialItem$value35 === void 0 ? void 0 : _initialItem$value35.data.y) : ((_initialItem$value36 = initialItem.value) === null || _initialItem$value36 === void 0 ? void 0 : _initialItem$value36.data.y) || 0;
|
|
824
645
|
const widthText = typeof ((_initialItem$value37 = initialItem.value) === null || _initialItem$value37 === void 0 ? void 0 : _initialItem$value37.data.width) === 'string' ? parseFloat((_initialItem$value38 = initialItem.value) === null || _initialItem$value38 === void 0 ? void 0 : _initialItem$value38.data.width) : ((_initialItem$value39 = initialItem.value) === null || _initialItem$value39 === void 0 ? void 0 : _initialItem$value39.data.width) || 0;
|
|
825
646
|
const heightText = typeof ((_initialItem$value40 = initialItem.value) === null || _initialItem$value40 === void 0 ? void 0 : _initialItem$value40.data.height) === 'string' ? parseFloat((_initialItem$value41 = initialItem.value) === null || _initialItem$value41 === void 0 ? void 0 : _initialItem$value41.data.height) : ((_initialItem$value42 = initialItem.value) === null || _initialItem$value42 === void 0 ? void 0 : _initialItem$value42.data.height) || 0;
|
|
826
|
-
|
|
827
647
|
switch (zone) {
|
|
828
648
|
case 'LEFT':
|
|
829
649
|
currentItem.value = {
|
|
@@ -839,7 +659,6 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
839
659
|
}
|
|
840
660
|
};
|
|
841
661
|
break;
|
|
842
|
-
|
|
843
662
|
case 'RIGHT':
|
|
844
663
|
currentItem.value = {
|
|
845
664
|
type: currentItem.value.type,
|
|
@@ -854,7 +673,6 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
854
673
|
}
|
|
855
674
|
};
|
|
856
675
|
break;
|
|
857
|
-
|
|
858
676
|
case 'CENTER':
|
|
859
677
|
currentItem.value = {
|
|
860
678
|
type: currentItem.value.type,
|
|
@@ -884,36 +702,22 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
884
702
|
}
|
|
885
703
|
};
|
|
886
704
|
}
|
|
887
|
-
|
|
888
705
|
}
|
|
889
706
|
},
|
|
890
707
|
onEnd: _event => {
|
|
891
708
|
var _currentItem$value5;
|
|
892
|
-
|
|
893
|
-
panPosition.value = withTiming(0);
|
|
894
|
-
|
|
895
709
|
if (((_currentItem$value5 = currentItem.value) === null || _currentItem$value5 === void 0 ? void 0 : _currentItem$value5.type) === 'text') {
|
|
896
|
-
var _currentItem$value$te;
|
|
897
|
-
|
|
898
710
|
runOnJS(textFocus)();
|
|
899
711
|
currentItem.value = {
|
|
900
712
|
type: currentItem.value.type,
|
|
901
713
|
strokeWidth: currentItem.value.strokeWidth,
|
|
902
714
|
color: currentItem.value.color,
|
|
903
715
|
data: currentItem.value.data,
|
|
904
|
-
text: currentItem.value.text !== DEFAULT_TEXT ?
|
|
716
|
+
text: currentItem.value.text !== DEFAULT_TEXT ? currentItem.value.text ?? '' : ''
|
|
905
717
|
};
|
|
906
718
|
}
|
|
907
|
-
|
|
908
719
|
runOnJS(addScreenStates)(currentItem.value);
|
|
909
720
|
}
|
|
910
|
-
}, []);
|
|
911
|
-
const rightPaneStyle = useAnimatedStyle(() => {
|
|
912
|
-
return {
|
|
913
|
-
transform: [{
|
|
914
|
-
translateX: panPosition.value
|
|
915
|
-
}]
|
|
916
|
-
};
|
|
917
721
|
});
|
|
918
722
|
useEffect(() => {
|
|
919
723
|
const sudDidHide = Keyboard.addListener('keyboardDidHide', () => {
|
|
@@ -924,8 +728,9 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
924
728
|
if (event.endCoordinates.height > 100) {
|
|
925
729
|
showTextInput.value = true;
|
|
926
730
|
}
|
|
927
|
-
});
|
|
731
|
+
});
|
|
928
732
|
|
|
733
|
+
// cleanup function
|
|
929
734
|
return () => {
|
|
930
735
|
sudDidShow.remove();
|
|
931
736
|
sudDidHide.remove();
|
|
@@ -935,13 +740,14 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
935
740
|
const textInputContainerStyle = useAnimatedStyle(() => {
|
|
936
741
|
return {
|
|
937
742
|
height: 'auto',
|
|
938
|
-
backgroundColor: '
|
|
743
|
+
backgroundColor: 'red',
|
|
939
744
|
display: 'flex',
|
|
940
745
|
opacity: showTextInput.value ? withTiming(1) : withTiming(0)
|
|
941
746
|
};
|
|
942
747
|
}, [showTextInput.value]);
|
|
943
748
|
const textInputStyle = useAnimatedStyle(() => {
|
|
944
749
|
return {
|
|
750
|
+
backgroundColor: 'blue',
|
|
945
751
|
display: showTextInput.value ? 'flex' : 'none',
|
|
946
752
|
opacity: showTextInput.value ? withTiming(1) : withTiming(0)
|
|
947
753
|
};
|
|
@@ -949,16 +755,14 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
949
755
|
useAnimatedReaction(() => {
|
|
950
756
|
return {
|
|
951
757
|
strokeWidth: strokeWidth.value,
|
|
952
|
-
color: color.value
|
|
758
|
+
color: color === null || color === void 0 ? void 0 : color.value
|
|
953
759
|
};
|
|
954
760
|
}, _ref4 => {
|
|
955
761
|
var _currentItem$value6;
|
|
956
|
-
|
|
957
762
|
let {
|
|
958
763
|
strokeWidth: sw,
|
|
959
764
|
color: c
|
|
960
765
|
} = _ref4;
|
|
961
|
-
|
|
962
766
|
switch ((_currentItem$value6 = currentItem.value) === null || _currentItem$value6 === void 0 ? void 0 : _currentItem$value6.type) {
|
|
963
767
|
case 'singleHead':
|
|
964
768
|
currentItem.value = {
|
|
@@ -968,7 +772,6 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
968
772
|
color: c
|
|
969
773
|
};
|
|
970
774
|
break;
|
|
971
|
-
|
|
972
775
|
case 'doubleHead':
|
|
973
776
|
currentItem.value = {
|
|
974
777
|
type: currentItem.value.type,
|
|
@@ -977,7 +780,6 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
977
780
|
color: c
|
|
978
781
|
};
|
|
979
782
|
break;
|
|
980
|
-
|
|
981
783
|
case 'ellipse':
|
|
982
784
|
currentItem.value = {
|
|
983
785
|
type: currentItem.value.type,
|
|
@@ -986,7 +788,6 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
986
788
|
color: c
|
|
987
789
|
};
|
|
988
790
|
break;
|
|
989
|
-
|
|
990
791
|
case 'rectangle':
|
|
991
792
|
currentItem.value = {
|
|
992
793
|
type: currentItem.value.type,
|
|
@@ -995,7 +796,6 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
995
796
|
color: c
|
|
996
797
|
};
|
|
997
798
|
break;
|
|
998
|
-
|
|
999
799
|
case 'pen':
|
|
1000
800
|
currentItem.value = {
|
|
1001
801
|
type: currentItem.value.type,
|
|
@@ -1004,7 +804,6 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
1004
804
|
color: c
|
|
1005
805
|
};
|
|
1006
806
|
break;
|
|
1007
|
-
|
|
1008
807
|
case 'text':
|
|
1009
808
|
currentItem.value = {
|
|
1010
809
|
type: currentItem.value.type,
|
|
@@ -1015,29 +814,24 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
1015
814
|
};
|
|
1016
815
|
break;
|
|
1017
816
|
}
|
|
1018
|
-
}, [strokeWidth.value, color.value]);
|
|
817
|
+
}, [strokeWidth.value, color === null || color === void 0 ? void 0 : color.value]);
|
|
1019
818
|
const onPressItem = useCallback((item, index) => () => {
|
|
1020
|
-
|
|
819
|
+
itemIsSelected.value = true;
|
|
1021
820
|
const previousItem = currentItem.value;
|
|
1022
821
|
strokeWidth.value = item.strokeWidth;
|
|
1023
822
|
color.value = item.color;
|
|
1024
823
|
currentItem.value = item;
|
|
1025
824
|
deleteDoneItem(index);
|
|
1026
|
-
|
|
1027
825
|
if (previousItem) {
|
|
1028
826
|
addDoneItem(previousItem);
|
|
1029
827
|
}
|
|
1030
|
-
|
|
1031
828
|
if (item.type === 'text') {
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
setTextVal((_item$text = item.text) !== null && _item$text !== void 0 ? _item$text : '');
|
|
829
|
+
setTextVal(item.text ?? '');
|
|
1035
830
|
} else {
|
|
1036
831
|
var _textInputRef$current2;
|
|
1037
|
-
|
|
1038
832
|
(_textInputRef$current2 = textInputRef.current) === null || _textInputRef$current2 === void 0 ? void 0 : _textInputRef$current2.blur();
|
|
1039
833
|
}
|
|
1040
|
-
}, [
|
|
834
|
+
}, [itemIsSelected, currentItem, strokeWidth, color, deleteDoneItem, addDoneItem]);
|
|
1041
835
|
const onTextHeightChange = useCallback(height => {
|
|
1042
836
|
onTextHeightUpdate(currentItem, textBaseHeight, height);
|
|
1043
837
|
}, [currentItem, textBaseHeight]);
|
|
@@ -1048,7 +842,6 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
1048
842
|
height: imageHeight
|
|
1049
843
|
});
|
|
1050
844
|
const ratioImageHeight = Math.round(imageHeight * drawRegion.width / imageWidth * 100) / 100;
|
|
1051
|
-
|
|
1052
845
|
if (ratioImageHeight < drawRegion.height) {
|
|
1053
846
|
setImageSize({
|
|
1054
847
|
width: drawRegion.width,
|
|
@@ -1078,7 +871,7 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
1078
871
|
style: styles.container
|
|
1079
872
|
}, /*#__PURE__*/React.createElement(View, {
|
|
1080
873
|
style: [styles.drawZone, {
|
|
1081
|
-
backgroundColor: backgroundColor
|
|
874
|
+
backgroundColor: backgroundColor ?? 'none'
|
|
1082
875
|
}],
|
|
1083
876
|
onLayout: event => {
|
|
1084
877
|
setDrawRegion({
|
|
@@ -1104,7 +897,7 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
1104
897
|
style: styles.bgImage
|
|
1105
898
|
}, /*#__PURE__*/React.createElement(DrawPad, {
|
|
1106
899
|
currentItem: currentItem,
|
|
1107
|
-
doneItems:
|
|
900
|
+
doneItems: drawState.doneItems,
|
|
1108
901
|
onPressItem: onPressItem,
|
|
1109
902
|
onTextHeightChange: onTextHeightChange
|
|
1110
903
|
}))) : null : drawRegion ? /*#__PURE__*/React.createElement(ViewShot, {
|
|
@@ -1117,25 +910,10 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
1117
910
|
style: drawRegion
|
|
1118
911
|
}, /*#__PURE__*/React.createElement(DrawPad, {
|
|
1119
912
|
currentItem: currentItem,
|
|
1120
|
-
doneItems:
|
|
913
|
+
doneItems: drawState.doneItems,
|
|
1121
914
|
onPressItem: onPressItem,
|
|
1122
915
|
onTextHeightChange: onTextHeightChange
|
|
1123
|
-
})) : null))), /*#__PURE__*/React.createElement(
|
|
1124
|
-
style: [styles.rightPaneBaseStyle, rightPaneStyle]
|
|
1125
|
-
}, /*#__PURE__*/React.createElement(View, {
|
|
1126
|
-
style: styles.strokeSliderContainer
|
|
1127
|
-
}, /*#__PURE__*/React.createElement(StrokeSlider, {
|
|
1128
|
-
minValue: 2,
|
|
1129
|
-
maxValue: 10,
|
|
1130
|
-
stroke: strokeWidth,
|
|
1131
|
-
onStrokeChange: onColorStrokeChange
|
|
1132
|
-
})), /*#__PURE__*/React.createElement(View, {
|
|
1133
|
-
style: styles.colorSliderContainer
|
|
1134
|
-
}, /*#__PURE__*/React.createElement(ColorSlider, {
|
|
1135
|
-
color: color,
|
|
1136
|
-
linearGradient: linearGradient,
|
|
1137
|
-
onColorChange: onColorStrokeChange
|
|
1138
|
-
})))), Platform.OS === 'ios' ? /*#__PURE__*/React.createElement(InputAccessoryView, null, /*#__PURE__*/React.createElement(AnimatedTextInput, {
|
|
916
|
+
})) : null)))), Platform.OS === 'ios' ? /*#__PURE__*/React.createElement(InputAccessoryView, null, /*#__PURE__*/React.createElement(AnimatedTextInput, {
|
|
1139
917
|
ref: textInputRef,
|
|
1140
918
|
style: [styles.textInput, textInputStyle],
|
|
1141
919
|
onEndEditing: (_textInputRef$current3 = textInputRef.current) === null || _textInputRef$current3 === void 0 ? void 0 : _textInputRef$current3.clear,
|
|
@@ -1152,6 +930,6 @@ const DrawCore = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
1152
930
|
value: textVal,
|
|
1153
931
|
autoCorrect: false
|
|
1154
932
|
})));
|
|
1155
|
-
}
|
|
933
|
+
};
|
|
1156
934
|
export default DrawCore;
|
|
1157
935
|
//# sourceMappingURL=index.js.map
|