@shopify/react-native-skia 0.1.188 → 0.1.190
Sign up to get free protection for your applications and to get access to all the features.
- package/cpp/api/JsiSkMatrix.h +6 -6
- package/ios/RNSkia-iOS/ViewScreenshotService.mm +13 -1
- package/jestSetup.js +17 -3
- package/lib/commonjs/Platform/IPlatform.d.ts +12 -0
- package/lib/commonjs/Platform/IPlatform.js +6 -0
- package/lib/commonjs/Platform/IPlatform.js.map +1 -0
- package/lib/commonjs/Platform/Platform.d.ts +2 -0
- package/lib/commonjs/Platform/Platform.js +24 -0
- package/lib/commonjs/Platform/Platform.js.map +1 -0
- package/lib/commonjs/Platform/Platform.web.d.ts +2 -0
- package/lib/commonjs/Platform/Platform.web.js +157 -0
- package/lib/commonjs/Platform/Platform.web.js.map +1 -0
- package/lib/commonjs/Platform/index.d.ts +1 -0
- package/lib/commonjs/Platform/index.js +19 -0
- package/lib/commonjs/Platform/index.js.map +1 -0
- package/lib/commonjs/skia/NativeSetup.js +3 -3
- package/lib/commonjs/skia/NativeSetup.js.map +1 -1
- package/lib/commonjs/skia/core/Data.js +2 -8
- package/lib/commonjs/skia/core/Data.js.map +1 -1
- package/lib/commonjs/skia/core/Image.js +3 -3
- package/lib/commonjs/skia/core/Image.js.map +1 -1
- package/lib/commonjs/skia/types/Matrix.d.ts +6 -6
- package/lib/commonjs/skia/types/Matrix.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkMatrix.d.ts +6 -6
- package/lib/commonjs/skia/web/JsiSkMatrix.js +6 -0
- package/lib/commonjs/skia/web/JsiSkMatrix.js.map +1 -1
- package/lib/commonjs/views/SkiaBaseWebView.d.ts +6 -1
- package/lib/commonjs/views/SkiaBaseWebView.js +32 -25
- package/lib/commonjs/views/SkiaBaseWebView.js.map +1 -1
- package/lib/commonjs/views/SkiaDomView.js +2 -2
- package/lib/commonjs/views/SkiaDomView.js.map +1 -1
- package/lib/commonjs/views/SkiaPictureView.js +2 -2
- package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
- package/lib/commonjs/views/SkiaView.js +3 -2
- package/lib/commonjs/views/SkiaView.js.map +1 -1
- package/lib/commonjs/views/useTouchHandler.js +3 -3
- package/lib/commonjs/views/useTouchHandler.js.map +1 -1
- package/lib/commonjs/web/WithSkiaWeb.js +2 -2
- package/lib/commonjs/web/WithSkiaWeb.js.map +1 -1
- package/lib/module/Platform/IPlatform.d.ts +12 -0
- package/lib/module/Platform/IPlatform.js +2 -0
- package/lib/module/Platform/IPlatform.js.map +1 -0
- package/lib/module/Platform/Platform.d.ts +2 -0
- package/lib/module/Platform/Platform.js +14 -0
- package/lib/module/Platform/Platform.js.map +1 -0
- package/lib/module/Platform/Platform.web.d.ts +2 -0
- package/lib/module/Platform/Platform.web.js +143 -0
- package/lib/module/Platform/Platform.web.js.map +1 -0
- package/lib/module/Platform/index.d.ts +1 -0
- package/lib/module/Platform/index.js +2 -0
- package/lib/module/Platform/index.js.map +1 -0
- package/lib/module/skia/NativeSetup.js +2 -2
- package/lib/module/skia/NativeSetup.js.map +1 -1
- package/lib/module/skia/core/Data.js +2 -7
- package/lib/module/skia/core/Data.js.map +1 -1
- package/lib/module/skia/core/Image.js +2 -2
- package/lib/module/skia/core/Image.js.map +1 -1
- package/lib/module/skia/types/Matrix.d.ts +6 -6
- package/lib/module/skia/types/Matrix.js.map +1 -1
- package/lib/module/skia/web/JsiSkMatrix.d.ts +6 -6
- package/lib/module/skia/web/JsiSkMatrix.js +6 -0
- package/lib/module/skia/web/JsiSkMatrix.js.map +1 -1
- package/lib/module/views/SkiaBaseWebView.d.ts +6 -1
- package/lib/module/views/SkiaBaseWebView.js +31 -24
- package/lib/module/views/SkiaBaseWebView.js.map +1 -1
- package/lib/module/views/SkiaDomView.js +2 -2
- package/lib/module/views/SkiaDomView.js.map +1 -1
- package/lib/module/views/SkiaPictureView.js +2 -2
- package/lib/module/views/SkiaPictureView.js.map +1 -1
- package/lib/module/views/SkiaView.js +2 -2
- package/lib/module/views/SkiaView.js.map +1 -1
- package/lib/module/views/useTouchHandler.js +3 -3
- package/lib/module/views/useTouchHandler.js.map +1 -1
- package/lib/module/web/WithSkiaWeb.js +1 -1
- package/lib/module/web/WithSkiaWeb.js.map +1 -1
- package/lib/typescript/src/Platform/IPlatform.d.ts +12 -0
- package/lib/typescript/src/Platform/Platform.d.ts +2 -0
- package/lib/typescript/src/Platform/Platform.web.d.ts +2 -0
- package/lib/typescript/src/Platform/index.d.ts +1 -0
- package/lib/typescript/src/skia/types/Matrix.d.ts +6 -6
- package/lib/typescript/src/skia/web/JsiSkMatrix.d.ts +6 -6
- package/lib/typescript/src/views/SkiaBaseWebView.d.ts +6 -1
- package/package.json +9 -9
- package/src/Platform/IPlatform.ts +20 -0
- package/src/Platform/Platform.ts +28 -0
- package/src/Platform/Platform.web.tsx +136 -0
- package/src/Platform/index.ts +1 -0
- package/src/skia/NativeSetup.ts +2 -2
- package/src/skia/core/Data.ts +4 -15
- package/src/skia/core/Image.ts +2 -3
- package/src/skia/types/Matrix.ts +6 -6
- package/src/skia/web/JsiSkMatrix.ts +6 -0
- package/src/views/SkiaBaseWebView.tsx +24 -19
- package/src/views/SkiaDomView.tsx +2 -2
- package/src/views/SkiaPictureView.tsx +2 -2
- package/src/views/SkiaView.tsx +2 -2
- package/src/views/useTouchHandler.ts +3 -3
- package/src/web/WithSkiaWeb.tsx +2 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["useCallback","useRef","
|
1
|
+
{"version":3,"names":["useCallback","useRef","Platform","TouchType","useInternalTouchHandler","handlers","deps","multiTouch","prevTouchInfoRef","prevVelocityRef","history","forEach","touches","i","length","touch","prevTouch","current","id","timeDiffseconds","timestamp","distX","x","distY","y","type","Start","End","Cancelled","PixelRatio","extendedTouchInfo","velocityX","velocityY","onStart","Active","onActive","onEnd","useTouchHandler","useMultiTouchHandler"],"sources":["useTouchHandler.ts"],"sourcesContent":["import type { DependencyList } from \"react\";\nimport { useCallback, useRef } from \"react\";\n\nimport type { Vector } from \"../skia/types\";\nimport { Platform } from \"../Platform\";\n\nimport type {\n ExtendedTouchInfo,\n TouchHandlers,\n TouchHandler,\n TouchInfo,\n} from \"./types\";\nimport { TouchType } from \"./types\";\n\nconst useInternalTouchHandler = (\n handlers: TouchHandlers,\n deps: DependencyList = [],\n multiTouch = false\n): TouchHandler => {\n const prevTouchInfoRef = useRef<{ [key: number]: TouchInfo | undefined }>({});\n const prevVelocityRef = useRef<{ [key: number]: Vector | undefined }>({});\n\n return useCallback((history: Array<Array<TouchInfo>>) => {\n // Process all items in the current touch history\n history.forEach((touches) => {\n // Enumerate touches\n for (let i = 0; i < touches.length; i++) {\n if (!multiTouch && i > 0) {\n break;\n }\n\n const touch = touches[i];\n const prevTouch = prevTouchInfoRef.current[touch.id];\n // Calculate the velocity from the previous touch.\n const timeDiffseconds =\n touch.timestamp -\n (prevTouchInfoRef.current[touch.id]?.timestamp ?? touch.timestamp);\n\n const distX = touch.x - (prevTouch?.x ?? touch.x);\n const distY = touch.y - (prevTouch?.y ?? touch.y);\n\n if (\n touch.type !== TouchType.Start &&\n touch.type !== TouchType.End &&\n touch.type !== TouchType.Cancelled &&\n timeDiffseconds > 0\n ) {\n prevVelocityRef.current[touch.id] = {\n x: distX / timeDiffseconds / Platform.PixelRatio,\n y: distY / timeDiffseconds / Platform.PixelRatio,\n };\n }\n\n const extendedTouchInfo: ExtendedTouchInfo = {\n ...touch,\n velocityX: prevVelocityRef.current[touch.id]?.x ?? 0,\n velocityY: prevVelocityRef.current[touch.id]?.y ?? 0,\n };\n\n // Save previous touch\n prevTouchInfoRef.current[touch.id] = touch;\n\n if (touch.type === TouchType.Start) {\n delete prevVelocityRef.current[touch.id];\n handlers.onStart && handlers.onStart(touch);\n } else if (touch.type === TouchType.Active) {\n handlers.onActive && handlers.onActive(extendedTouchInfo);\n } else {\n handlers.onEnd && handlers.onEnd(extendedTouchInfo);\n }\n }\n });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n};\n\n/**\n * Provides a callback for handling touch events in the Skia View.\n * This touch handler only handles single touches.\n * @param handlers Callbacks for the different touch states\n * @param deps optional Dependency array to update the handlers\n * @returns A function that can be used from within the onDraw callback to\n * update and handle touch events. Call it with the touches property from\n * the info object.\n */\nexport const useTouchHandler = (\n handlers: TouchHandlers,\n deps: DependencyList = []\n): TouchHandler => {\n return useInternalTouchHandler(handlers, deps, false);\n};\n\n/**\n * Provides a callback for handling touch events in the Skia View.\n * This touch handler handles multiple touches.\n * @param handlers Callbacks for the different touch states\n * @param deps optional Dependency array to update the handlers\n * @returns A function that can be used from within the onDraw callback to\n * update and handle touch events. Call it with the touches property from\n * the info object.\n */\nexport const useMultiTouchHandler = (\n handlers: TouchHandlers,\n deps: DependencyList = []\n): TouchHandler => {\n return useInternalTouchHandler(handlers, deps, true);\n};\n"],"mappings":"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"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["React","useMemo","lazy","Suspense","Platform","LoadSkiaWeb","WithSkiaWeb","getComponent","fallback","opts","Inner","OS","console","warn"],"sources":["WithSkiaWeb.tsx"],"sourcesContent":["import type { ComponentProps, ComponentType } from \"react\";\nimport React, { useMemo, lazy, Suspense } from \"react\";\nimport { Platform } from \"
|
1
|
+
{"version":3,"names":["React","useMemo","lazy","Suspense","Platform","LoadSkiaWeb","WithSkiaWeb","getComponent","fallback","opts","Inner","OS","console","warn"],"sources":["WithSkiaWeb.tsx"],"sourcesContent":["import type { ComponentProps, ComponentType } from \"react\";\nimport React, { useMemo, lazy, Suspense } from \"react\";\n\nimport { Platform } from \"../Platform\";\n\nimport { LoadSkiaWeb } from \"./LoadSkiaWeb\";\n\ninterface WithSkiaProps {\n fallback?: ComponentProps<typeof Suspense>[\"fallback\"];\n getComponent: () => Promise<{ default: ComponentType }>;\n opts?: Parameters<typeof LoadSkiaWeb>[0];\n}\n\nexport const WithSkiaWeb = ({\n getComponent,\n fallback,\n opts,\n}: WithSkiaProps) => {\n const Inner = useMemo(\n // TODO: investigate\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (): any =>\n lazy(async () => {\n if (Platform.OS === \"web\") {\n await LoadSkiaWeb(opts);\n } else {\n console.warn(\n \"<WithSkiaWeb /> is only necessary on web. Consider not using on native.\"\n );\n }\n return getComponent();\n }),\n [getComponent, opts]\n );\n return (\n <Suspense fallback={fallback ?? null}>\n <Inner />\n </Suspense>\n );\n};\n"],"mappings":"AACA,OAAOA,KAAP,IAAgBC,OAAhB,EAAyBC,IAAzB,EAA+BC,QAA/B,QAA+C,OAA/C;AAEA,SAASC,QAAT,QAAyB,aAAzB;AAEA,SAASC,WAAT,QAA4B,eAA5B;AAQA,OAAO,MAAMC,WAAW,GAAG,QAIN;EAAA,IAJO;IAC1BC,YAD0B;IAE1BC,QAF0B;IAG1BC;EAH0B,CAIP;EACnB,MAAMC,KAAK,GAAGT,OAAO,EACnB;EACA;EACA,mBACEC,IAAI,CAAC,YAAY;IACf,IAAIE,QAAQ,CAACO,EAAT,KAAgB,KAApB,EAA2B;MACzB,MAAMN,WAAW,CAACI,IAAD,CAAjB;IACD,CAFD,MAEO;MACLG,OAAO,CAACC,IAAR,CACE,yEADF;IAGD;;IACD,OAAON,YAAY,EAAnB;EACD,CATG,CAJa,EAcnB,CAACA,YAAD,EAAeE,IAAf,CAdmB,CAArB;EAgBA,oBACE,oBAAC,QAAD;IAAU,QAAQ,EAAED,QAAF,aAAEA,QAAF,cAAEA,QAAF,GAAc;EAAhC,gBACE,oBAAC,KAAD,OADF,CADF;AAKD,CA1BM"}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
import type { HostComponent, NodeHandle, ViewComponent } from "react-native";
|
3
|
+
import type { DataModule } from "../skia/types";
|
4
|
+
export interface IPlatform {
|
5
|
+
OS: string;
|
6
|
+
requireNativeComponent: <T>(viewName: string) => HostComponent<T>;
|
7
|
+
PixelRatio: number;
|
8
|
+
NativeModules: Record<string, any>;
|
9
|
+
findNodeHandle: (componentOrHandle: null | number | React.Component<any, any> | React.ComponentClass<any>) => null | NodeHandle;
|
10
|
+
resolveAsset: (source: DataModule) => string;
|
11
|
+
View: typeof ViewComponent;
|
12
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from "./Platform";
|
@@ -13,12 +13,12 @@ export declare enum MatrixIndex {
|
|
13
13
|
}
|
14
14
|
export declare const isMatrix: (obj: unknown) => obj is SkMatrix;
|
15
15
|
export interface SkMatrix extends SkJSIInstance<"Matrix"> {
|
16
|
-
concat: (matrix: SkMatrix) =>
|
17
|
-
translate: (x: number, y: number) =>
|
18
|
-
scale: (x: number, y?: number) =>
|
19
|
-
skew: (x: number, y: number) =>
|
20
|
-
rotate: (theta: number) =>
|
21
|
-
identity: () =>
|
16
|
+
concat: (matrix: SkMatrix) => SkMatrix;
|
17
|
+
translate: (x: number, y: number) => SkMatrix;
|
18
|
+
scale: (x: number, y?: number) => SkMatrix;
|
19
|
+
skew: (x: number, y: number) => SkMatrix;
|
20
|
+
rotate: (theta: number) => SkMatrix;
|
21
|
+
identity: () => SkMatrix;
|
22
22
|
get: () => number[];
|
23
23
|
}
|
24
24
|
declare type Transform2dName = "translateX" | "translateY" | "scale" | "skewX" | "skewY" | "scaleX" | "scaleY" | "rotateZ" | "rotate";
|
@@ -3,11 +3,11 @@ import type { SkMatrix } from "../types";
|
|
3
3
|
import { HostObject } from "./Host";
|
4
4
|
export declare class JsiSkMatrix extends HostObject<Matrix3x3, "Matrix"> implements SkMatrix {
|
5
5
|
constructor(CanvasKit: CanvasKit, ref: Matrix3x3);
|
6
|
-
concat(matrix: SkMatrix):
|
7
|
-
translate(x: number, y: number):
|
8
|
-
scale(x: number, y?: number):
|
9
|
-
skew(x: number, y: number):
|
10
|
-
rotate(value: number):
|
11
|
-
identity():
|
6
|
+
concat(matrix: SkMatrix): this;
|
7
|
+
translate(x: number, y: number): this;
|
8
|
+
scale(x: number, y?: number): this;
|
9
|
+
skew(x: number, y: number): this;
|
10
|
+
rotate(value: number): this;
|
11
|
+
identity(): this;
|
12
12
|
get(): number[];
|
13
13
|
}
|
@@ -17,7 +17,7 @@ export declare abstract class SkiaBaseWebView<TProps extends SkiaBaseViewProps>
|
|
17
17
|
protected width: number;
|
18
18
|
protected height: number;
|
19
19
|
private unsubscribeAll;
|
20
|
-
private
|
20
|
+
private onLayoutEvent;
|
21
21
|
protected getSize(): {
|
22
22
|
width: number;
|
23
23
|
height: number;
|
@@ -58,5 +58,10 @@ export declare abstract class SkiaBaseWebView<TProps extends SkiaBaseViewProps>
|
|
58
58
|
registerValues(_values: SkiaValue<unknown>[]): void;
|
59
59
|
private handleTouchEvent;
|
60
60
|
createTouchHandler(touchType: TouchType): (evt: PointerEvent) => void;
|
61
|
+
private onStart;
|
62
|
+
private onActive;
|
63
|
+
private onCancel;
|
64
|
+
private onEnd;
|
65
|
+
private onLayout;
|
61
66
|
render(): JSX.Element;
|
62
67
|
}
|
package/package.json
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
"setup-skia-web": "./scripts/setup-canvaskit.js"
|
8
8
|
},
|
9
9
|
"title": "React Native Skia",
|
10
|
-
"version": "0.1.
|
10
|
+
"version": "0.1.190",
|
11
11
|
"description": "High-performance React Native Graphics using Skia",
|
12
12
|
"main": "lib/module/index.js",
|
13
13
|
"files": [
|
@@ -81,28 +81,28 @@
|
|
81
81
|
"devDependencies": {
|
82
82
|
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
|
83
83
|
"@types/jest": "^28.1.6",
|
84
|
+
"@types/pixelmatch": "^5.2.4",
|
85
|
+
"@types/pngjs": "^6.0.1",
|
84
86
|
"@types/react-native": "0.70.6",
|
85
87
|
"@types/react-reconciler": "^0.26.7",
|
88
|
+
"@types/ws": "^8.5.3",
|
86
89
|
"eslint": "8.21.0",
|
87
90
|
"eslint-config-react-native-wcandillon": "3.9.0",
|
88
91
|
"eslint-plugin-reanimated": "2.0.0",
|
89
92
|
"jest": "28.1.3",
|
90
93
|
"merge-dirs": "^0.2.1",
|
94
|
+
"pixelmatch": "^5.3.0",
|
95
|
+
"pngjs": "^6.0.0",
|
91
96
|
"react": "18.1.0",
|
92
97
|
"react-native": "0.71.7",
|
93
98
|
"react-native-builder-bob": "^0.18.2",
|
94
99
|
"ts-jest": "^28.0.7",
|
95
|
-
"typescript": "4.8.3"
|
100
|
+
"typescript": "4.8.3",
|
101
|
+
"ws": "^8.11.0"
|
96
102
|
},
|
97
103
|
"dependencies": {
|
98
|
-
"@types/pixelmatch": "^5.2.4",
|
99
|
-
"@types/pngjs": "^6.0.1",
|
100
|
-
"@types/ws": "^8.5.3",
|
101
104
|
"canvaskit-wasm": "0.38.0",
|
102
|
-
"
|
103
|
-
"pngjs": "^6.0.0",
|
104
|
-
"react-reconciler": "^0.27.0",
|
105
|
-
"ws": "^8.11.0"
|
105
|
+
"react-reconciler": "^0.27.0"
|
106
106
|
},
|
107
107
|
"eslintIgnore": [
|
108
108
|
"node_modules/",
|
@@ -0,0 +1,20 @@
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
2
|
+
import type { HostComponent, NodeHandle, ViewComponent } from "react-native";
|
3
|
+
|
4
|
+
import type { DataModule } from "../skia/types";
|
5
|
+
|
6
|
+
export interface IPlatform {
|
7
|
+
OS: string;
|
8
|
+
requireNativeComponent: <T>(viewName: string) => HostComponent<T>;
|
9
|
+
PixelRatio: number;
|
10
|
+
NativeModules: Record<string, any>;
|
11
|
+
findNodeHandle: (
|
12
|
+
componentOrHandle:
|
13
|
+
| null
|
14
|
+
| number
|
15
|
+
| React.Component<any, any>
|
16
|
+
| React.ComponentClass<any>
|
17
|
+
) => null | NodeHandle;
|
18
|
+
resolveAsset: (source: DataModule) => string;
|
19
|
+
View: typeof ViewComponent;
|
20
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import {
|
2
|
+
Image,
|
3
|
+
PixelRatio,
|
4
|
+
requireNativeComponent,
|
5
|
+
Platform as RNPlatform,
|
6
|
+
findNodeHandle,
|
7
|
+
NativeModules,
|
8
|
+
View,
|
9
|
+
} from "react-native";
|
10
|
+
|
11
|
+
import type { DataModule } from "../skia/types";
|
12
|
+
import { isRNModule } from "../skia/types";
|
13
|
+
|
14
|
+
import type { IPlatform } from "./IPlatform";
|
15
|
+
|
16
|
+
export const Platform: IPlatform = {
|
17
|
+
OS: RNPlatform.OS,
|
18
|
+
PixelRatio: PixelRatio.get(),
|
19
|
+
requireNativeComponent,
|
20
|
+
resolveAsset: (source: DataModule) => {
|
21
|
+
return isRNModule(source)
|
22
|
+
? Image.resolveAssetSource(source).uri
|
23
|
+
: source.default;
|
24
|
+
},
|
25
|
+
findNodeHandle,
|
26
|
+
NativeModules,
|
27
|
+
View,
|
28
|
+
};
|
@@ -0,0 +1,136 @@
|
|
1
|
+
import type { RefObject, CSSProperties } from "react";
|
2
|
+
import React, { useLayoutEffect, useMemo, useRef } from "react";
|
3
|
+
import type { LayoutChangeEvent, ViewComponent, ViewProps } from "react-native";
|
4
|
+
|
5
|
+
import type { DataModule } from "../skia/types";
|
6
|
+
import { isRNModule } from "../skia/types";
|
7
|
+
|
8
|
+
import type { IPlatform } from "./IPlatform";
|
9
|
+
|
10
|
+
// eslint-disable-next-line max-len
|
11
|
+
// https://github.com/necolas/react-native-web/blob/master/packages/react-native-web/src/modules/useElementLayout/index.js
|
12
|
+
const DOM_LAYOUT_HANDLER_NAME = "__reactLayoutHandler";
|
13
|
+
type OnLayout = ((event: LayoutChangeEvent) => void) | undefined;
|
14
|
+
type Div = HTMLDivElement & {
|
15
|
+
__reactLayoutHandler: OnLayout;
|
16
|
+
};
|
17
|
+
|
18
|
+
let resizeObserver: ResizeObserver | null = null;
|
19
|
+
|
20
|
+
const getObserver = () => {
|
21
|
+
if (resizeObserver == null) {
|
22
|
+
resizeObserver = new window.ResizeObserver(function (entries) {
|
23
|
+
entries.forEach((entry) => {
|
24
|
+
const node = entry.target as Div;
|
25
|
+
const { left, top, width, height } = entry.contentRect;
|
26
|
+
const onLayout = node[DOM_LAYOUT_HANDLER_NAME];
|
27
|
+
if (typeof onLayout === "function") {
|
28
|
+
// setTimeout 0 is taken from react-native-web (UIManager)
|
29
|
+
setTimeout(
|
30
|
+
() =>
|
31
|
+
onLayout({
|
32
|
+
timeStamp: Date.now(),
|
33
|
+
nativeEvent: { layout: { x: left, y: top, width, height } },
|
34
|
+
currentTarget: 0,
|
35
|
+
target: 0,
|
36
|
+
bubbles: false,
|
37
|
+
cancelable: false,
|
38
|
+
defaultPrevented: false,
|
39
|
+
eventPhase: 0,
|
40
|
+
isDefaultPrevented() {
|
41
|
+
throw new Error("Method not supported on web.");
|
42
|
+
},
|
43
|
+
isPropagationStopped() {
|
44
|
+
throw new Error("Method not supported on web.");
|
45
|
+
},
|
46
|
+
persist() {
|
47
|
+
throw new Error("Method not supported on web.");
|
48
|
+
},
|
49
|
+
preventDefault() {
|
50
|
+
throw new Error("Method not supported on web.");
|
51
|
+
},
|
52
|
+
stopPropagation() {
|
53
|
+
throw new Error("Method not supported on web.");
|
54
|
+
},
|
55
|
+
isTrusted: true,
|
56
|
+
type: "",
|
57
|
+
}),
|
58
|
+
0
|
59
|
+
);
|
60
|
+
}
|
61
|
+
});
|
62
|
+
});
|
63
|
+
}
|
64
|
+
return resizeObserver;
|
65
|
+
};
|
66
|
+
|
67
|
+
const useElementLayout = (ref: RefObject<Div>, onLayout: OnLayout) => {
|
68
|
+
const observer = getObserver();
|
69
|
+
|
70
|
+
useLayoutEffect(() => {
|
71
|
+
const node = ref.current;
|
72
|
+
if (node !== null) {
|
73
|
+
node[DOM_LAYOUT_HANDLER_NAME] = onLayout;
|
74
|
+
}
|
75
|
+
}, [ref, onLayout]);
|
76
|
+
|
77
|
+
useLayoutEffect(() => {
|
78
|
+
const node = ref.current;
|
79
|
+
if (node != null && observer != null) {
|
80
|
+
if (typeof node[DOM_LAYOUT_HANDLER_NAME] === "function") {
|
81
|
+
observer.observe(node);
|
82
|
+
} else {
|
83
|
+
observer.unobserve(node);
|
84
|
+
}
|
85
|
+
}
|
86
|
+
return () => {
|
87
|
+
if (node != null && observer != null) {
|
88
|
+
observer.unobserve(node);
|
89
|
+
}
|
90
|
+
};
|
91
|
+
}, [observer, ref]);
|
92
|
+
};
|
93
|
+
|
94
|
+
const View = (({ children, onLayout, style: rawStyle }: ViewProps) => {
|
95
|
+
const style = useMemo(() => (rawStyle ?? {}) as CSSProperties, [rawStyle]);
|
96
|
+
const ref = useRef<Div>(null);
|
97
|
+
useElementLayout(ref, onLayout);
|
98
|
+
const cssStyles = useMemo(() => {
|
99
|
+
return {
|
100
|
+
...style,
|
101
|
+
display: "flex",
|
102
|
+
flexDirection: style.flexDirection || "column",
|
103
|
+
flexWrap: style.flexWrap || "nowrap",
|
104
|
+
justifyContent: style.justifyContent || "flex-start",
|
105
|
+
alignItems: style.alignItems || "stretch",
|
106
|
+
alignContent: style.alignContent || "stretch",
|
107
|
+
};
|
108
|
+
}, [style]);
|
109
|
+
|
110
|
+
return (
|
111
|
+
<div ref={ref} style={cssStyles}>
|
112
|
+
{children}
|
113
|
+
</div>
|
114
|
+
);
|
115
|
+
}) as unknown as typeof ViewComponent;
|
116
|
+
|
117
|
+
export const Platform: IPlatform = {
|
118
|
+
OS: "web",
|
119
|
+
PixelRatio: window.devicePixelRatio,
|
120
|
+
requireNativeComponent: () => {
|
121
|
+
throw new Error("requireNativeComponent is not supported on the web");
|
122
|
+
},
|
123
|
+
resolveAsset: (source: DataModule) => {
|
124
|
+
if (isRNModule(source)) {
|
125
|
+
throw new Error(
|
126
|
+
"Image source is a number - this is not supported on the web"
|
127
|
+
);
|
128
|
+
}
|
129
|
+
return source.default;
|
130
|
+
},
|
131
|
+
findNodeHandle: () => {
|
132
|
+
throw new Error("findNodeHandle is not supported on the web");
|
133
|
+
},
|
134
|
+
NativeModules: {},
|
135
|
+
View,
|
136
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from "./Platform";
|
package/src/skia/NativeSetup.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
import {
|
1
|
+
import { Platform } from "../Platform";
|
2
2
|
|
3
3
|
if (Platform.OS !== "web" && global.SkiaApi == null) {
|
4
4
|
// Initialize RN Skia
|
5
|
-
const SkiaModule = NativeModules.RNSkia;
|
5
|
+
const SkiaModule = Platform.NativeModules.RNSkia;
|
6
6
|
if (SkiaModule == null || typeof SkiaModule.install !== "function") {
|
7
7
|
throw new Error(
|
8
8
|
"Native RNSkia Module cannot be found! Make sure you correctly " +
|
package/src/skia/core/Data.ts
CHANGED
@@ -1,20 +1,8 @@
|
|
1
1
|
import { useEffect, useRef, useState } from "react";
|
2
|
-
import { Image } from "react-native";
|
3
2
|
|
4
3
|
import { Skia } from "../Skia";
|
5
|
-
import {
|
6
|
-
import
|
7
|
-
SkData,
|
8
|
-
DataModule,
|
9
|
-
DataSourceParam,
|
10
|
-
JsiDisposable,
|
11
|
-
} from "../types";
|
12
|
-
|
13
|
-
const resolveAsset = (source: DataModule) => {
|
14
|
-
return isRNModule(source)
|
15
|
-
? Image.resolveAssetSource(source).uri
|
16
|
-
: source.default;
|
17
|
-
};
|
4
|
+
import type { SkData, DataSourceParam, JsiDisposable } from "../types";
|
5
|
+
import { Platform } from "../../Platform";
|
18
6
|
|
19
7
|
const factoryWrapper = <T>(
|
20
8
|
data2: SkData,
|
@@ -42,7 +30,8 @@ const loadData = <T>(
|
|
42
30
|
resolve(factoryWrapper(Skia.Data.fromBytes(source), factory, onError))
|
43
31
|
);
|
44
32
|
} else {
|
45
|
-
const uri =
|
33
|
+
const uri =
|
34
|
+
typeof source === "string" ? source : Platform.resolveAsset(source);
|
46
35
|
return Skia.Data.fromURI(uri).then((d) =>
|
47
36
|
factoryWrapper(d, factory, onError)
|
48
37
|
);
|
package/src/skia/core/Image.ts
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
import {
|
2
|
-
|
1
|
+
import { Platform } from "../../Platform";
|
3
2
|
import { Skia } from "../Skia";
|
4
3
|
import type { DataSourceParam, SkImage } from "../types";
|
5
4
|
|
@@ -48,7 +47,7 @@ export const makeImageFromView = <
|
|
48
47
|
);
|
49
48
|
}
|
50
49
|
}
|
51
|
-
const viewTag = findNodeHandle(viewRef.current);
|
50
|
+
const viewTag = Platform.findNodeHandle(viewRef.current);
|
52
51
|
if (viewTag !== null && viewTag !== 0) {
|
53
52
|
return Skia.Image.MakeImageFromViewTag(viewTag);
|
54
53
|
}
|
package/src/skia/types/Matrix.ts
CHANGED
@@ -16,12 +16,12 @@ export const isMatrix = (obj: unknown): obj is SkMatrix =>
|
|
16
16
|
obj !== null && (obj as SkJSIInstance<string>).__typename__ === "Matrix";
|
17
17
|
|
18
18
|
export interface SkMatrix extends SkJSIInstance<"Matrix"> {
|
19
|
-
concat: (matrix: SkMatrix) =>
|
20
|
-
translate: (x: number, y: number) =>
|
21
|
-
scale: (x: number, y?: number) =>
|
22
|
-
skew: (x: number, y: number) =>
|
23
|
-
rotate: (theta: number) =>
|
24
|
-
identity: () =>
|
19
|
+
concat: (matrix: SkMatrix) => SkMatrix;
|
20
|
+
translate: (x: number, y: number) => SkMatrix;
|
21
|
+
scale: (x: number, y?: number) => SkMatrix;
|
22
|
+
skew: (x: number, y: number) => SkMatrix;
|
23
|
+
rotate: (theta: number) => SkMatrix;
|
24
|
+
identity: () => SkMatrix;
|
25
25
|
get: () => number[];
|
26
26
|
}
|
27
27
|
|
@@ -16,6 +16,7 @@ export class JsiSkMatrix
|
|
16
16
|
this.ref.set(
|
17
17
|
this.CanvasKit.Matrix.multiply(this.ref, JsiSkMatrix.fromValue(matrix))
|
18
18
|
);
|
19
|
+
return this;
|
19
20
|
}
|
20
21
|
|
21
22
|
translate(x: number, y: number) {
|
@@ -25,6 +26,7 @@ export class JsiSkMatrix
|
|
25
26
|
Float32Array.of(...this.CanvasKit.Matrix.translated(x, y))
|
26
27
|
)
|
27
28
|
);
|
29
|
+
return this;
|
28
30
|
}
|
29
31
|
|
30
32
|
scale(x: number, y?: number) {
|
@@ -34,6 +36,7 @@ export class JsiSkMatrix
|
|
34
36
|
Float32Array.of(...this.CanvasKit.Matrix.scaled(x, y ?? x))
|
35
37
|
)
|
36
38
|
);
|
39
|
+
return this;
|
37
40
|
}
|
38
41
|
|
39
42
|
skew(x: number, y: number) {
|
@@ -43,6 +46,7 @@ export class JsiSkMatrix
|
|
43
46
|
Float32Array.of(...this.CanvasKit.Matrix.skewed(x, y))
|
44
47
|
)
|
45
48
|
);
|
49
|
+
return this;
|
46
50
|
}
|
47
51
|
|
48
52
|
rotate(value: number) {
|
@@ -52,10 +56,12 @@ export class JsiSkMatrix
|
|
52
56
|
Float32Array.of(...this.CanvasKit.Matrix.rotated(value))
|
53
57
|
)
|
54
58
|
);
|
59
|
+
return this;
|
55
60
|
}
|
56
61
|
|
57
62
|
identity() {
|
58
63
|
this.ref.set(this.CanvasKit.Matrix.identity());
|
64
|
+
return this;
|
59
65
|
}
|
60
66
|
|
61
67
|
get() {
|
@@ -2,16 +2,16 @@
|
|
2
2
|
import React from "react";
|
3
3
|
import type { PointerEvent } from "react";
|
4
4
|
import type { LayoutChangeEvent } from "react-native";
|
5
|
-
import { PixelRatio, View } from "react-native";
|
6
5
|
|
7
6
|
import type { SkRect, SkCanvas } from "../skia/types";
|
8
7
|
import type { SkiaValue } from "../values";
|
9
8
|
import { JsiSkSurface } from "../skia/web/JsiSkSurface";
|
9
|
+
import { Platform } from "../Platform";
|
10
10
|
|
11
11
|
import type { DrawMode, SkiaBaseViewProps, TouchInfo } from "./types";
|
12
12
|
import { TouchType } from "./types";
|
13
13
|
|
14
|
-
const pd = PixelRatio
|
14
|
+
const pd = Platform.PixelRatio;
|
15
15
|
|
16
16
|
export abstract class SkiaBaseWebView<
|
17
17
|
TProps extends SkiaBaseViewProps
|
@@ -38,17 +38,16 @@ export abstract class SkiaBaseWebView<
|
|
38
38
|
this._unsubscriptions = [];
|
39
39
|
}
|
40
40
|
|
41
|
-
private
|
41
|
+
private onLayoutEvent(evt: LayoutChangeEvent) {
|
42
42
|
const { CanvasKit } = global;
|
43
|
-
const { width, height } = evt.nativeEvent.layout;
|
44
|
-
this.width = width;
|
45
|
-
this.height = height;
|
46
43
|
// Reset canvas / surface on layout change
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
44
|
+
const canvas = this._canvasRef.current;
|
45
|
+
if (canvas) {
|
46
|
+
this.width = canvas.clientWidth;
|
47
|
+
this.height = canvas.clientHeight;
|
48
|
+
canvas.width = this.width * pd;
|
49
|
+
canvas.height = this.height * pd;
|
50
|
+
const surface = CanvasKit.MakeWebGLCanvasSurface(canvas);
|
52
51
|
if (!surface) {
|
53
52
|
throw new Error("Could not create surface");
|
54
53
|
}
|
@@ -178,21 +177,27 @@ export abstract class SkiaBaseWebView<
|
|
178
177
|
return (evt: PointerEvent) => this.handleTouchEvent(evt, touchType);
|
179
178
|
}
|
180
179
|
|
180
|
+
private onStart = this.createTouchHandler(TouchType.Start);
|
181
|
+
private onActive = this.createTouchHandler(TouchType.Active);
|
182
|
+
private onCancel = this.createTouchHandler(TouchType.Cancelled);
|
183
|
+
private onEnd = this.createTouchHandler(TouchType.End);
|
184
|
+
private onLayout = this.onLayoutEvent.bind(this);
|
185
|
+
|
181
186
|
render() {
|
182
187
|
const { mode, debug = false, ...viewProps } = this.props;
|
183
188
|
return (
|
184
|
-
<View {...viewProps} onLayout={this.onLayout
|
189
|
+
<Platform.View {...viewProps} onLayout={this.onLayout}>
|
185
190
|
<canvas
|
186
191
|
ref={this._canvasRef}
|
187
192
|
style={{ display: "flex", flex: 1 }}
|
188
|
-
onPointerDown={this.
|
189
|
-
onPointerMove={this.
|
190
|
-
onPointerUp={this.
|
191
|
-
onPointerCancel={this.
|
192
|
-
onPointerLeave={this.
|
193
|
-
onPointerOut={this.
|
193
|
+
onPointerDown={this.onStart}
|
194
|
+
onPointerMove={this.onActive}
|
195
|
+
onPointerUp={this.onEnd}
|
196
|
+
onPointerCancel={this.onCancel}
|
197
|
+
onPointerLeave={this.onEnd}
|
198
|
+
onPointerOut={this.onEnd}
|
194
199
|
/>
|
195
|
-
</View>
|
200
|
+
</Platform.View>
|
196
201
|
);
|
197
202
|
}
|
198
203
|
}
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import React from "react";
|
2
|
-
import { requireNativeComponent, Platform } from "react-native";
|
3
2
|
import type { HostComponent } from "react-native";
|
4
3
|
|
5
4
|
import type { SkRect } from "../skia/types";
|
6
5
|
import type { SkiaValue } from "../values";
|
6
|
+
import { Platform } from "../Platform";
|
7
7
|
|
8
8
|
import { SkiaViewApi } from "./api";
|
9
9
|
import { SkiaViewNativeId } from "./SkiaView";
|
@@ -11,7 +11,7 @@ import type { NativeSkiaViewProps, SkiaDomViewProps } from "./types";
|
|
11
11
|
|
12
12
|
const NativeSkiaDomView: HostComponent<SkiaDomViewProps> =
|
13
13
|
Platform.OS !== "web"
|
14
|
-
? requireNativeComponent<NativeSkiaViewProps>("SkiaDomView")
|
14
|
+
? Platform.requireNativeComponent<NativeSkiaViewProps>("SkiaDomView")
|
15
15
|
: // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
16
16
|
(null as any);
|
17
17
|
|
@@ -1,15 +1,15 @@
|
|
1
1
|
import React from "react";
|
2
|
-
import { requireNativeComponent } from "react-native";
|
3
2
|
|
4
3
|
import type { SkRect } from "../skia/types";
|
5
4
|
import type { SkiaValue } from "../values";
|
5
|
+
import { Platform } from "../Platform";
|
6
6
|
|
7
7
|
import { SkiaViewApi } from "./api";
|
8
8
|
import { SkiaViewNativeId } from "./SkiaView";
|
9
9
|
import type { NativeSkiaViewProps, SkiaPictureViewProps } from "./types";
|
10
10
|
|
11
11
|
const NativeSkiaPictureView =
|
12
|
-
requireNativeComponent<NativeSkiaViewProps>("SkiaPictureView");
|
12
|
+
Platform.requireNativeComponent<NativeSkiaViewProps>("SkiaPictureView");
|
13
13
|
|
14
14
|
export class SkiaPictureView extends React.Component<SkiaPictureViewProps> {
|
15
15
|
constructor(props: SkiaPictureViewProps) {
|
package/src/views/SkiaView.tsx
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import React from "react";
|
2
|
-
import { requireNativeComponent } from "react-native";
|
3
2
|
|
4
3
|
import type { SkRect } from "../skia/types";
|
5
4
|
import type { SkiaValue } from "../values";
|
5
|
+
import { Platform } from "../Platform";
|
6
6
|
|
7
7
|
import { SkiaViewApi } from "./api";
|
8
8
|
import type { NativeSkiaViewProps, SkiaDrawViewProps } from "./types";
|
@@ -10,7 +10,7 @@ import type { NativeSkiaViewProps, SkiaDrawViewProps } from "./types";
|
|
10
10
|
export const SkiaViewNativeId = { current: 1000 };
|
11
11
|
|
12
12
|
const NativeSkiaView =
|
13
|
-
requireNativeComponent<NativeSkiaViewProps>("SkiaDrawView");
|
13
|
+
Platform.requireNativeComponent<NativeSkiaViewProps>("SkiaDrawView");
|
14
14
|
|
15
15
|
export class SkiaView extends React.Component<SkiaDrawViewProps> {
|
16
16
|
constructor(props: SkiaDrawViewProps) {
|