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.
Files changed (63) hide show
  1. package/README.md +77 -20
  2. package/lib/commonjs/canvas/canvas.js +68 -56
  3. package/lib/commonjs/canvas/canvas.js.map +1 -1
  4. package/lib/commonjs/canvas/context.js +1 -1
  5. package/lib/commonjs/canvas/context.js.map +1 -1
  6. package/lib/commonjs/components/index.js +4 -4
  7. package/lib/commonjs/components/index.js.map +1 -1
  8. package/lib/commonjs/hoc/with-touchable-handler.js +29 -34
  9. package/lib/commonjs/hoc/with-touchable-handler.js.map +1 -1
  10. package/lib/commonjs/hooks/use-gesture-handler.js +11 -5
  11. package/lib/commonjs/hooks/use-gesture-handler.js.map +1 -1
  12. package/lib/commonjs/index.js +1 -1
  13. package/lib/commonjs/index.js.map +1 -1
  14. package/lib/commonjs/utils/get-circle-path.js +2 -0
  15. package/lib/commonjs/utils/get-circle-path.js.map +1 -1
  16. package/lib/commonjs/utils/get-rect-path.js +8 -5
  17. package/lib/commonjs/utils/get-rect-path.js.map +1 -1
  18. package/lib/commonjs/utils/unwrap-animated-value.js +7 -0
  19. package/lib/commonjs/utils/unwrap-animated-value.js.map +1 -1
  20. package/lib/module/canvas/canvas.js +70 -58
  21. package/lib/module/canvas/canvas.js.map +1 -1
  22. package/lib/module/canvas/context.js +1 -1
  23. package/lib/module/canvas/context.js.map +1 -1
  24. package/lib/module/components/index.js +4 -4
  25. package/lib/module/components/index.js.map +1 -1
  26. package/lib/module/hoc/with-touchable-handler.js +28 -34
  27. package/lib/module/hoc/with-touchable-handler.js.map +1 -1
  28. package/lib/module/hooks/use-gesture-handler.js +11 -5
  29. package/lib/module/hooks/use-gesture-handler.js.map +1 -1
  30. package/lib/module/index.js +1 -1
  31. package/lib/module/index.js.map +1 -1
  32. package/lib/module/utils/get-circle-path.js +2 -0
  33. package/lib/module/utils/get-circle-path.js.map +1 -1
  34. package/lib/module/utils/get-rect-path.js +9 -6
  35. package/lib/module/utils/get-rect-path.js.map +1 -1
  36. package/lib/module/utils/unwrap-animated-value.js +7 -0
  37. package/lib/module/utils/unwrap-animated-value.js.map +1 -1
  38. package/lib/typescript/canvas/canvas.d.ts +7 -2
  39. package/lib/typescript/canvas/canvas.d.ts.map +1 -1
  40. package/lib/typescript/canvas/context.d.ts +6 -5
  41. package/lib/typescript/canvas/context.d.ts.map +1 -1
  42. package/lib/typescript/components/index.d.ts +2 -2
  43. package/lib/typescript/components/index.d.ts.map +1 -1
  44. package/lib/typescript/hoc/with-touchable-handler.d.ts +7 -9
  45. package/lib/typescript/hoc/with-touchable-handler.d.ts.map +1 -1
  46. package/lib/typescript/hooks/use-gesture-handler.d.ts +7 -8
  47. package/lib/typescript/hooks/use-gesture-handler.d.ts.map +1 -1
  48. package/lib/typescript/index.d.ts +1 -1
  49. package/lib/typescript/index.d.ts.map +1 -1
  50. package/lib/typescript/utils/get-circle-path.d.ts.map +1 -1
  51. package/lib/typescript/utils/get-rect-path.d.ts.map +1 -1
  52. package/lib/typescript/utils/unwrap-animated-value.d.ts +2 -1
  53. package/lib/typescript/utils/unwrap-animated-value.d.ts.map +1 -1
  54. package/package.json +6 -4
  55. package/src/canvas/canvas.tsx +109 -81
  56. package/src/canvas/context.tsx +19 -10
  57. package/src/components/index.ts +5 -4
  58. package/src/hoc/with-touchable-handler.tsx +40 -35
  59. package/src/hooks/use-gesture-handler.ts +25 -16
  60. package/src/index.ts +1 -1
  61. package/src/utils/get-circle-path.ts +1 -0
  62. package/src/utils/get-rect-path.ts +11 -6
  63. 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 type { TranslationInfo } from '../hoc';
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?: (touchInfo: TouchInfo, context: ContextType) => void;
11
+ onStart?: (
12
+ touchInfo: GestureStateChangeEvent<PanGestureHandlerEventPayload>,
13
+ context: ContextType
14
+ ) => void;
11
15
  onActive?: (
12
- extendedTouchInfo: ExtendedTouchInfo & TranslationInfo,
16
+ touchInfo: GestureUpdateEvent<PanGestureHandlerEventPayload>,
13
17
  context: ContextType
14
18
  ) => void;
15
19
  onEnd?: (
16
- extendedTouchInfo: ExtendedTouchInfo & TranslationInfo,
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 = useValue<ContextType>({} as any);
30
+ const context = useSharedValue<ContextType>({} as any);
27
31
 
28
32
  const handleStart = useCallback(
29
- (touchInfo: TouchInfo) => {
33
+ (touchInfo: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => {
34
+ 'worklet';
30
35
  if (!onStart) return;
31
- return onStart(touchInfo, context.current);
36
+ return onStart(touchInfo, context.value);
32
37
  },
33
38
  [context, onStart]
34
39
  );
35
40
 
36
41
  const handleActive = useCallback(
37
- (extendedTouchInfo: ExtendedTouchInfo & TranslationInfo) => {
42
+ (extendedTouchInfo: GestureUpdateEvent<PanGestureHandlerEventPayload>) => {
43
+ 'worklet';
38
44
  if (!onActive) return;
39
- return onActive(extendedTouchInfo, context.current);
45
+ return onActive(extendedTouchInfo, context.value);
40
46
  },
41
47
  [context, onActive]
42
48
  );
43
49
 
44
50
  const handleEnd = useCallback(
45
- (extendedTouchInfo: ExtendedTouchInfo & TranslationInfo) => {
51
+ (
52
+ extendedTouchInfo: GestureStateChangeEvent<PanGestureHandlerEventPayload>
53
+ ) => {
54
+ 'worklet';
46
55
  if (!onEnd) return;
47
- return onEnd(extendedTouchInfo, context.current);
56
+ return onEnd(extendedTouchInfo, context.value);
48
57
  },
49
58
  [context, onEnd]
50
59
  );
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
+ import * as Touchable from './components';
1
2
  export * from './hoc';
2
3
  export * from './hooks/use-gesture-handler';
3
- import * as Touchable from './components';
4
4
 
5
5
  export default Touchable;
@@ -3,5 +3,6 @@ import { Skia } from '@shopify/react-native-skia';
3
3
  type GetCirclePathParams = { cx: number; cy: number; r: number };
4
4
 
5
5
  export const getCirclePath = ({ cx, cy, r }: GetCirclePathParams) => {
6
+ 'worklet';
6
7
  return Skia.Path.Make().addCircle(cx, cy, r);
7
8
  };
@@ -1,4 +1,4 @@
1
- import { rect, rrect, Skia, type SkRect } from '@shopify/react-native-skia';
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
- skPath.addRect(rect(x, y, width, height));
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
- skPath.addRRect(rrect(rect, r, r));
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
- skPath.addRRect(rrect(rect(x, y, width, height), r, r));
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
  }, {});