react-native-skia-gesture 0.2.0 → 0.3.2
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 +77 -20
- package/lib/commonjs/canvas/canvas.js +68 -56
- package/lib/commonjs/canvas/canvas.js.map +1 -1
- package/lib/commonjs/canvas/context.js +1 -1
- package/lib/commonjs/canvas/context.js.map +1 -1
- package/lib/commonjs/components/index.js +4 -4
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/hoc/with-touchable-handler.js +29 -34
- package/lib/commonjs/hoc/with-touchable-handler.js.map +1 -1
- package/lib/commonjs/hooks/use-gesture-handler.js +11 -5
- package/lib/commonjs/hooks/use-gesture-handler.js.map +1 -1
- package/lib/commonjs/index.js +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils/get-circle-path.js +2 -0
- package/lib/commonjs/utils/get-circle-path.js.map +1 -1
- package/lib/commonjs/utils/get-rect-path.js +8 -5
- package/lib/commonjs/utils/get-rect-path.js.map +1 -1
- package/lib/commonjs/utils/unwrap-animated-value.js +7 -0
- package/lib/commonjs/utils/unwrap-animated-value.js.map +1 -1
- package/lib/module/canvas/canvas.js +70 -58
- package/lib/module/canvas/canvas.js.map +1 -1
- package/lib/module/canvas/context.js +1 -1
- package/lib/module/canvas/context.js.map +1 -1
- package/lib/module/components/index.js +4 -4
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/hoc/with-touchable-handler.js +28 -34
- package/lib/module/hoc/with-touchable-handler.js.map +1 -1
- package/lib/module/hooks/use-gesture-handler.js +11 -5
- package/lib/module/hooks/use-gesture-handler.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/get-circle-path.js +2 -0
- package/lib/module/utils/get-circle-path.js.map +1 -1
- package/lib/module/utils/get-rect-path.js +9 -6
- package/lib/module/utils/get-rect-path.js.map +1 -1
- package/lib/module/utils/unwrap-animated-value.js +7 -0
- package/lib/module/utils/unwrap-animated-value.js.map +1 -1
- package/lib/typescript/canvas/canvas.d.ts +7 -2
- package/lib/typescript/canvas/canvas.d.ts.map +1 -1
- package/lib/typescript/canvas/context.d.ts +6 -5
- package/lib/typescript/canvas/context.d.ts.map +1 -1
- package/lib/typescript/components/index.d.ts +2 -2
- package/lib/typescript/components/index.d.ts.map +1 -1
- package/lib/typescript/hoc/with-touchable-handler.d.ts +7 -9
- package/lib/typescript/hoc/with-touchable-handler.d.ts.map +1 -1
- package/lib/typescript/hooks/use-gesture-handler.d.ts +7 -8
- package/lib/typescript/hooks/use-gesture-handler.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +1 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/utils/get-circle-path.d.ts.map +1 -1
- package/lib/typescript/utils/get-rect-path.d.ts.map +1 -1
- package/lib/typescript/utils/unwrap-animated-value.d.ts +2 -1
- package/lib/typescript/utils/unwrap-animated-value.d.ts.map +1 -1
- package/package.json +6 -4
- package/src/canvas/canvas.tsx +109 -81
- package/src/canvas/context.tsx +19 -10
- package/src/components/index.ts +5 -4
- package/src/hoc/with-touchable-handler.tsx +40 -35
- package/src/hooks/use-gesture-handler.ts +25 -16
- package/src/index.ts +1 -1
- package/src/utils/get-circle-path.ts +1 -0
- package/src/utils/get-rect-path.ts +11 -6
- package/src/utils/unwrap-animated-value.ts +9 -1
@@ -1,19 +1,23 @@
|
|
1
|
-
import {
|
2
|
-
type ExtendedTouchInfo,
|
3
|
-
type TouchInfo,
|
4
|
-
useValue,
|
5
|
-
} from '@shopify/react-native-skia';
|
6
1
|
import { useCallback } from 'react';
|
7
|
-
import
|
2
|
+
import { useSharedValue } from 'react-native-reanimated';
|
3
|
+
|
4
|
+
import type {
|
5
|
+
GestureStateChangeEvent,
|
6
|
+
GestureUpdateEvent,
|
7
|
+
PanGestureHandlerEventPayload,
|
8
|
+
} from 'react-native-gesture-handler';
|
8
9
|
|
9
10
|
type UseGestureHandlerParams<ContextType> = {
|
10
|
-
onStart?: (
|
11
|
+
onStart?: (
|
12
|
+
touchInfo: GestureStateChangeEvent<PanGestureHandlerEventPayload>,
|
13
|
+
context: ContextType
|
14
|
+
) => void;
|
11
15
|
onActive?: (
|
12
|
-
|
16
|
+
touchInfo: GestureUpdateEvent<PanGestureHandlerEventPayload>,
|
13
17
|
context: ContextType
|
14
18
|
) => void;
|
15
19
|
onEnd?: (
|
16
|
-
|
20
|
+
touchInfo: GestureStateChangeEvent<PanGestureHandlerEventPayload>,
|
17
21
|
context: ContextType
|
18
22
|
) => void;
|
19
23
|
};
|
@@ -23,28 +27,33 @@ const useGestureHandler = <ContextType>(
|
|
23
27
|
) => {
|
24
28
|
const { onStart, onActive, onEnd } = gestureHandlers;
|
25
29
|
|
26
|
-
const context =
|
30
|
+
const context = useSharedValue<ContextType>({} as any);
|
27
31
|
|
28
32
|
const handleStart = useCallback(
|
29
|
-
(touchInfo:
|
33
|
+
(touchInfo: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => {
|
34
|
+
'worklet';
|
30
35
|
if (!onStart) return;
|
31
|
-
return onStart(touchInfo, context.
|
36
|
+
return onStart(touchInfo, context.value);
|
32
37
|
},
|
33
38
|
[context, onStart]
|
34
39
|
);
|
35
40
|
|
36
41
|
const handleActive = useCallback(
|
37
|
-
(extendedTouchInfo:
|
42
|
+
(extendedTouchInfo: GestureUpdateEvent<PanGestureHandlerEventPayload>) => {
|
43
|
+
'worklet';
|
38
44
|
if (!onActive) return;
|
39
|
-
return onActive(extendedTouchInfo, context.
|
45
|
+
return onActive(extendedTouchInfo, context.value);
|
40
46
|
},
|
41
47
|
[context, onActive]
|
42
48
|
);
|
43
49
|
|
44
50
|
const handleEnd = useCallback(
|
45
|
-
(
|
51
|
+
(
|
52
|
+
extendedTouchInfo: GestureStateChangeEvent<PanGestureHandlerEventPayload>
|
53
|
+
) => {
|
54
|
+
'worklet';
|
46
55
|
if (!onEnd) return;
|
47
|
-
return onEnd(extendedTouchInfo, context.
|
56
|
+
return onEnd(extendedTouchInfo, context.value);
|
48
57
|
},
|
49
58
|
[context, onEnd]
|
50
59
|
);
|
package/src/index.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { Skia, type SkRect } from '@shopify/react-native-skia';
|
2
2
|
|
3
3
|
type GetRectPathParams =
|
4
4
|
| {
|
@@ -10,16 +10,18 @@ type GetRectPathParams =
|
|
10
10
|
| { rect: SkRect };
|
11
11
|
|
12
12
|
const getRectPath = (params: GetRectPathParams) => {
|
13
|
+
'worklet';
|
14
|
+
|
13
15
|
const skPath = Skia.Path.Make();
|
14
16
|
if ('rect' in params) {
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
16
17
|
const { rect } = params;
|
17
18
|
|
18
19
|
skPath.addRect(rect);
|
19
20
|
return skPath;
|
20
21
|
}
|
21
22
|
const { x, y, width, height } = params;
|
22
|
-
|
23
|
+
|
24
|
+
skPath.addRect(Skia.XYWHRect(x, y, width, height));
|
23
25
|
return skPath;
|
24
26
|
};
|
25
27
|
|
@@ -28,17 +30,20 @@ type GetRoundedRectPathParams = GetRectPathParams & {
|
|
28
30
|
};
|
29
31
|
|
30
32
|
const getRoundedRectPath = (params: GetRoundedRectPathParams) => {
|
33
|
+
'worklet';
|
34
|
+
|
31
35
|
const { r } = params;
|
32
36
|
const skPath = Skia.Path.Make();
|
33
37
|
if ('rect' in params) {
|
34
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
35
38
|
const { rect } = params;
|
36
|
-
|
39
|
+
|
40
|
+
skPath.addRRect(Skia.RRectXY(rect, r, r));
|
37
41
|
return skPath;
|
38
42
|
}
|
39
43
|
const { x, y, width, height } = params;
|
40
44
|
|
41
|
-
|
45
|
+
const roundedRect = Skia.RRectXY(Skia.XYWHRect(x, y, width, height), r, r);
|
46
|
+
skPath.addRRect(roundedRect);
|
42
47
|
return skPath;
|
43
48
|
};
|
44
49
|
|
@@ -1,12 +1,19 @@
|
|
1
1
|
import type { SkiaValue } from '@shopify/react-native-skia';
|
2
|
+
import type Animated from 'react-native-reanimated';
|
2
3
|
|
3
4
|
type SkiaValueWithSelector<T> = {
|
4
5
|
value: SkiaValue<T>;
|
5
6
|
selector: (v: T) => T;
|
6
7
|
};
|
7
8
|
const unwrapAnimatedValue = <T>(
|
8
|
-
value: SkiaValue<T> | SkiaValueWithSelector<T> | T
|
9
|
+
value: SkiaValue<T> | SkiaValueWithSelector<T> | Animated.SharedValue<T> | T
|
9
10
|
): T => {
|
11
|
+
'worklet';
|
12
|
+
|
13
|
+
if ((value as Animated.SharedValue<T>).value != null) {
|
14
|
+
return (value as Animated.SharedValue<T>).value as T;
|
15
|
+
}
|
16
|
+
|
10
17
|
if ((value as SkiaValue<T>).current != null) {
|
11
18
|
return (value as SkiaValue<T>).current;
|
12
19
|
}
|
@@ -22,6 +29,7 @@ const unwrapAnimatedValue = <T>(
|
|
22
29
|
const unwrapAnimatedValueObject = <T>(
|
23
30
|
value: Record<any, SkiaValue<T> | T>
|
24
31
|
): Record<any, T> => {
|
32
|
+
'worklet';
|
25
33
|
return Object.keys(value).reduce((acc, key) => {
|
26
34
|
return { ...acc, [key]: unwrapAnimatedValue(value[key]) };
|
27
35
|
}, {});
|