react-native-skia-gesture 0.1.6
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 +20 -0
- package/README.md +121 -0
- package/lib/commonjs/canvas/canvas.js +64 -0
- package/lib/commonjs/canvas/canvas.js.map +1 -0
- package/lib/commonjs/canvas/context.js +18 -0
- package/lib/commonjs/canvas/context.js.map +1 -0
- package/lib/commonjs/canvas/index.js +17 -0
- package/lib/commonjs/canvas/index.js.map +1 -0
- package/lib/commonjs/hoc/index.js +17 -0
- package/lib/commonjs/hoc/index.js.map +1 -0
- package/lib/commonjs/hoc/with-touchable-handler.js +94 -0
- package/lib/commonjs/hoc/with-touchable-handler.js.map +1 -0
- package/lib/commonjs/hooks/use-gesture-handler.js +35 -0
- package/lib/commonjs/hooks/use-gesture-handler.js.map +1 -0
- package/lib/commonjs/index.js +39 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/utils/get-circle-path.js +17 -0
- package/lib/commonjs/utils/get-circle-path.js.map +1 -0
- package/lib/commonjs/utils/get-rect-path.js +48 -0
- package/lib/commonjs/utils/get-rect-path.js.map +1 -0
- package/lib/commonjs/utils/unwrap-animated-value.js +23 -0
- package/lib/commonjs/utils/unwrap-animated-value.js.map +1 -0
- package/lib/module/canvas/canvas.js +56 -0
- package/lib/module/canvas/canvas.js.map +1 -0
- package/lib/module/canvas/context.js +9 -0
- package/lib/module/canvas/context.js.map +1 -0
- package/lib/module/canvas/index.js +2 -0
- package/lib/module/canvas/index.js.map +1 -0
- package/lib/module/hoc/index.js +2 -0
- package/lib/module/hoc/index.js.map +1 -0
- package/lib/module/hoc/with-touchable-handler.js +88 -0
- package/lib/module/hoc/with-touchable-handler.js.map +1 -0
- package/lib/module/hooks/use-gesture-handler.js +29 -0
- package/lib/module/hooks/use-gesture-handler.js.map +1 -0
- package/lib/module/index.js +4 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/utils/get-circle-path.js +10 -0
- package/lib/module/utils/get-circle-path.js.map +1 -0
- package/lib/module/utils/get-rect-path.js +41 -0
- package/lib/module/utils/get-rect-path.js.map +1 -0
- package/lib/module/utils/unwrap-animated-value.js +16 -0
- package/lib/module/utils/unwrap-animated-value.js.map +1 -0
- package/lib/typescript/canvas/canvas.d.ts +5 -0
- package/lib/typescript/canvas/canvas.d.ts.map +1 -0
- package/lib/typescript/canvas/context.d.ts +14 -0
- package/lib/typescript/canvas/context.d.ts.map +1 -0
- package/lib/typescript/canvas/index.d.ts +2 -0
- package/lib/typescript/canvas/index.d.ts.map +1 -0
- package/lib/typescript/hoc/index.d.ts +2 -0
- package/lib/typescript/hoc/index.d.ts.map +1 -0
- package/lib/typescript/hoc/with-touchable-handler.d.ts +15 -0
- package/lib/typescript/hoc/with-touchable-handler.d.ts.map +1 -0
- package/lib/typescript/hooks/use-gesture-handler.d.ts +14 -0
- package/lib/typescript/hooks/use-gesture-handler.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +4 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/utils/get-circle-path.d.ts +8 -0
- package/lib/typescript/utils/get-circle-path.d.ts.map +1 -0
- package/lib/typescript/utils/get-rect-path.d.ts +16 -0
- package/lib/typescript/utils/get-rect-path.d.ts.map +1 -0
- package/lib/typescript/utils/unwrap-animated-value.d.ts +5 -0
- package/lib/typescript/utils/unwrap-animated-value.d.ts.map +1 -0
- package/package.json +160 -0
- package/src/canvas/canvas.tsx +66 -0
- package/src/canvas/context.tsx +27 -0
- package/src/canvas/index.ts +1 -0
- package/src/hoc/index.ts +1 -0
- package/src/hoc/with-touchable-handler.tsx +127 -0
- package/src/hooks/use-gesture-handler.ts +59 -0
- package/src/index.ts +3 -0
- package/src/utils/get-circle-path.ts +7 -0
- package/src/utils/get-rect-path.ts +41 -0
- package/src/utils/unwrap-animated-value.ts +18 -0
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA,cAAc,UAAU"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA,cAAc,0BAA0B"}
|
@@ -0,0 +1,88 @@
|
|
1
|
+
import { useValue } from '@shopify/react-native-skia';
|
2
|
+
import { useCallback, useEffect, useId } from 'react';
|
3
|
+
import { getCirclePath } from '../utils/get-circle-path';
|
4
|
+
import { getRectPath, getRoundedRectPath } from '../utils/get-rect-path';
|
5
|
+
import { unwrapAnimatedValue, unwrapAnimatedValueObject } from '../utils/unwrap-animated-value';
|
6
|
+
import { useTouchHandlerContext } from '../canvas/context';
|
7
|
+
const getSkiaPath = (key, props) => {
|
8
|
+
const unwrappedProps = unwrapAnimatedValueObject(props);
|
9
|
+
switch (key) {
|
10
|
+
case 'Circle':
|
11
|
+
return getCirclePath(unwrappedProps);
|
12
|
+
case 'Rect':
|
13
|
+
return getRectPath(unwrappedProps);
|
14
|
+
case 'RoundedRect':
|
15
|
+
return getRoundedRectPath(unwrappedProps);
|
16
|
+
default:
|
17
|
+
return null;
|
18
|
+
}
|
19
|
+
};
|
20
|
+
const withTouchableHandler = Component => {
|
21
|
+
return _ref => {
|
22
|
+
let {
|
23
|
+
onStart: onStartProp,
|
24
|
+
onActive: onActiveProp,
|
25
|
+
onEnd: onEndProp,
|
26
|
+
touchablePath,
|
27
|
+
...props
|
28
|
+
} = _ref;
|
29
|
+
const id = useId();
|
30
|
+
const ref = useTouchHandlerContext();
|
31
|
+
const startingPoint = useValue(null);
|
32
|
+
const onStart = useCallback(event => {
|
33
|
+
startingPoint.current = {
|
34
|
+
x: event.x,
|
35
|
+
y: event.y
|
36
|
+
};
|
37
|
+
return onStartProp === null || onStartProp === void 0 ? void 0 : onStartProp(event);
|
38
|
+
}, [onStartProp, startingPoint]);
|
39
|
+
const onActive = useCallback(event => {
|
40
|
+
var _startingPoint$curren, _startingPoint$curren2;
|
41
|
+
const translationX = event.x - (((_startingPoint$curren = startingPoint.current) === null || _startingPoint$curren === void 0 ? void 0 : _startingPoint$curren.x) ?? 0);
|
42
|
+
const translationY = event.y - (((_startingPoint$curren2 = startingPoint.current) === null || _startingPoint$curren2 === void 0 ? void 0 : _startingPoint$curren2.y) ?? 0);
|
43
|
+
return onActiveProp === null || onActiveProp === void 0 ? void 0 : onActiveProp({
|
44
|
+
...event,
|
45
|
+
translationX,
|
46
|
+
translationY
|
47
|
+
});
|
48
|
+
}, [onActiveProp, startingPoint]);
|
49
|
+
const onEnd = useCallback(event => {
|
50
|
+
var _startingPoint$curren3, _startingPoint$curren4;
|
51
|
+
const translationX = event.x - (((_startingPoint$curren3 = startingPoint.current) === null || _startingPoint$curren3 === void 0 ? void 0 : _startingPoint$curren3.x) ?? 0);
|
52
|
+
const translationY = event.y - (((_startingPoint$curren4 = startingPoint.current) === null || _startingPoint$curren4 === void 0 ? void 0 : _startingPoint$curren4.y) ?? 0);
|
53
|
+
return onEndProp === null || onEndProp === void 0 ? void 0 : onEndProp({
|
54
|
+
...event,
|
55
|
+
translationX,
|
56
|
+
translationY
|
57
|
+
});
|
58
|
+
}, [onEndProp, startingPoint]);
|
59
|
+
const isPointInPath = useCallback(point => {
|
60
|
+
if (touchablePath) {
|
61
|
+
return unwrapAnimatedValue(touchablePath).contains(point.x, point.y);
|
62
|
+
}
|
63
|
+
const path = getSkiaPath(Component.name, props);
|
64
|
+
if (!path) {
|
65
|
+
throw Error('No touchablePath provided');
|
66
|
+
}
|
67
|
+
return path.contains(point.x, point.y);
|
68
|
+
}, [props, touchablePath]);
|
69
|
+
useEffect(() => {
|
70
|
+
ref.current = {
|
71
|
+
[`id:${id}`]: {
|
72
|
+
isPointInPath,
|
73
|
+
onStart,
|
74
|
+
onActive,
|
75
|
+
onEnd
|
76
|
+
},
|
77
|
+
...ref.current
|
78
|
+
};
|
79
|
+
return () => {
|
80
|
+
var _ref$current;
|
81
|
+
(_ref$current = ref.current) === null || _ref$current === void 0 ? true : delete _ref$current[id];
|
82
|
+
};
|
83
|
+
}, [id, isPointInPath, onActive, onEnd, onStart, ref, touchablePath]);
|
84
|
+
return Component(props);
|
85
|
+
};
|
86
|
+
};
|
87
|
+
export { withTouchableHandler };
|
88
|
+
//# sourceMappingURL=with-touchable-handler.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["useValue","useCallback","useEffect","useId","getCirclePath","getRectPath","getRoundedRectPath","unwrapAnimatedValue","unwrapAnimatedValueObject","useTouchHandlerContext","getSkiaPath","key","props","unwrappedProps","withTouchableHandler","Component","onStart","onStartProp","onActive","onActiveProp","onEnd","onEndProp","touchablePath","id","ref","startingPoint","event","current","x","y","translationX","translationY","isPointInPath","point","contains","path","name","Error"],"sourceRoot":"../../src","sources":["with-touchable-handler.tsx"],"mappings":"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"}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { useValue } from '@shopify/react-native-skia';
|
2
|
+
import { useCallback } from 'react';
|
3
|
+
const useGestureHandler = gestureHandlers => {
|
4
|
+
const {
|
5
|
+
onStart,
|
6
|
+
onActive,
|
7
|
+
onEnd
|
8
|
+
} = gestureHandlers;
|
9
|
+
const context = useValue({});
|
10
|
+
const handleStart = useCallback(touchInfo => {
|
11
|
+
if (!onStart) return;
|
12
|
+
return onStart(touchInfo, context.current);
|
13
|
+
}, [context, onStart]);
|
14
|
+
const handleActive = useCallback(extendedTouchInfo => {
|
15
|
+
if (!onActive) return;
|
16
|
+
return onActive(extendedTouchInfo, context.current);
|
17
|
+
}, [context, onActive]);
|
18
|
+
const handleEnd = useCallback(extendedTouchInfo => {
|
19
|
+
if (!onEnd) return;
|
20
|
+
return onEnd(extendedTouchInfo, context.current);
|
21
|
+
}, [context, onEnd]);
|
22
|
+
return {
|
23
|
+
onStart: handleStart,
|
24
|
+
onActive: handleActive,
|
25
|
+
onEnd: handleEnd
|
26
|
+
};
|
27
|
+
};
|
28
|
+
export { useGestureHandler };
|
29
|
+
//# sourceMappingURL=use-gesture-handler.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["useValue","useCallback","useGestureHandler","gestureHandlers","onStart","onActive","onEnd","context","handleStart","touchInfo","current","handleActive","extendedTouchInfo","handleEnd"],"sourceRoot":"../../src","sources":["use-gesture-handler.ts"],"mappings":"AAAA,SAGEA,QAAQ,QACH,4BAA4B;AACnC,SAASC,WAAW,QAAQ,OAAO;AAenC,MAAMC,iBAAiB,GACrBC,eAAqD,IAClD;EACH,MAAM;IAAEC,OAAO;IAAEC,QAAQ;IAAEC;EAAM,CAAC,GAAGH,eAAe;EAEpD,MAAMI,OAAO,GAAGP,QAAQ,CAAc,CAAC,CAAC,CAAQ;EAEhD,MAAMQ,WAAW,GAAGP,WAAW,CAC5BQ,SAAoB,IAAK;IACxB,IAAI,CAACL,OAAO,EAAE;IACd,OAAOA,OAAO,CAACK,SAAS,EAAEF,OAAO,CAACG,OAAO,CAAC;EAC5C,CAAC,EACD,CAACH,OAAO,EAAEH,OAAO,CAAC,CACnB;EAED,MAAMO,YAAY,GAAGV,WAAW,CAC7BW,iBAAsD,IAAK;IAC1D,IAAI,CAACP,QAAQ,EAAE;IACf,OAAOA,QAAQ,CAACO,iBAAiB,EAAEL,OAAO,CAACG,OAAO,CAAC;EACrD,CAAC,EACD,CAACH,OAAO,EAAEF,QAAQ,CAAC,CACpB;EAED,MAAMQ,SAAS,GAAGZ,WAAW,CAC1BW,iBAAsD,IAAK;IAC1D,IAAI,CAACN,KAAK,EAAE;IACZ,OAAOA,KAAK,CAACM,iBAAiB,EAAEL,OAAO,CAACG,OAAO,CAAC;EAClD,CAAC,EACD,CAACH,OAAO,EAAED,KAAK,CAAC,CACjB;EAED,OAAO;IACLF,OAAO,EAAEI,WAAW;IACpBH,QAAQ,EAAEM,YAAY;IACtBL,KAAK,EAAEO;EACT,CAAC;AACH,CAAC;AAED,SAASX,iBAAiB"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA,cAAc,UAAU;AACxB,cAAc,OAAO;AACrB,cAAc,6BAA6B"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["Skia","getCirclePath","cx","cy","r","Path","Make","addCircle"],"sourceRoot":"../../src","sources":["get-circle-path.ts"],"mappings":"AAAA,SAASA,IAAI,QAAQ,4BAA4B;AAIjD,OAAO,MAAMC,aAAa,GAAG,QAAwC;EAAA,IAAvC;IAAEC,EAAE;IAAEC,EAAE;IAAEC;EAAuB,CAAC;EAC9D,OAAOJ,IAAI,CAACK,IAAI,CAACC,IAAI,EAAE,CAACC,SAAS,CAACL,EAAE,EAAEC,EAAE,EAAEC,CAAC,CAAC;AAC9C,CAAC"}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import { rect, rrect, Skia } from '@shopify/react-native-skia';
|
2
|
+
const getRectPath = params => {
|
3
|
+
const skPath = Skia.Path.Make();
|
4
|
+
if ('rect' in params) {
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
6
|
+
const {
|
7
|
+
rect
|
8
|
+
} = params;
|
9
|
+
skPath.addRect(rect);
|
10
|
+
return skPath;
|
11
|
+
}
|
12
|
+
const {
|
13
|
+
x,
|
14
|
+
y,
|
15
|
+
width,
|
16
|
+
height
|
17
|
+
} = params;
|
18
|
+
skPath.addRect(rect(x, y, width, height));
|
19
|
+
return skPath;
|
20
|
+
};
|
21
|
+
const getRoundedRectPath = params => {
|
22
|
+
const {
|
23
|
+
r
|
24
|
+
} = params;
|
25
|
+
if ('rect' in params) {
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
27
|
+
const {
|
28
|
+
rect
|
29
|
+
} = params;
|
30
|
+
return Skia.Path.Make().addRRect(rrect(rect, r, r));
|
31
|
+
}
|
32
|
+
const {
|
33
|
+
x,
|
34
|
+
y,
|
35
|
+
width,
|
36
|
+
height
|
37
|
+
} = params;
|
38
|
+
return Skia.Path.Make().addRRect(rrect(rect(x, y, width, height), r, r));
|
39
|
+
};
|
40
|
+
export { getRectPath, getRoundedRectPath };
|
41
|
+
//# sourceMappingURL=get-rect-path.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["rect","rrect","Skia","getRectPath","params","skPath","Path","Make","addRect","x","y","width","height","getRoundedRectPath","r","addRRect"],"sourceRoot":"../../src","sources":["get-rect-path.ts"],"mappings":"AAAA,SAASA,IAAI,EAAEC,KAAK,EAAEC,IAAI,QAAgB,4BAA4B;AAWtE,MAAMC,WAAW,GAAIC,MAAyB,IAAK;EACjD,MAAMC,MAAM,GAAGH,IAAI,CAACI,IAAI,CAACC,IAAI,EAAE;EAC/B,IAAI,MAAM,IAAIH,MAAM,EAAE;IACpB;IACA,MAAM;MAAEJ;IAAK,CAAC,GAAGI,MAAM;IAEvBC,MAAM,CAACG,OAAO,CAACR,IAAI,CAAC;IACpB,OAAOK,MAAM;EACf;EACA,MAAM;IAAEI,CAAC;IAAEC,CAAC;IAAEC,KAAK;IAAEC;EAAO,CAAC,GAAGR,MAAM;EACtCC,MAAM,CAACG,OAAO,CAACR,IAAI,CAACS,CAAC,EAAEC,CAAC,EAAEC,KAAK,EAAEC,MAAM,CAAC,CAAC;EACzC,OAAOP,MAAM;AACf,CAAC;AAMD,MAAMQ,kBAAkB,GAAIT,MAAgC,IAAK;EAC/D,MAAM;IAAEU;EAAE,CAAC,GAAGV,MAAM;EACpB,IAAI,MAAM,IAAIA,MAAM,EAAE;IACpB;IACA,MAAM;MAAEJ;IAAK,CAAC,GAAGI,MAAM;IACvB,OAAOF,IAAI,CAACI,IAAI,CAACC,IAAI,EAAE,CAACQ,QAAQ,CAACd,KAAK,CAACD,IAAI,EAAEc,CAAC,EAAEA,CAAC,CAAC,CAAC;EACrD;EACA,MAAM;IAAEL,CAAC;IAAEC,CAAC;IAAEC,KAAK;IAAEC;EAAO,CAAC,GAAGR,MAAM;EACtC,OAAOF,IAAI,CAACI,IAAI,CAACC,IAAI,EAAE,CAACQ,QAAQ,CAACd,KAAK,CAACD,IAAI,CAACS,CAAC,EAAEC,CAAC,EAAEC,KAAK,EAAEC,MAAM,CAAC,EAAEE,CAAC,EAAEA,CAAC,CAAC,CAAC;AAC1E,CAAC;AAED,SAASX,WAAW,EAAEU,kBAAkB"}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
const unwrapAnimatedValue = value => {
|
2
|
+
if (value.current != null) {
|
3
|
+
return value.current;
|
4
|
+
}
|
5
|
+
return value;
|
6
|
+
};
|
7
|
+
const unwrapAnimatedValueObject = value => {
|
8
|
+
return Object.keys(value).reduce((acc, key) => {
|
9
|
+
return {
|
10
|
+
...acc,
|
11
|
+
[key]: unwrapAnimatedValue(value[key])
|
12
|
+
};
|
13
|
+
}, {});
|
14
|
+
};
|
15
|
+
export { unwrapAnimatedValue, unwrapAnimatedValueObject };
|
16
|
+
//# sourceMappingURL=unwrap-animated-value.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["unwrapAnimatedValue","value","current","unwrapAnimatedValueObject","Object","keys","reduce","acc","key"],"sourceRoot":"../../src","sources":["unwrap-animated-value.ts"],"mappings":"AAEA,MAAMA,mBAAmB,GAAOC,KAAuB,IAAQ;EAC7D,IAAKA,KAAK,CAAkBC,OAAO,IAAI,IAAI,EAAE;IAC3C,OAAQD,KAAK,CAAkBC,OAAO;EACxC;EACA,OAAOD,KAAK;AACd,CAAC;AAED,MAAME,yBAAyB,GAC7BF,KAAoC,IACjB;EACnB,OAAOG,MAAM,CAACC,IAAI,CAACJ,KAAK,CAAC,CAACK,MAAM,CAAC,CAACC,GAAG,EAAEC,GAAG,KAAK;IAC7C,OAAO;MAAE,GAAGD,GAAG;MAAE,CAACC,GAAG,GAAGR,mBAAmB,CAACC,KAAK,CAACO,GAAG,CAAC;IAAE,CAAC;EAC3D,CAAC,EAAE,CAAC,CAAC,CAAC;AACR,CAAC;AAED,SAASR,mBAAmB,EAAEG,yBAAyB"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"canvas.d.ts","sourceRoot":"","sources":["../../../src/canvas/canvas.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EAGZ,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAoB,MAAM,OAAO,CAAC;AAGzC,QAAA,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAsDjC,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import type { ExtendedTouchInfo, TouchInfo, Vector } from '@shopify/react-native-skia';
|
2
|
+
import React from 'react';
|
3
|
+
export type TouchableHandlerContextType = {
|
4
|
+
current: Record<string, {
|
5
|
+
onStart: (touchInfo: TouchInfo) => void;
|
6
|
+
onActive: (touchInfo: ExtendedTouchInfo) => void;
|
7
|
+
onEnd: (touchInfo: ExtendedTouchInfo) => void;
|
8
|
+
isPointInPath: (point: Vector) => boolean;
|
9
|
+
}>;
|
10
|
+
};
|
11
|
+
declare const TouchHandlerContext: React.Context<TouchableHandlerContextType>;
|
12
|
+
declare const useTouchHandlerContext: () => TouchableHandlerContextType;
|
13
|
+
export { TouchHandlerContext, useTouchHandlerContext };
|
14
|
+
//# sourceMappingURL=context.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/canvas/context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,SAAS,EACT,MAAM,EACP,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAqB,MAAM,OAAO,CAAC;AAE1C,MAAM,MAAM,2BAA2B,GAAG;IACxC,OAAO,EAAE,MAAM,CACb,MAAM,EACN;QACE,OAAO,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,IAAI,CAAC;QACxC,QAAQ,EAAE,CAAC,SAAS,EAAE,iBAAiB,KAAK,IAAI,CAAC;QACjD,KAAK,EAAE,CAAC,SAAS,EAAE,iBAAiB,KAAK,IAAI,CAAC;QAC9C,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;KAC3C,CACF,CAAC;CACH,CAAC;AACF,QAAA,MAAM,mBAAmB,4CAEvB,CAAC;AAEH,QAAA,MAAM,sBAAsB,mCAE3B,CAAC;AAEF,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/canvas/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hoc/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC"}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { ExtendedTouchInfo, SkiaProps, SkiaValue, SkPath, TouchInfo } from '@shopify/react-native-skia';
|
2
|
+
export type TranslationInfo = {
|
3
|
+
translationX: number;
|
4
|
+
translationY: number;
|
5
|
+
};
|
6
|
+
export type TouchableHandlerProps = {
|
7
|
+
onStart: (touchInfo: TouchInfo) => void;
|
8
|
+
onActive: (touchInfo: ExtendedTouchInfo & TranslationInfo) => void;
|
9
|
+
onEnd: (touchInfo: ExtendedTouchInfo & TranslationInfo) => void;
|
10
|
+
touchablePath: SkPath | SkiaValue<SkPath>;
|
11
|
+
};
|
12
|
+
type WithTouchableHandlerProps<T> = SkiaProps<T> & Partial<TouchableHandlerProps>;
|
13
|
+
declare const withTouchableHandler: <T>(Component: (props: WithTouchableHandlerProps<T>) => JSX.Element) => ({ onStart: onStartProp, onActive: onActiveProp, onEnd: onEndProp, touchablePath, ...props }: WithTouchableHandlerProps<T>) => JSX.Element;
|
14
|
+
export { withTouchableHandler };
|
15
|
+
//# sourceMappingURL=with-touchable-handler.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"with-touchable-handler.d.ts","sourceRoot":"","sources":["../../../src/hoc/with-touchable-handler.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,SAAS,EACT,SAAS,EACT,MAAM,EACN,SAAS,EAGV,MAAM,4BAA4B,CAAC;AAUpC,MAAM,MAAM,eAAe,GAAG;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,IAAI,CAAC;IACxC,QAAQ,EAAE,CAAC,SAAS,EAAE,iBAAiB,GAAG,eAAe,KAAK,IAAI,CAAC;IACnE,KAAK,EAAE,CAAC,SAAS,EAAE,iBAAiB,GAAG,eAAe,KAAK,IAAI,CAAC;IAChE,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;CAC3C,CAAC;AAEF,KAAK,yBAAyB,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,GAC9C,OAAO,CAAC,qBAAqB,CAAC,CAAC;AAiBjC,QAAA,MAAM,oBAAoB,0DAC4B,WAAW,+IA2EhE,CAAC;AAEF,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { ExtendedTouchInfo, TouchInfo } from '@shopify/react-native-skia';
|
2
|
+
import type { TranslationInfo } from '../hoc';
|
3
|
+
type UseGestureHandlerParams<ContextType> = {
|
4
|
+
onStart?: (touchInfo: TouchInfo, context: ContextType) => void;
|
5
|
+
onActive?: (extendedTouchInfo: ExtendedTouchInfo & TranslationInfo, context: ContextType) => void;
|
6
|
+
onEnd?: (extendedTouchInfo: ExtendedTouchInfo & TranslationInfo, context: ContextType) => void;
|
7
|
+
};
|
8
|
+
declare const useGestureHandler: <ContextType>(gestureHandlers: UseGestureHandlerParams<ContextType>) => {
|
9
|
+
onStart: (touchInfo: TouchInfo) => void;
|
10
|
+
onActive: (extendedTouchInfo: ExtendedTouchInfo & TranslationInfo) => void;
|
11
|
+
onEnd: (extendedTouchInfo: ExtendedTouchInfo & TranslationInfo) => void;
|
12
|
+
};
|
13
|
+
export { useGestureHandler };
|
14
|
+
//# sourceMappingURL=use-gesture-handler.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"use-gesture-handler.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-gesture-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,SAAS,EAEV,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAE9C,KAAK,uBAAuB,CAAC,WAAW,IAAI;IAC1C,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,KAAK,IAAI,CAAC;IAC/D,QAAQ,CAAC,EAAE,CACT,iBAAiB,EAAE,iBAAiB,GAAG,eAAe,EACtD,OAAO,EAAE,WAAW,KACjB,IAAI,CAAC;IACV,KAAK,CAAC,EAAE,CACN,iBAAiB,EAAE,iBAAiB,GAAG,eAAe,EACtD,OAAO,EAAE,WAAW,KACjB,IAAI,CAAC;CACX,CAAC;AAEF,QAAA,MAAM,iBAAiB;yBAQP,SAAS;kCAQD,iBAAiB,GAAG,eAAe;+BAQnC,iBAAiB,GAAG,eAAe;CAY1D,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,OAAO,CAAC;AACtB,cAAc,6BAA6B,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"get-circle-path.d.ts","sourceRoot":"","sources":["../../../src/utils/get-circle-path.ts"],"names":[],"mappings":"AAEA,KAAK,mBAAmB,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjE,eAAO,MAAM,aAAa,kBAAmB,mBAAmB,gDAE/D,CAAC"}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { SkRect } from '@shopify/react-native-skia';
|
2
|
+
type GetRectPathParams = {
|
3
|
+
x: number;
|
4
|
+
y: number;
|
5
|
+
width: number;
|
6
|
+
height: number;
|
7
|
+
} | {
|
8
|
+
rect: SkRect;
|
9
|
+
};
|
10
|
+
declare const getRectPath: (params: GetRectPathParams) => import("@shopify/react-native-skia").SkPath;
|
11
|
+
type GetRoundedRectPathParams = GetRectPathParams & {
|
12
|
+
r: number;
|
13
|
+
};
|
14
|
+
declare const getRoundedRectPath: (params: GetRoundedRectPathParams) => import("@shopify/react-native-skia").SkPath;
|
15
|
+
export { getRectPath, getRoundedRectPath };
|
16
|
+
//# sourceMappingURL=get-rect-path.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"get-rect-path.d.ts","sourceRoot":"","sources":["../../../src/utils/get-rect-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEvE,KAAK,iBAAiB,GAClB;IACE,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,GACD;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAErB,QAAA,MAAM,WAAW,WAAY,iBAAiB,gDAY7C,CAAC;AAEF,KAAK,wBAAwB,GAAG,iBAAiB,GAAG;IAClD,CAAC,EAAE,MAAM,CAAC;CACX,CAAC;AAEF,QAAA,MAAM,kBAAkB,WAAY,wBAAwB,gDAS3D,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,CAAC"}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import type { SkiaValue } from '@shopify/react-native-skia';
|
2
|
+
declare const unwrapAnimatedValue: <T>(value: T | SkiaValue<T>) => T;
|
3
|
+
declare const unwrapAnimatedValueObject: <T>(value: Record<any, T | SkiaValue<T>>) => Record<any, T>;
|
4
|
+
export { unwrapAnimatedValue, unwrapAnimatedValueObject };
|
5
|
+
//# sourceMappingURL=unwrap-animated-value.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"unwrap-animated-value.d.ts","sourceRoot":"","sources":["../../../src/utils/unwrap-animated-value.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAE5D,QAAA,MAAM,mBAAmB,mCAKxB,CAAC;AAEF,QAAA,MAAM,yBAAyB,6DAM9B,CAAC;AAEF,OAAO,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,CAAC"}
|
package/package.json
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
{
|
2
|
+
"name": "react-native-skia-gesture",
|
3
|
+
"version": "0.1.6",
|
4
|
+
"description": "A detection system for React Native Skia components",
|
5
|
+
"main": "lib/commonjs/index",
|
6
|
+
"module": "lib/module/index",
|
7
|
+
"types": "lib/typescript/index.d.ts",
|
8
|
+
"react-native": "src/index",
|
9
|
+
"source": "src/index",
|
10
|
+
"files": [
|
11
|
+
"src",
|
12
|
+
"lib",
|
13
|
+
"android",
|
14
|
+
"ios",
|
15
|
+
"cpp",
|
16
|
+
"*.podspec",
|
17
|
+
"!lib/typescript/example",
|
18
|
+
"!ios/build",
|
19
|
+
"!android/build",
|
20
|
+
"!android/gradle",
|
21
|
+
"!android/gradlew",
|
22
|
+
"!android/gradlew.bat",
|
23
|
+
"!android/local.properties",
|
24
|
+
"!**/__tests__",
|
25
|
+
"!**/__fixtures__",
|
26
|
+
"!**/__mocks__",
|
27
|
+
"!**/.*"
|
28
|
+
],
|
29
|
+
"scripts": {
|
30
|
+
"test": "jest",
|
31
|
+
"typecheck": "tsc --noEmit",
|
32
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
33
|
+
"prepack": "bob build",
|
34
|
+
"release": "release-it",
|
35
|
+
"example": "yarn --cwd example",
|
36
|
+
"bootstrap": "yarn example && yarn install"
|
37
|
+
},
|
38
|
+
"keywords": [
|
39
|
+
"react-native",
|
40
|
+
"ios",
|
41
|
+
"android"
|
42
|
+
],
|
43
|
+
"repository": "https://github.com/enzomanuelmangano/react-native-skia-gesture",
|
44
|
+
"author": "Enzo Manuel Mangano <enzomanuelmangano@gmail.com> (https://github.com/enzomanuelmangano)",
|
45
|
+
"license": "MIT",
|
46
|
+
"bugs": {
|
47
|
+
"url": "https://github.com/enzomanuelmangano/react-native-skia-gesture/issues"
|
48
|
+
},
|
49
|
+
"homepage": "https://github.com/enzomanuelmangano/react-native-skia-gesture#readme",
|
50
|
+
"publishConfig": {
|
51
|
+
"registry": "https://registry.npmjs.org/"
|
52
|
+
},
|
53
|
+
"devDependencies": {
|
54
|
+
"@commitlint/config-conventional": "^17.0.2",
|
55
|
+
"@evilmartians/lefthook": "^1.2.2",
|
56
|
+
"@react-native-community/eslint-config": "^3.0.2",
|
57
|
+
"@release-it/conventional-changelog": "^5.0.0",
|
58
|
+
"@shopify/react-native-skia": "0.1.157",
|
59
|
+
"@types/jest": "^28.1.2",
|
60
|
+
"@types/react": "18.0.26",
|
61
|
+
"@types/react-native": "0.70.0",
|
62
|
+
"commitlint": "^17.0.2",
|
63
|
+
"del-cli": "^5.0.0",
|
64
|
+
"eslint": "^8.4.1",
|
65
|
+
"eslint-config-prettier": "^8.5.0",
|
66
|
+
"eslint-plugin-prettier": "^4.0.0",
|
67
|
+
"jest": "^28.1.1",
|
68
|
+
"pod-install": "^0.1.0",
|
69
|
+
"prettier": "^2.0.5",
|
70
|
+
"react": "18.1.0",
|
71
|
+
"react-native": "0.70.5",
|
72
|
+
"react-native-builder-bob": "^0.20.0",
|
73
|
+
"release-it": "^15.0.0",
|
74
|
+
"typescript": "^4.5.2"
|
75
|
+
},
|
76
|
+
"resolutions": {
|
77
|
+
"@types/react": "17.0.21"
|
78
|
+
},
|
79
|
+
"peerDependencies": {
|
80
|
+
"react": ">= 18.0.0",
|
81
|
+
"react-native": "*"
|
82
|
+
},
|
83
|
+
"engines": {
|
84
|
+
"node": ">= 16.0.0"
|
85
|
+
},
|
86
|
+
"packageManager": "^yarn@1.22.15",
|
87
|
+
"jest": {
|
88
|
+
"preset": "react-native",
|
89
|
+
"modulePathIgnorePatterns": [
|
90
|
+
"<rootDir>/example/node_modules",
|
91
|
+
"<rootDir>/lib/"
|
92
|
+
]
|
93
|
+
},
|
94
|
+
"commitlint": {
|
95
|
+
"extends": [
|
96
|
+
"@commitlint/config-conventional"
|
97
|
+
]
|
98
|
+
},
|
99
|
+
"release-it": {
|
100
|
+
"git": {
|
101
|
+
"commitMessage": "chore: release ${version}",
|
102
|
+
"tagName": "v${version}"
|
103
|
+
},
|
104
|
+
"npm": {
|
105
|
+
"publish": true
|
106
|
+
},
|
107
|
+
"github": {
|
108
|
+
"release": true
|
109
|
+
},
|
110
|
+
"plugins": {
|
111
|
+
"@release-it/conventional-changelog": {
|
112
|
+
"preset": "angular"
|
113
|
+
}
|
114
|
+
}
|
115
|
+
},
|
116
|
+
"eslintConfig": {
|
117
|
+
"root": true,
|
118
|
+
"extends": [
|
119
|
+
"@react-native-community",
|
120
|
+
"prettier"
|
121
|
+
],
|
122
|
+
"rules": {
|
123
|
+
"prettier/prettier": [
|
124
|
+
"error",
|
125
|
+
{
|
126
|
+
"quoteProps": "consistent",
|
127
|
+
"singleQuote": true,
|
128
|
+
"tabWidth": 2,
|
129
|
+
"trailingComma": "es5",
|
130
|
+
"useTabs": false
|
131
|
+
}
|
132
|
+
]
|
133
|
+
}
|
134
|
+
},
|
135
|
+
"eslintIgnore": [
|
136
|
+
"node_modules/",
|
137
|
+
"lib/"
|
138
|
+
],
|
139
|
+
"prettier": {
|
140
|
+
"quoteProps": "consistent",
|
141
|
+
"singleQuote": true,
|
142
|
+
"tabWidth": 2,
|
143
|
+
"trailingComma": "es5",
|
144
|
+
"useTabs": false
|
145
|
+
},
|
146
|
+
"react-native-builder-bob": {
|
147
|
+
"source": "src",
|
148
|
+
"output": "lib",
|
149
|
+
"targets": [
|
150
|
+
"commonjs",
|
151
|
+
"module",
|
152
|
+
[
|
153
|
+
"typescript",
|
154
|
+
{
|
155
|
+
"project": "tsconfig.build.json"
|
156
|
+
}
|
157
|
+
]
|
158
|
+
]
|
159
|
+
}
|
160
|
+
}
|
@@ -0,0 +1,66 @@
|
|
1
|
+
import {
|
2
|
+
Canvas as SkiaCanvas,
|
3
|
+
CanvasProps,
|
4
|
+
useTouchHandler,
|
5
|
+
useValue,
|
6
|
+
} from '@shopify/react-native-skia';
|
7
|
+
import React, { useEffect } from 'react';
|
8
|
+
import { TouchHandlerContext, TouchableHandlerContextType } from './context';
|
9
|
+
|
10
|
+
const Canvas: React.FC<CanvasProps> = ({ children, onTouch, ...props }) => {
|
11
|
+
const touchableRefs = useValue<TouchableHandlerContextType['current']>({});
|
12
|
+
|
13
|
+
const activeKey = useValue<string | null>(null);
|
14
|
+
|
15
|
+
const touchHandler = useTouchHandler(
|
16
|
+
{
|
17
|
+
onStart: (event) => {
|
18
|
+
const keys = Object.keys(touchableRefs.current);
|
19
|
+
for (let i = 0; i < keys.length; i++) {
|
20
|
+
const key = keys[i] as string;
|
21
|
+
const touchableItem = touchableRefs.current[key];
|
22
|
+
|
23
|
+
if (touchableItem?.isPointInPath(event)) {
|
24
|
+
activeKey.current = key;
|
25
|
+
touchableItem.onStart?.(event);
|
26
|
+
return;
|
27
|
+
}
|
28
|
+
}
|
29
|
+
},
|
30
|
+
onActive: (event) => {
|
31
|
+
if (!activeKey.current) return;
|
32
|
+
const touchableItem = touchableRefs.current[activeKey.current];
|
33
|
+
return touchableItem?.onActive?.(event);
|
34
|
+
},
|
35
|
+
onEnd: (event) => {
|
36
|
+
if (!activeKey.current) return;
|
37
|
+
const touchableItem = touchableRefs.current[activeKey.current];
|
38
|
+
activeKey.current = null;
|
39
|
+
return touchableItem?.onEnd?.(event);
|
40
|
+
},
|
41
|
+
},
|
42
|
+
[touchableRefs, activeKey]
|
43
|
+
);
|
44
|
+
|
45
|
+
useEffect(() => {
|
46
|
+
return () => {
|
47
|
+
touchableRefs.current = {};
|
48
|
+
};
|
49
|
+
}, [touchableRefs]);
|
50
|
+
|
51
|
+
return (
|
52
|
+
<SkiaCanvas
|
53
|
+
{...props}
|
54
|
+
onTouch={(touchInfo) => {
|
55
|
+
touchHandler(touchInfo);
|
56
|
+
return onTouch?.(touchInfo);
|
57
|
+
}}
|
58
|
+
>
|
59
|
+
<TouchHandlerContext.Provider value={touchableRefs}>
|
60
|
+
{children}
|
61
|
+
</TouchHandlerContext.Provider>
|
62
|
+
</SkiaCanvas>
|
63
|
+
);
|
64
|
+
};
|
65
|
+
|
66
|
+
export { Canvas };
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import type {
|
2
|
+
ExtendedTouchInfo,
|
3
|
+
TouchInfo,
|
4
|
+
Vector,
|
5
|
+
} from '@shopify/react-native-skia';
|
6
|
+
import React, { useContext } from 'react';
|
7
|
+
|
8
|
+
export type TouchableHandlerContextType = {
|
9
|
+
current: Record<
|
10
|
+
string,
|
11
|
+
{
|
12
|
+
onStart: (touchInfo: TouchInfo) => void;
|
13
|
+
onActive: (touchInfo: ExtendedTouchInfo) => void;
|
14
|
+
onEnd: (touchInfo: ExtendedTouchInfo) => void;
|
15
|
+
isPointInPath: (point: Vector) => boolean;
|
16
|
+
}
|
17
|
+
>;
|
18
|
+
};
|
19
|
+
const TouchHandlerContext = React.createContext<TouchableHandlerContextType>({
|
20
|
+
current: {},
|
21
|
+
});
|
22
|
+
|
23
|
+
const useTouchHandlerContext = () => {
|
24
|
+
return useContext(TouchHandlerContext);
|
25
|
+
};
|
26
|
+
|
27
|
+
export { TouchHandlerContext, useTouchHandlerContext };
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './canvas';
|
package/src/hoc/index.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export * from './with-touchable-handler';
|