@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.
- package/LICENSE +1 -1
- package/README.md +9 -2
- package/lib/commonjs/components/DrawCore/CurrentAnimatedItem.js +159 -148
- package/lib/commonjs/components/DrawCore/CurrentAnimatedItem.js.map +1 -1
- package/lib/commonjs/components/DrawCore/CurrentAnimatedText.js +18 -17
- package/lib/commonjs/components/DrawCore/CurrentAnimatedText.js.map +1 -1
- package/lib/commonjs/components/DrawCore/DrawPad.js +2 -2
- package/lib/commonjs/components/DrawCore/DrawPad.js.map +1 -1
- package/lib/commonjs/components/DrawCore/index.js +54 -14
- package/lib/commonjs/components/DrawCore/index.js.map +1 -1
- package/lib/commonjs/components/DrawCore/useDrawHook.js +1 -3
- package/lib/commonjs/components/DrawCore/useDrawHook.js.map +1 -1
- package/lib/commonjs/components/DrawWithOptions/index.js +6 -2
- package/lib/commonjs/components/DrawWithOptions/index.js.map +1 -1
- package/lib/commonjs/components/Slider/ColorSlider.js +18 -30
- package/lib/commonjs/components/Slider/ColorSlider.js.map +1 -1
- package/lib/commonjs/components/Slider/Sliders.js +1 -1
- package/lib/commonjs/components/Slider/Sliders.js.map +1 -1
- package/lib/commonjs/components/Slider/StrokeSlider.js +11 -23
- package/lib/commonjs/components/Slider/StrokeSlider.js.map +1 -1
- package/lib/module/components/DrawCore/CurrentAnimatedItem.js +158 -148
- package/lib/module/components/DrawCore/CurrentAnimatedItem.js.map +1 -1
- package/lib/module/components/DrawCore/CurrentAnimatedText.js +19 -18
- package/lib/module/components/DrawCore/CurrentAnimatedText.js.map +1 -1
- package/lib/module/components/DrawCore/DrawPad.js +2 -2
- package/lib/module/components/DrawCore/DrawPad.js.map +1 -1
- package/lib/module/components/DrawCore/index.js +54 -14
- package/lib/module/components/DrawCore/index.js.map +1 -1
- package/lib/module/components/DrawCore/useDrawHook.js +1 -3
- package/lib/module/components/DrawCore/useDrawHook.js.map +1 -1
- package/lib/module/components/DrawWithOptions/index.js +6 -2
- package/lib/module/components/DrawWithOptions/index.js.map +1 -1
- package/lib/module/components/Slider/ColorSlider.js +20 -32
- package/lib/module/components/Slider/ColorSlider.js.map +1 -1
- package/lib/module/components/Slider/Sliders.js +1 -1
- package/lib/module/components/Slider/Sliders.js.map +1 -1
- package/lib/module/components/Slider/StrokeSlider.js +13 -25
- package/lib/module/components/Slider/StrokeSlider.js.map +1 -1
- package/lib/typescript/components/DrawCore/CurrentAnimatedItem.d.ts +1 -0
- package/lib/typescript/components/DrawCore/CurrentAnimatedItem.d.ts.map +1 -1
- package/lib/typescript/components/DrawCore/CurrentAnimatedText.d.ts.map +1 -1
- package/lib/typescript/components/DrawCore/DrawPad.d.ts.map +1 -1
- package/lib/typescript/components/DrawCore/index.d.ts.map +1 -1
- package/lib/typescript/components/DrawCore/useDrawHook.d.ts.map +1 -1
- package/lib/typescript/components/DrawWithOptions/index.d.ts +3 -4
- package/lib/typescript/components/DrawWithOptions/index.d.ts.map +1 -1
- package/lib/typescript/components/Slider/ColorSlider.d.ts +2 -3
- package/lib/typescript/components/Slider/ColorSlider.d.ts.map +1 -1
- package/lib/typescript/components/Slider/Sliders.d.ts +2 -3
- package/lib/typescript/components/Slider/Sliders.d.ts.map +1 -1
- package/lib/typescript/components/Slider/StrokeSlider.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/DrawCore/CurrentAnimatedItem.tsx +285 -333
- package/src/components/DrawCore/CurrentAnimatedText.tsx +14 -11
- package/src/components/DrawCore/DrawPad.tsx +4 -1
- package/src/components/DrawCore/index.tsx +77 -25
- package/src/components/DrawCore/useDrawHook.tsx +1 -2
- package/src/components/DrawWithOptions/index.tsx +12 -4
- package/src/components/Slider/ColorSlider.tsx +42 -50
- package/src/components/Slider/Sliders.tsx +4 -4
- package/src/components/Slider/StrokeSlider.tsx +24 -33
- 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
|
-
|
|
57
|
-
|
|
58
|
-
currentItem.value?.type === 'text'
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
}
|
|
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
|
-
}
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
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 (
|
|
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:
|
|
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
|
-
|
|
1167
|
-
|
|
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={
|
|
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
|
|
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<
|
|
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
|
-
{
|
|
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
|
|
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 {
|
|
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<
|
|
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
|
-
}
|
|
65
|
+
});
|
|
69
66
|
|
|
70
67
|
const wrapperOnColorChange = () => {
|
|
71
68
|
onColorStrokeChange();
|
|
72
69
|
};
|
|
73
70
|
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
{
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
}
|
|
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
|
-
<
|
|
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
|
-
</
|
|
131
|
+
</GestureDetector>
|
|
140
132
|
</View>
|
|
141
133
|
);
|
|
142
134
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { View
|
|
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 {
|
|
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<
|
|
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
|
-
}
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
minValue
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
}
|
|
71
|
+
});
|
|
81
72
|
|
|
82
73
|
return (
|
|
83
74
|
<View style={sliderStyle.container}>
|
|
84
|
-
<
|
|
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
|
-
</
|
|
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 }
|