@shopify/react-native-skia 1.4.2 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- package/android/CMakeLists.txt +38 -6
- package/android/build.gradle +1 -0
- package/android/cpp/jni/include/JniSkiaBaseView.h +0 -4
- package/android/cpp/jni/include/JniSkiaDomView.h +0 -6
- package/android/cpp/jni/include/JniSkiaPictureView.h +0 -6
- package/android/cpp/rnskia-android/RNSkAndroidView.h +0 -20
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +0 -72
- package/cpp/rnskia/RNSkDomView.cpp +0 -79
- package/cpp/rnskia/RNSkDomView.h +1 -39
- package/cpp/rnskia/RNSkPictureView.h +0 -1
- package/cpp/rnskia/RNSkView.h +0 -17
- package/ios/RNSkia-iOS/DisplayLink.mm +7 -0
- package/ios/RNSkia-iOS/SkiaUIView.mm +0 -51
- package/lib/commonjs/mock/index.js +0 -1
- package/lib/commonjs/mock/index.js.map +1 -1
- package/lib/commonjs/renderer/Canvas.d.ts +1 -2
- package/lib/commonjs/renderer/Canvas.js +0 -3
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
- package/lib/commonjs/views/SkiaBaseWebView.d.ts +2 -11
- package/lib/commonjs/views/SkiaBaseWebView.js +3 -31
- package/lib/commonjs/views/SkiaBaseWebView.js.map +1 -1
- package/lib/commonjs/views/SkiaDomView.js +0 -12
- package/lib/commonjs/views/SkiaDomView.js.map +1 -1
- package/lib/commonjs/views/SkiaDomView.web.d.ts +2 -2
- package/lib/commonjs/views/SkiaDomView.web.js +1 -6
- package/lib/commonjs/views/SkiaDomView.web.js.map +1 -1
- package/lib/commonjs/views/SkiaJSDomView.js +0 -12
- package/lib/commonjs/views/SkiaJSDomView.js.map +1 -1
- package/lib/commonjs/views/index.d.ts +0 -1
- package/lib/commonjs/views/index.js +0 -11
- package/lib/commonjs/views/index.js.map +1 -1
- package/lib/commonjs/views/types.d.ts +0 -26
- package/lib/commonjs/views/types.js +0 -8
- package/lib/commonjs/views/types.js.map +1 -1
- package/lib/commonjs/web/WithSkiaWeb.js +4 -1
- package/lib/commonjs/web/WithSkiaWeb.js.map +1 -1
- package/lib/module/mock/index.js +0 -1
- package/lib/module/mock/index.js.map +1 -1
- package/lib/module/renderer/Canvas.d.ts +1 -2
- package/lib/module/renderer/Canvas.js +0 -3
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/skia/web/JsiSkia.js.map +1 -1
- package/lib/module/views/SkiaBaseWebView.d.ts +2 -11
- package/lib/module/views/SkiaBaseWebView.js +3 -31
- package/lib/module/views/SkiaBaseWebView.js.map +1 -1
- package/lib/module/views/SkiaDomView.js +0 -12
- package/lib/module/views/SkiaDomView.js.map +1 -1
- package/lib/module/views/SkiaDomView.web.d.ts +2 -2
- package/lib/module/views/SkiaDomView.web.js +1 -6
- package/lib/module/views/SkiaDomView.web.js.map +1 -1
- package/lib/module/views/SkiaJSDomView.js +0 -12
- package/lib/module/views/SkiaJSDomView.js.map +1 -1
- package/lib/module/views/index.d.ts +0 -1
- package/lib/module/views/index.js +0 -1
- package/lib/module/views/index.js.map +1 -1
- package/lib/module/views/types.d.ts +0 -26
- package/lib/module/views/types.js +1 -7
- package/lib/module/views/types.js.map +1 -1
- package/lib/module/web/WithSkiaWeb.js +4 -1
- package/lib/module/web/WithSkiaWeb.js.map +1 -1
- package/lib/typescript/lib/commonjs/mock/index.d.ts +0 -1
- package/lib/typescript/lib/commonjs/views/SkiaBaseWebView.d.ts +0 -3
- package/lib/typescript/lib/commonjs/views/SkiaDomView.web.d.ts +1 -1
- package/lib/typescript/lib/commonjs/views/types.d.ts +0 -1
- package/lib/typescript/lib/module/mock/index.d.ts +0 -1
- package/lib/typescript/lib/module/views/SkiaBaseWebView.d.ts +0 -3
- package/lib/typescript/lib/module/views/SkiaDomView.web.d.ts +1 -1
- package/lib/typescript/lib/module/views/index.d.ts +0 -1
- package/lib/typescript/lib/module/views/types.d.ts +1 -1
- package/lib/typescript/src/renderer/Canvas.d.ts +1 -2
- package/lib/typescript/src/views/SkiaBaseWebView.d.ts +2 -11
- package/lib/typescript/src/views/SkiaDomView.web.d.ts +2 -2
- package/lib/typescript/src/views/index.d.ts +0 -1
- package/lib/typescript/src/views/types.d.ts +0 -26
- package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
- package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
- package/libs/ios/libskottie.xcframework/Info.plist +5 -5
- package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
- package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
- package/libs/ios/libskparagraph.xcframework/Info.plist +5 -5
- package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e/libskparagraph.a +0 -0
- package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e_x86_64-simulator/libskparagraph.a +0 -0
- package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
- package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
- package/libs/ios/libskshaper.xcframework/Info.plist +5 -5
- package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
- package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
- package/libs/ios/libskunicode_core.xcframework/ios-arm64_arm64e/libskunicode_core.a +0 -0
- package/libs/ios/libskunicode_core.xcframework/ios-arm64_arm64e_x86_64-simulator/libskunicode_core.a +0 -0
- package/libs/ios/libskunicode_libgrapheme.xcframework/ios-arm64_arm64e/libskunicode_libgrapheme.a +0 -0
- package/libs/ios/libskunicode_libgrapheme.xcframework/ios-arm64_arm64e_x86_64-simulator/libskunicode_libgrapheme.a +0 -0
- package/libs/ios/libsvg.xcframework/Info.plist +5 -5
- package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
- package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
- package/package.json +3 -6
- package/src/mock/index.ts +0 -1
- package/src/renderer/Canvas.tsx +1 -5
- package/src/renderer/__tests__/setup.tsx +0 -2
- package/src/skia/web/JsiSkia.ts +1 -1
- package/src/views/SkiaBaseWebView.tsx +5 -42
- package/src/views/SkiaDomView.tsx +2 -14
- package/src/views/SkiaDomView.web.tsx +2 -9
- package/src/views/SkiaJSDomView.tsx +2 -14
- package/src/views/index.ts +0 -1
- package/src/views/types.ts +0 -32
- package/src/web/WithSkiaWeb.tsx +3 -1
- package/cpp/rnskia/RNSkInfoParameter.h +0 -92
- package/lib/commonjs/renderer/__tests__/TouchHandler.spec.d.ts +0 -1
- package/lib/commonjs/views/useTouchHandler.d.ts +0 -22
- package/lib/commonjs/views/useTouchHandler.js +0 -83
- package/lib/commonjs/views/useTouchHandler.js.map +0 -1
- package/lib/module/renderer/__tests__/TouchHandler.spec.d.ts +0 -1
- package/lib/module/views/useTouchHandler.d.ts +0 -22
- package/lib/module/views/useTouchHandler.js +0 -75
- package/lib/module/views/useTouchHandler.js.map +0 -1
- package/lib/typescript/lib/commonjs/views/useTouchHandler.d.ts +0 -12
- package/lib/typescript/lib/module/views/useTouchHandler.d.ts +0 -2
- package/lib/typescript/src/renderer/__tests__/TouchHandler.spec.d.ts +0 -1
- package/lib/typescript/src/views/useTouchHandler.d.ts +0 -22
- package/src/renderer/__tests__/TouchHandler.spec.tsx +0 -113
- package/src/views/useTouchHandler.ts +0 -107
@@ -1,113 +0,0 @@
|
|
1
|
-
import React from "react";
|
2
|
-
|
3
|
-
import { TouchType } from "../../views/types";
|
4
|
-
|
5
|
-
import type { EmptyProps } from "./setup";
|
6
|
-
import { mountCanvas, importSkia } from "./setup";
|
7
|
-
|
8
|
-
const SimpleActiveTouch = ({}: EmptyProps) => {
|
9
|
-
const { useTouchHandler } = importSkia();
|
10
|
-
const touchHandler = useTouchHandler({
|
11
|
-
onStart: ({ x, y }) => {
|
12
|
-
expect(x).toBe(10);
|
13
|
-
expect(y).toBe(10);
|
14
|
-
},
|
15
|
-
onActive: ({ x, y, velocityX, velocityY }) => {
|
16
|
-
expect(x).toBe(20);
|
17
|
-
expect(y).toBe(20);
|
18
|
-
expect(velocityX).toBe(10);
|
19
|
-
expect(velocityY).toBe(10);
|
20
|
-
},
|
21
|
-
});
|
22
|
-
const history = [
|
23
|
-
[
|
24
|
-
{
|
25
|
-
x: 10,
|
26
|
-
y: 10,
|
27
|
-
force: 0,
|
28
|
-
type: TouchType.Start,
|
29
|
-
id: 2,
|
30
|
-
timestamp: 0,
|
31
|
-
},
|
32
|
-
],
|
33
|
-
[
|
34
|
-
{
|
35
|
-
x: 20,
|
36
|
-
y: 20,
|
37
|
-
force: 0,
|
38
|
-
type: TouchType.Active,
|
39
|
-
id: 2,
|
40
|
-
timestamp: 1,
|
41
|
-
},
|
42
|
-
],
|
43
|
-
];
|
44
|
-
touchHandler(history);
|
45
|
-
return null;
|
46
|
-
};
|
47
|
-
|
48
|
-
const SimpleEndTouch = ({}: EmptyProps) => {
|
49
|
-
const { useTouchHandler } = importSkia();
|
50
|
-
const touchHandler = useTouchHandler({
|
51
|
-
onStart: ({ x, y }) => {
|
52
|
-
expect(x).toBe(10);
|
53
|
-
expect(y).toBe(10);
|
54
|
-
},
|
55
|
-
onActive: ({ x, y, velocityX, velocityY }) => {
|
56
|
-
expect(x).toBe(20);
|
57
|
-
expect(y).toBe(20);
|
58
|
-
expect(velocityX).toBe(10);
|
59
|
-
expect(velocityY).toBe(10);
|
60
|
-
},
|
61
|
-
onEnd: ({ x, y, velocityX, velocityY }) => {
|
62
|
-
expect(x).toBe(30);
|
63
|
-
expect(y).toBe(30);
|
64
|
-
expect(velocityX).toBe(10);
|
65
|
-
expect(velocityY).toBe(10);
|
66
|
-
},
|
67
|
-
});
|
68
|
-
const history = [
|
69
|
-
[
|
70
|
-
{
|
71
|
-
x: 10,
|
72
|
-
y: 10,
|
73
|
-
force: 0,
|
74
|
-
type: TouchType.Start,
|
75
|
-
id: 2,
|
76
|
-
timestamp: 0,
|
77
|
-
},
|
78
|
-
],
|
79
|
-
[
|
80
|
-
{
|
81
|
-
x: 20,
|
82
|
-
y: 20,
|
83
|
-
force: 0,
|
84
|
-
type: TouchType.Active,
|
85
|
-
id: 2,
|
86
|
-
timestamp: 1,
|
87
|
-
},
|
88
|
-
],
|
89
|
-
[
|
90
|
-
{
|
91
|
-
x: 30,
|
92
|
-
y: 30,
|
93
|
-
force: 0,
|
94
|
-
type: TouchType.End,
|
95
|
-
id: 2,
|
96
|
-
timestamp: 2,
|
97
|
-
},
|
98
|
-
],
|
99
|
-
];
|
100
|
-
touchHandler(history);
|
101
|
-
return null;
|
102
|
-
};
|
103
|
-
|
104
|
-
describe("Test handling of touch information", () => {
|
105
|
-
it("Should check that the received values are correct", () => {
|
106
|
-
const { draw } = mountCanvas(<SimpleActiveTouch />);
|
107
|
-
draw();
|
108
|
-
});
|
109
|
-
it("Calculates the velocity properly onEnd event", () => {
|
110
|
-
const { draw } = mountCanvas(<SimpleEndTouch />);
|
111
|
-
draw();
|
112
|
-
});
|
113
|
-
});
|
@@ -1,107 +0,0 @@
|
|
1
|
-
import type { DependencyList } from "react";
|
2
|
-
import { useCallback, useRef } from "react";
|
3
|
-
|
4
|
-
import type { Vector } from "../skia/types";
|
5
|
-
import { Platform } from "../Platform";
|
6
|
-
|
7
|
-
import type {
|
8
|
-
ExtendedTouchInfo,
|
9
|
-
TouchHandlers,
|
10
|
-
TouchHandler,
|
11
|
-
TouchInfo,
|
12
|
-
} from "./types";
|
13
|
-
import { TouchType } from "./types";
|
14
|
-
|
15
|
-
const useInternalTouchHandler = (
|
16
|
-
handlers: TouchHandlers,
|
17
|
-
deps: DependencyList = [],
|
18
|
-
multiTouch = false
|
19
|
-
): TouchHandler => {
|
20
|
-
const prevTouchInfoRef = useRef<{ [key: number]: TouchInfo | undefined }>({});
|
21
|
-
const prevVelocityRef = useRef<{ [key: number]: Vector | undefined }>({});
|
22
|
-
|
23
|
-
return useCallback((history: Array<Array<TouchInfo>>) => {
|
24
|
-
// Process all items in the current touch history
|
25
|
-
history.forEach((touches) => {
|
26
|
-
// Enumerate touches
|
27
|
-
for (let i = 0; i < touches.length; i++) {
|
28
|
-
if (!multiTouch && i > 0) {
|
29
|
-
break;
|
30
|
-
}
|
31
|
-
|
32
|
-
const touch = touches[i];
|
33
|
-
const prevTouch = prevTouchInfoRef.current[touch.id];
|
34
|
-
// Calculate the velocity from the previous touch.
|
35
|
-
const timeDiffseconds =
|
36
|
-
touch.timestamp -
|
37
|
-
(prevTouchInfoRef.current[touch.id]?.timestamp ?? touch.timestamp);
|
38
|
-
|
39
|
-
const distX = touch.x - (prevTouch?.x ?? touch.x);
|
40
|
-
const distY = touch.y - (prevTouch?.y ?? touch.y);
|
41
|
-
|
42
|
-
if (
|
43
|
-
touch.type !== TouchType.Start &&
|
44
|
-
touch.type !== TouchType.End &&
|
45
|
-
touch.type !== TouchType.Cancelled &&
|
46
|
-
timeDiffseconds > 0
|
47
|
-
) {
|
48
|
-
prevVelocityRef.current[touch.id] = {
|
49
|
-
x: distX / timeDiffseconds / Platform.PixelRatio,
|
50
|
-
y: distY / timeDiffseconds / Platform.PixelRatio,
|
51
|
-
};
|
52
|
-
}
|
53
|
-
|
54
|
-
const extendedTouchInfo: ExtendedTouchInfo = {
|
55
|
-
...touch,
|
56
|
-
velocityX: prevVelocityRef.current[touch.id]?.x ?? 0,
|
57
|
-
velocityY: prevVelocityRef.current[touch.id]?.y ?? 0,
|
58
|
-
};
|
59
|
-
|
60
|
-
// Save previous touch
|
61
|
-
prevTouchInfoRef.current[touch.id] = touch;
|
62
|
-
|
63
|
-
if (touch.type === TouchType.Start) {
|
64
|
-
delete prevVelocityRef.current[touch.id];
|
65
|
-
handlers.onStart && handlers.onStart(touch);
|
66
|
-
} else if (touch.type === TouchType.Active) {
|
67
|
-
handlers.onActive && handlers.onActive(extendedTouchInfo);
|
68
|
-
} else {
|
69
|
-
handlers.onEnd && handlers.onEnd(extendedTouchInfo);
|
70
|
-
}
|
71
|
-
}
|
72
|
-
});
|
73
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
74
|
-
}, deps);
|
75
|
-
};
|
76
|
-
|
77
|
-
/**
|
78
|
-
* Provides a callback for handling touch events in the Skia View.
|
79
|
-
* This touch handler only handles single touches.
|
80
|
-
* @param handlers Callbacks for the different touch states
|
81
|
-
* @param deps optional Dependency array to update the handlers
|
82
|
-
* @returns A function that can be used from within the onDraw callback to
|
83
|
-
* update and handle touch events. Call it with the touches property from
|
84
|
-
* the info object.
|
85
|
-
*/
|
86
|
-
export const useTouchHandler = (
|
87
|
-
handlers: TouchHandlers,
|
88
|
-
deps: DependencyList = []
|
89
|
-
): TouchHandler => {
|
90
|
-
return useInternalTouchHandler(handlers, deps, false);
|
91
|
-
};
|
92
|
-
|
93
|
-
/**
|
94
|
-
* Provides a callback for handling touch events in the Skia View.
|
95
|
-
* This touch handler handles multiple touches.
|
96
|
-
* @param handlers Callbacks for the different touch states
|
97
|
-
* @param deps optional Dependency array to update the handlers
|
98
|
-
* @returns A function that can be used from within the onDraw callback to
|
99
|
-
* update and handle touch events. Call it with the touches property from
|
100
|
-
* the info object.
|
101
|
-
*/
|
102
|
-
export const useMultiTouchHandler = (
|
103
|
-
handlers: TouchHandlers,
|
104
|
-
deps: DependencyList = []
|
105
|
-
): TouchHandler => {
|
106
|
-
return useInternalTouchHandler(handlers, deps, true);
|
107
|
-
};
|