@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
@@ -0,0 +1 @@
|
|
1
|
+
export * from "./Platform";
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./Platform\";\n"],"mappings":"AAAA,cAAc,YAAd"}
|
@@ -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
|
|
7
7
|
if (SkiaModule == null || typeof SkiaModule.install !== "function") {
|
8
8
|
throw new Error("Native RNSkia Module cannot be found! Make sure you correctly " + "installed native dependencies and rebuilt your app.");
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["
|
1
|
+
{"version":3,"names":["Platform","OS","global","SkiaApi","SkiaModule","NativeModules","RNSkia","install","Error","result"],"sources":["NativeSetup.ts"],"sourcesContent":["import { Platform } from \"../Platform\";\n\nif (Platform.OS !== \"web\" && global.SkiaApi == null) {\n // Initialize RN Skia\n const SkiaModule = Platform.NativeModules.RNSkia;\n if (SkiaModule == null || typeof SkiaModule.install !== \"function\") {\n throw new Error(\n \"Native RNSkia Module cannot be found! Make sure you correctly \" +\n \"installed native dependencies and rebuilt your app.\"\n );\n }\n const result = SkiaModule.install();\n if (result !== true) {\n throw new Error(\n `Native Skia Module failed to correctly install JSI Bindings! Result: ${result}`\n );\n }\n}\n"],"mappings":"AAAA,SAASA,QAAT,QAAyB,aAAzB;;AAEA,IAAIA,QAAQ,CAACC,EAAT,KAAgB,KAAhB,IAAyBC,MAAM,CAACC,OAAP,IAAkB,IAA/C,EAAqD;EACnD;EACA,MAAMC,UAAU,GAAGJ,QAAQ,CAACK,aAAT,CAAuBC,MAA1C;;EACA,IAAIF,UAAU,IAAI,IAAd,IAAsB,OAAOA,UAAU,CAACG,OAAlB,KAA8B,UAAxD,EAAoE;IAClE,MAAM,IAAIC,KAAJ,CACJ,mEACE,qDAFE,CAAN;EAID;;EACD,MAAMC,MAAM,GAAGL,UAAU,CAACG,OAAX,EAAf;;EACA,IAAIE,MAAM,KAAK,IAAf,EAAqB;IACnB,MAAM,IAAID,KAAJ,CACH,wEAAuEC,MAAO,EAD3E,CAAN;EAGD;AACF"}
|
@@ -1,11 +1,6 @@
|
|
1
1
|
import { useEffect, useRef, useState } from "react";
|
2
|
-
import { Image } from "react-native";
|
3
2
|
import { Skia } from "../Skia";
|
4
|
-
import {
|
5
|
-
|
6
|
-
const resolveAsset = source => {
|
7
|
-
return isRNModule(source) ? Image.resolveAssetSource(source).uri : source.default;
|
8
|
-
};
|
3
|
+
import { Platform } from "../../Platform";
|
9
4
|
|
10
5
|
const factoryWrapper = (data2, factory, onError) => {
|
11
6
|
const factoryResult = factory(data2);
|
@@ -24,7 +19,7 @@ const loadData = (source, factory, onError) => {
|
|
24
19
|
} else if (source instanceof Uint8Array) {
|
25
20
|
return new Promise(resolve => resolve(factoryWrapper(Skia.Data.fromBytes(source), factory, onError)));
|
26
21
|
} else {
|
27
|
-
const uri = typeof source === "string" ? source : resolveAsset(source);
|
22
|
+
const uri = typeof source === "string" ? source : Platform.resolveAsset(source);
|
28
23
|
return Skia.Data.fromURI(uri).then(d => factoryWrapper(d, factory, onError));
|
29
24
|
}
|
30
25
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["useEffect","useRef","useState","
|
1
|
+
{"version":3,"names":["useEffect","useRef","useState","Skia","Platform","factoryWrapper","data2","factory","onError","factoryResult","Error","loadData","source","undefined","Promise","resolve","Uint8Array","Data","fromBytes","uri","resolveAsset","fromURI","then","d","useLoading","loader","mounted","data","setData","dataRef","current","value","dispose","useRawData","identity","useData"],"sources":["Data.ts"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\n\nimport { Skia } from \"../Skia\";\nimport type { SkData, DataSourceParam, JsiDisposable } from \"../types\";\nimport { Platform } from \"../../Platform\";\n\nconst factoryWrapper = <T>(\n data2: SkData,\n factory: (data: SkData) => T,\n onError?: (err: Error) => void\n) => {\n const factoryResult = factory(data2);\n if (factoryResult === null) {\n onError && onError(new Error(\"Could not load data\"));\n return null;\n } else {\n return factoryResult;\n }\n};\n\nconst loadData = <T>(\n source: DataSourceParam,\n factory: (data: SkData) => T | null,\n onError?: (err: Error) => void\n): Promise<T | null> => {\n if (source === null || source === undefined) {\n return new Promise((resolve) => resolve(null));\n } else if (source instanceof Uint8Array) {\n return new Promise((resolve) =>\n resolve(factoryWrapper(Skia.Data.fromBytes(source), factory, onError))\n );\n } else {\n const uri =\n typeof source === \"string\" ? source : Platform.resolveAsset(source);\n return Skia.Data.fromURI(uri).then((d) =>\n factoryWrapper(d, factory, onError)\n );\n }\n};\nconst useLoading = <T extends JsiDisposable>(\n source: DataSourceParam,\n loader: () => Promise<T | null>\n) => {\n const mounted = useRef(false);\n const [data, setData] = useState<T | null>(null);\n const dataRef = useRef<T | null>(null);\n useEffect(() => {\n mounted.current = true;\n loader().then((value) => {\n if (mounted.current) {\n setData(value);\n dataRef.current = value;\n }\n });\n return () => {\n dataRef.current?.dispose();\n mounted.current = false;\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [source]);\n return data;\n};\n\nexport const useRawData = <T extends JsiDisposable>(\n source: DataSourceParam,\n factory: (data: SkData) => T | null,\n onError?: (err: Error) => void\n) => useLoading(source, () => loadData<T>(source, factory, onError));\n\nconst identity = (data: SkData) => data;\n\nexport const useData = (\n source: DataSourceParam,\n onError?: (err: Error) => void\n) => useRawData(source, identity, onError);\n"],"mappings":"AAAA,SAASA,SAAT,EAAoBC,MAApB,EAA4BC,QAA5B,QAA4C,OAA5C;AAEA,SAASC,IAAT,QAAqB,SAArB;AAEA,SAASC,QAAT,QAAyB,gBAAzB;;AAEA,MAAMC,cAAc,GAAG,CACrBC,KADqB,EAErBC,OAFqB,EAGrBC,OAHqB,KAIlB;EACH,MAAMC,aAAa,GAAGF,OAAO,CAACD,KAAD,CAA7B;;EACA,IAAIG,aAAa,KAAK,IAAtB,EAA4B;IAC1BD,OAAO,IAAIA,OAAO,CAAC,IAAIE,KAAJ,CAAU,qBAAV,CAAD,CAAlB;IACA,OAAO,IAAP;EACD,CAHD,MAGO;IACL,OAAOD,aAAP;EACD;AACF,CAZD;;AAcA,MAAME,QAAQ,GAAG,CACfC,MADe,EAEfL,OAFe,EAGfC,OAHe,KAIO;EACtB,IAAII,MAAM,KAAK,IAAX,IAAmBA,MAAM,KAAKC,SAAlC,EAA6C;IAC3C,OAAO,IAAIC,OAAJ,CAAaC,OAAD,IAAaA,OAAO,CAAC,IAAD,CA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wBA,OAAO,MAAMM,UAAU,GAAG,CACxBrB,MADwB,EAExBL,OAFwB,EAGxBC,OAHwB,KAIrBgB,UAAU,CAACZ,MAAD,EAAS,MAAMD,QAAQ,CAAIC,MAAJ,EAAYL,OAAZ,EAAqBC,OAArB,CAAvB,CAJR;;AAMP,MAAM0B,QAAQ,GAAIP,IAAD,IAAkBA,IAAnC;;AAEA,OAAO,MAAMQ,OAAO,GAAG,CACrBvB,MADqB,EAErBJ,OAFqB,KAGlByB,UAAU,CAACrB,MAAD,EAASsB,QAAT,EAAmB1B,OAAnB,CAHR"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { Platform } from "../../Platform";
|
2
2
|
import { Skia } from "../Skia";
|
3
3
|
import { useRawData } from "./Data";
|
4
4
|
const imgFactory = Skia.Image.MakeImageFromEncoded.bind(Skia.Image);
|
@@ -30,7 +30,7 @@ export const makeImageFromView = function (viewRef) {
|
|
30
30
|
}
|
31
31
|
}
|
32
32
|
|
33
|
-
const viewTag = findNodeHandle(viewRef.current);
|
33
|
+
const viewTag = Platform.findNodeHandle(viewRef.current);
|
34
34
|
|
35
35
|
if (viewTag !== null && viewTag !== 0) {
|
36
36
|
return Skia.Image.MakeImageFromViewTag(viewTag);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["
|
1
|
+
{"version":3,"names":["Platform","Skia","useRawData","imgFactory","Image","MakeImageFromEncoded","bind","useImage","source","onError","makeImageFromView","viewRef","callback","OS","Promise","reject","Error","viewTag","findNodeHandle","current","MakeImageFromViewTag"],"sources":["Image.ts"],"sourcesContent":["import { Platform } from \"../../Platform\";\nimport { Skia } from \"../Skia\";\nimport type { DataSourceParam, SkImage } from \"../types\";\n\nimport { useRawData } from \"./Data\";\n\nconst imgFactory = Skia.Image.MakeImageFromEncoded.bind(Skia.Image);\n\n/**\n * Returns a Skia Image object\n * */\nexport const useImage = (\n source: DataSourceParam,\n onError?: (err: Error) => void\n) => useRawData(source, imgFactory, onError);\n\n/**\n * Creates an image from a given view reference. NOTE: This method has different implementations\n * on web/native. On web, the callback is called with the view ref and the callback is expected to\n * return a promise that resolves to a Skia Image object. On native, the view ref is used to\n * find the view tag and the Skia Image object is created from the view tag. This means that on web\n * you will need to implement the logic to create the image from the view ref yourself.\n * @param viewRef Ref to the view we're creating an image from\n * @returns A promise that resolves to a Skia Image object or rejects\n * with an error id the view tag is invalid.\n */\nexport const makeImageFromView = <\n T extends\n | number\n | React.Component<unknown, unknown>\n | React.ComponentClass<unknown>\n>(\n viewRef: React.RefObject<T>,\n callback:\n | null\n | ((viewRef: React.RefObject<T>) => Promise<SkImage | null>) = null\n) => {\n // In web implementation we just delegate the work to the provided callback\n if (Platform.OS === \"web\") {\n if (callback) {\n return callback(viewRef);\n } else {\n Promise.reject(\n new Error(\n \"Callback is required on web in the makeImageFromView function.\"\n )\n );\n }\n }\n const viewTag = Platform.findNodeHandle(viewRef.current);\n if (viewTag !== null && viewTag !== 0) {\n return Skia.Image.MakeImageFromViewTag(viewTag);\n }\n return Promise.reject(new Error(\"Invalid view tag\"));\n};\n"],"mappings":"AAAA,SAASA,QAAT,QAAyB,gBAAzB;AACA,SAASC,IAAT,QAAqB,SAArB;AAGA,SAASC,UAAT,QAA2B,QAA3B;AAEA,MAAMC,UAAU,GAAGF,IAAI,CAACG,KAAL,CAAWC,oBAAX,CAAgCC,IAAhC,CAAqCL,IAAI,CAACG,KAA1C,CAAnB;AAEA;AACA;AACA;;AACA,OAAO,MAAMG,QAAQ,GAAG,CACtBC,MADsB,EAEtBC,OAFsB,KAGnBP,UAAU,CAACM,MAAD,EAASL,UAAT,EAAqBM,OAArB,CAHR;AAKP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,iBAAiB,GAAG,UAM/BC,OAN+B,EAU5B;EAAA,IAHHC,QAGG,uEAD8D,IAC9D;;EACH;EACA,IAAIZ,QAAQ,CAACa,EAAT,KAAgB,KAApB,EAA2B;IACzB,IAAID,QAAJ,EAAc;MACZ,OAAOA,QAAQ,CAACD,OAAD,CAAf;IACD,CAFD,MAEO;MACLG,OAAO,CAACC,MAAR,CACE,IAAIC,KAAJ,CACE,gEADF,CADF;IAKD;EACF;;EACD,MAAMC,OAAO,GAAGjB,QAAQ,CAACkB,cAAT,CAAwBP,OAAO,CAACQ,OAAhC,CAAhB;;EACA,IAAIF,OAAO,KAAK,IAAZ,IAAoBA,OAAO,KAAK,CAApC,EAAuC;IACrC,OAAOhB,IAAI,CAACG,KAAL,CAAWgB,oBAAX,CAAgCH,OAAhC,CAAP;EACD;;EACD,OAAOH,OAAO,CAACC,MAAR,CAAe,IAAIC,KAAJ,CAAU,kBAAV,CAAf,CAAP;AACD,CA5BM"}
|
@@ -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";
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["MatrixIndex","isMatrix","obj","__typename__","processTransform","m","transforms","transform","key","Object","keys","value","translate","scale","skew","rotate","toDegrees","exhaustiveCheck","a","Error","rad","Math","PI"],"sources":["Matrix.ts"],"sourcesContent":["import type { SkJSIInstance } from \"./JsiInstance\";\nimport type { SkCanvas } from \"./Canvas\";\nexport enum MatrixIndex {\n ScaleX = 0,\n SkewX = 1,\n TransX = 2,\n SkewY = 3,\n ScaleY = 4,\n TransY = 5,\n Persp0 = 6,\n Persp1 = 7,\n Persp2 = 8,\n}\n\nexport const isMatrix = (obj: unknown): obj is SkMatrix =>\n obj !== null && (obj as SkJSIInstance<string>).__typename__ === \"Matrix\";\n\nexport interface SkMatrix extends SkJSIInstance<\"Matrix\"> {\n concat: (matrix: SkMatrix) =>
|
1
|
+
{"version":3,"names":["MatrixIndex","isMatrix","obj","__typename__","processTransform","m","transforms","transform","key","Object","keys","value","translate","scale","skew","rotate","toDegrees","exhaustiveCheck","a","Error","rad","Math","PI"],"sources":["Matrix.ts"],"sourcesContent":["import type { SkJSIInstance } from \"./JsiInstance\";\nimport type { SkCanvas } from \"./Canvas\";\nexport enum MatrixIndex {\n ScaleX = 0,\n SkewX = 1,\n TransX = 2,\n SkewY = 3,\n ScaleY = 4,\n TransY = 5,\n Persp0 = 6,\n Persp1 = 7,\n Persp2 = 8,\n}\n\nexport const isMatrix = (obj: unknown): obj is SkMatrix =>\n obj !== null && (obj as SkJSIInstance<string>).__typename__ === \"Matrix\";\n\nexport interface SkMatrix extends SkJSIInstance<\"Matrix\"> {\n concat: (matrix: SkMatrix) => SkMatrix;\n translate: (x: number, y: number) => SkMatrix;\n scale: (x: number, y?: number) => SkMatrix;\n skew: (x: number, y: number) => SkMatrix;\n rotate: (theta: number) => SkMatrix;\n identity: () => SkMatrix;\n get: () => number[];\n}\n\ntype Transform2dName =\n | \"translateX\"\n | \"translateY\"\n | \"scale\"\n | \"skewX\"\n | \"skewY\"\n | \"scaleX\"\n | \"scaleY\"\n | \"rotateZ\"\n | \"rotate\";\n\ntype Transformations = {\n readonly [Name in Transform2dName]: number;\n};\n\nexport type Transforms2d = readonly (\n | Pick<Transformations, \"translateX\">\n | Pick<Transformations, \"translateY\">\n | Pick<Transformations, \"scale\">\n | Pick<Transformations, \"scaleX\">\n | Pick<Transformations, \"scaleY\">\n | Pick<Transformations, \"skewX\">\n | Pick<Transformations, \"skewY\">\n | Pick<Transformations, \"rotate\">\n)[];\n\nexport interface TransformProp {\n transform?: Transforms2d;\n}\n\nexport const processTransform = <T extends SkMatrix | SkCanvas>(\n m: T,\n transforms: Transforms2d\n) => {\n for (const transform of transforms) {\n const key = Object.keys(transform)[0] as Transform2dName;\n const value = (transform as Pick<Transformations, typeof key>)[key];\n if (key === \"translateX\") {\n m.translate(value, 0);\n continue;\n }\n if (key === \"translateY\") {\n m.translate(0, value);\n continue;\n }\n if (key === \"scale\") {\n m.scale(value, value);\n continue;\n }\n if (key === \"scaleX\") {\n m.scale(value, 1);\n continue;\n }\n if (key === \"scaleY\") {\n m.scale(1, value);\n continue;\n }\n if (key === \"skewX\") {\n m.skew(value, 0);\n continue;\n }\n if (key === \"skewY\") {\n m.skew(0, value);\n continue;\n }\n if (key === \"rotate\" || key === \"rotateZ\") {\n if (isMatrix(m)) {\n m.rotate(value);\n } else {\n m.rotate(toDegrees(value), 0, 0);\n }\n continue;\n }\n exhaustiveCheck(key);\n }\n return m;\n};\n\nconst exhaustiveCheck = (a: never): never => {\n throw new Error(`Unknown transformation: ${a}`);\n};\n\nexport const toDegrees = (rad: number) => {\n return (rad * 180) / Math.PI;\n};\n"],"mappings":"AAEA,WAAYA,WAAZ;;WAAYA,W;EAAAA,W,CAAAA,W;EAAAA,W,CAAAA,W;EAAAA,W,CAAAA,W;EAAAA,W,CAAAA,W;EAAAA,W,CAAAA,W;EAAAA,W,CAAAA,W;EAAAA,W,CAAAA,W;EAAAA,W,CAAAA,W;EAAAA,W,CAAAA,W;GAAAA,W,KAAAA,W;;AAYZ,OAAO,MAAMC,QAAQ,GAAIC,GAAD,IACtBA,GAAG,KAAK,IAAR,IAAiBA,GAAD,CAA+BC,YAA/B,KAAgD,QAD3D;AA2CP,OAAO,MAAMC,g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D,CAAf;EACD;;EACD,OAAOH,CAAP;AACD,CA9CM;;AAgDP,MAAMY,eAAe,GAAIC,CAAD,IAAqB;EAC3C,MAAM,IAAIC,KAAJ,CAAW,2BAA0BD,CAAE,EAAvC,CAAN;AACD,CAFD;;AAIA,OAAO,MAAMF,SAAS,GAAII,GAAD,IAAiB;EACxC,OAAQA,GAAG,GAAG,GAAP,GAAcC,IAAI,CAACC,EAA1B;AACD,CAFM"}
|
@@ -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
|
}
|
@@ -6,26 +6,32 @@ export class JsiSkMatrix extends HostObject {
|
|
6
6
|
|
7
7
|
concat(matrix) {
|
8
8
|
this.ref.set(this.CanvasKit.Matrix.multiply(this.ref, JsiSkMatrix.fromValue(matrix)));
|
9
|
+
return this;
|
9
10
|
}
|
10
11
|
|
11
12
|
translate(x, y) {
|
12
13
|
this.concat(new JsiSkMatrix(this.CanvasKit, Float32Array.of(...this.CanvasKit.Matrix.translated(x, y))));
|
14
|
+
return this;
|
13
15
|
}
|
14
16
|
|
15
17
|
scale(x, y) {
|
16
18
|
this.concat(new JsiSkMatrix(this.CanvasKit, Float32Array.of(...this.CanvasKit.Matrix.scaled(x, y !== null && y !== void 0 ? y : x))));
|
19
|
+
return this;
|
17
20
|
}
|
18
21
|
|
19
22
|
skew(x, y) {
|
20
23
|
this.concat(new JsiSkMatrix(this.CanvasKit, Float32Array.of(...this.CanvasKit.Matrix.skewed(x, y))));
|
24
|
+
return this;
|
21
25
|
}
|
22
26
|
|
23
27
|
rotate(value) {
|
24
28
|
this.concat(new JsiSkMatrix(this.CanvasKit, Float32Array.of(...this.CanvasKit.Matrix.rotated(value))));
|
29
|
+
return this;
|
25
30
|
}
|
26
31
|
|
27
32
|
identity() {
|
28
33
|
this.ref.set(this.CanvasKit.Matrix.identity());
|
34
|
+
return this;
|
29
35
|
}
|
30
36
|
|
31
37
|
get() {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["HostObject","JsiSkMatrix","constructor","CanvasKit","ref","concat","matrix","set","Matrix","multiply","fromValue","translate","x","y","Float32Array","of","translated","scale","scaled","skew","skewed","rotate","value","rotated","identity","get","Array","from"],"sources":["JsiSkMatrix.ts"],"sourcesContent":["import type { CanvasKit, Matrix3x3 } from \"canvaskit-wasm\";\n\nimport type { SkMatrix } from \"../types\";\n\nimport { HostObject } from \"./Host\";\n\nexport class JsiSkMatrix\n extends HostObject<Matrix3x3, \"Matrix\">\n implements SkMatrix\n{\n constructor(CanvasKit: CanvasKit, ref: Matrix3x3) {\n super(CanvasKit, ref, \"Matrix\");\n }\n\n concat(matrix: SkMatrix) {\n this.ref.set(\n this.CanvasKit.Matrix.multiply(this.ref, JsiSkMatrix.fromValue(matrix))\n );\n }\n\n translate(x: number, y: number) {\n this.concat(\n new JsiSkMatrix(\n this.CanvasKit,\n Float32Array.of(...this.CanvasKit.Matrix.translated(x, y))\n )\n );\n }\n\n scale(x: number, y?: number) {\n this.concat(\n new JsiSkMatrix(\n this.CanvasKit,\n Float32Array.of(...this.CanvasKit.Matrix.scaled(x, y ?? x))\n )\n );\n }\n\n skew(x: number, y: number) {\n this.concat(\n new JsiSkMatrix(\n this.CanvasKit,\n Float32Array.of(...this.CanvasKit.Matrix.skewed(x, y))\n )\n );\n }\n\n rotate(value: number) {\n this.concat(\n new JsiSkMatrix(\n this.CanvasKit,\n Float32Array.of(...this.CanvasKit.Matrix.rotated(value))\n )\n );\n }\n\n identity() {\n this.ref.set(this.CanvasKit.Matrix.identity());\n }\n\n get() {\n return Array.from(this.ref);\n }\n}\n"],"mappings":"AAIA,SAASA,UAAT,QAA2B,QAA3B;AAEA,OAAO,MAAMC,WAAN,SACGD,UADH,CAGP;EACEE,WAAW,CAACC,SAAD,EAAuBC,GAAvB,EAAuC;IAChD,MAAMD,SAAN,EAAiBC,GAAjB,EAAsB,QAAtB;EACD;;EAEDC,MAAM,CAACC,MAAD,EAAmB;IACvB,KAAKF,GAAL,CAASG,GAAT,CACE,KAAKJ,SAAL,CAAeK,MAAf,CAAsBC,QAAtB,CAA+B,KAAKL,GAApC,EAAyCH,WAAW,CAACS,SAAZ,CAAsBJ,MAAtB,CAAzC,CADF;
|
1
|
+
{"version":3,"names":["HostObject","JsiSkMatrix","constructor","CanvasKit","ref","concat","matrix","set","Matrix","multiply","fromValue","translate","x","y","Float32Array","of","translated","scale","scaled","skew","skewed","rotate","value","rotated","identity","get","Array","from"],"sources":["JsiSkMatrix.ts"],"sourcesContent":["import type { CanvasKit, Matrix3x3 } from \"canvaskit-wasm\";\n\nimport type { SkMatrix } from \"../types\";\n\nimport { HostObject } from \"./Host\";\n\nexport class JsiSkMatrix\n extends HostObject<Matrix3x3, \"Matrix\">\n implements SkMatrix\n{\n constructor(CanvasKit: CanvasKit, ref: Matrix3x3) {\n super(CanvasKit, ref, \"Matrix\");\n }\n\n concat(matrix: SkMatrix) {\n this.ref.set(\n this.CanvasKit.Matrix.multiply(this.ref, JsiSkMatrix.fromValue(matrix))\n );\n return this;\n }\n\n translate(x: number, y: number) {\n this.concat(\n new JsiSkMatrix(\n this.CanvasKit,\n Float32Array.of(...this.CanvasKit.Matrix.translated(x, y))\n )\n );\n return this;\n }\n\n scale(x: number, y?: number) {\n this.concat(\n new JsiSkMatrix(\n this.CanvasKit,\n Float32Array.of(...this.CanvasKit.Matrix.scaled(x, y ?? x))\n )\n );\n return this;\n }\n\n skew(x: number, y: number) {\n this.concat(\n new JsiSkMatrix(\n this.CanvasKit,\n Float32Array.of(...this.CanvasKit.Matrix.skewed(x, y))\n )\n );\n return this;\n }\n\n rotate(value: number) {\n this.concat(\n new JsiSkMatrix(\n this.CanvasKit,\n Float32Array.of(...this.CanvasKit.Matrix.rotated(value))\n )\n );\n return this;\n }\n\n identity() {\n this.ref.set(this.CanvasKit.Matrix.identity());\n return this;\n }\n\n get() {\n return Array.from(this.ref);\n }\n}\n"],"mappings":"AAIA,SAASA,UAAT,QAA2B,QAA3B;AAEA,OAAO,MAAMC,WAAN,SACGD,UADH,CAGP;EACEE,WAAW,CAACC,SAAD,EAAuBC,GAAvB,EAAuC;IAChD,MAAMD,SAAN,EAAiBC,GAAjB,EAAsB,QAAtB;EACD;;EAEDC,MAAM,CAACC,MAAD,EAAmB;IACvB,KAAKF,GAAL,CAASG,GAAT,CACE,KAAKJ,SAAL,CAAeK,MAAf,CAAsBC,QAAtB,CAA+B,KAAKL,GAApC,EAAyCH,WAAW,CAACS,SAAZ,CAAsBJ,MAAtB,CAAzC,CADF;IAGA,OAAO,IAAP;EACD;;EAEDK,SAAS,CAACC,CAAD,EAAYC,CAAZ,EAAuB;IAC9B,KAAKR,MAAL,CACE,IAAIJ,WAAJ,CACE,KAAKE,SADP,EAEEW,YAAY,CAACC,EAAb,CAAgB,GAAG,KAAKZ,SAAL,CAAeK,MAAf,CAAsBQ,UAAtB,CAAiCJ,CAAjC,EAAoCC,CAApC,CAAnB,CAFF,CADF;IAMA,OAAO,IAAP;EACD;;EAEDI,KAAK,CAACL,CAAD,EAAYC,CAAZ,EAAwB;IAC3B,KAAKR,MAAL,CACE,IAAIJ,WAAJ,CACE,KAAKE,SADP,EAEEW,YAAY,CAACC,EAAb,CAAgB,GAAG,KAAKZ,SAAL,CAAeK,MAAf,CAAsBU,MAAtB,CAA6BN,CAA7B,EAAgCC,CAAhC,aAAgCA,CAAhC,cAAgCA,CAAhC,GAAqCD,CAArC,CAAnB,CAFF,CADF;IAMA,OAAO,IAAP;EACD;;EAEDO,IAAI,CAACP,CAAD,EAAYC,CAAZ,EAAuB;IACzB,KAAKR,MAAL,CACE,IAAIJ,WAAJ,CACE,KAAKE,SADP,EAEEW,YAAY,CAACC,EAAb,CAAgB,GAAG,KAAKZ,SAAL,CAAeK,MAAf,CAAsBY,MAAtB,CAA6BR,CAA7B,EAAgCC,CAAhC,CAAnB,CAFF,CADF;IAMA,OAAO,IAAP;EACD;;EAEDQ,MAAM,CAACC,KAAD,EAAgB;IACpB,KAAKjB,MAAL,CACE,IAAIJ,WAAJ,CACE,KAAKE,SADP,EAEEW,YAAY,CAACC,EAAb,CAAgB,GAAG,KAAKZ,SAAL,CAAeK,MAAf,CAAsBe,OAAtB,CAA8BD,KAA9B,CAAnB,CAFF,CADF;IAMA,OAAO,IAAP;EACD;;EAEDE,QAAQ,GAAG;IACT,KAAKpB,GAAL,CAASG,GAAT,CAAa,KAAKJ,SAAL,CAAeK,MAAf,CAAsBgB,QAAtB,EAAb;IACA,OAAO,IAAP;EACD;;EAEDC,GAAG,GAAG;IACJ,OAAOC,KAAK,CAACC,IAAN,CAAW,KAAKvB,GAAhB,CAAP;EACD;;AA3DH"}
|
@@ -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
|
}
|
@@ -4,10 +4,10 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
4
4
|
|
5
5
|
/* global HTMLCanvasElement */
|
6
6
|
import React from "react";
|
7
|
-
import { PixelRatio, View } from "react-native";
|
8
7
|
import { JsiSkSurface } from "../skia/web/JsiSkSurface";
|
8
|
+
import { Platform } from "../Platform";
|
9
9
|
import { TouchType } from "./types";
|
10
|
-
const pd = PixelRatio
|
10
|
+
const pd = Platform.PixelRatio;
|
11
11
|
export class SkiaBaseWebView extends React.Component {
|
12
12
|
constructor(props) {
|
13
13
|
var _props$mode;
|
@@ -34,6 +34,16 @@ export class SkiaBaseWebView extends React.Component {
|
|
34
34
|
|
35
35
|
_defineProperty(this, "height", 0);
|
36
36
|
|
37
|
+
_defineProperty(this, "onStart", this.createTouchHandler(TouchType.Start));
|
38
|
+
|
39
|
+
_defineProperty(this, "onActive", this.createTouchHandler(TouchType.Active));
|
40
|
+
|
41
|
+
_defineProperty(this, "onCancel", this.createTouchHandler(TouchType.Cancelled));
|
42
|
+
|
43
|
+
_defineProperty(this, "onEnd", this.createTouchHandler(TouchType.End));
|
44
|
+
|
45
|
+
_defineProperty(this, "onLayout", this.onLayoutEvent.bind(this));
|
46
|
+
|
37
47
|
this._mode = (_props$mode = props.mode) !== null && _props$mode !== void 0 ? _props$mode : "default";
|
38
48
|
}
|
39
49
|
|
@@ -43,22 +53,19 @@ export class SkiaBaseWebView extends React.Component {
|
|
43
53
|
this._unsubscriptions = [];
|
44
54
|
}
|
45
55
|
|
46
|
-
|
56
|
+
onLayoutEvent(evt) {
|
47
57
|
const {
|
48
58
|
CanvasKit
|
49
|
-
} = global;
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
const
|
59
|
-
canvas.width = width * pd;
|
60
|
-
canvas.height = height * pd;
|
61
|
-
const surface = CanvasKit.MakeWebGLCanvasSurface(this._canvasRef.current);
|
59
|
+
} = global; // Reset canvas / surface on layout change
|
60
|
+
|
61
|
+
const canvas = this._canvasRef.current;
|
62
|
+
|
63
|
+
if (canvas) {
|
64
|
+
this.width = canvas.clientWidth;
|
65
|
+
this.height = canvas.clientHeight;
|
66
|
+
canvas.width = this.width * pd;
|
67
|
+
canvas.height = this.height * pd;
|
68
|
+
const surface = CanvasKit.MakeWebGLCanvasSurface(canvas);
|
62
69
|
|
63
70
|
if (!surface) {
|
64
71
|
throw new Error("Could not create surface");
|
@@ -204,20 +211,20 @@ export class SkiaBaseWebView extends React.Component {
|
|
204
211
|
debug = false,
|
205
212
|
...viewProps
|
206
213
|
} = this.props;
|
207
|
-
return /*#__PURE__*/React.createElement(View, _extends({}, viewProps, {
|
208
|
-
onLayout: this.onLayout
|
214
|
+
return /*#__PURE__*/React.createElement(Platform.View, _extends({}, viewProps, {
|
215
|
+
onLayout: this.onLayout
|
209
216
|
}), /*#__PURE__*/React.createElement("canvas", {
|
210
217
|
ref: this._canvasRef,
|
211
218
|
style: {
|
212
219
|
display: "flex",
|
213
220
|
flex: 1
|
214
221
|
},
|
215
|
-
onPointerDown: this.
|
216
|
-
onPointerMove: this.
|
217
|
-
onPointerUp: this.
|
218
|
-
onPointerCancel: this.
|
219
|
-
onPointerLeave: this.
|
220
|
-
onPointerOut: this.
|
222
|
+
onPointerDown: this.onStart,
|
223
|
+
onPointerMove: this.onActive,
|
224
|
+
onPointerUp: this.onEnd,
|
225
|
+
onPointerCancel: this.onCancel,
|
226
|
+
onPointerLeave: this.onEnd,
|
227
|
+
onPointerOut: this.onEnd
|
221
228
|
}));
|
222
229
|
}
|
223
230
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["React","PixelRatio","View","JsiSkSurface","TouchType","pd","get","SkiaBaseWebView","Component","constructor","props","createRef","_mode","mode","unsubscribeAll","_unsubscriptions","forEach","u","onLayout","evt","CanvasKit","global","width","height","nativeEvent","layout","_canvasRef","current","canvas","surface","MakeWebGLCanvasSurface","Error","_surface","_canvas","getCanvas","redraw","getSize","componentDidMount","tick","componentDidUpdate","componentWillUnmount","cancelAnimationFrame","requestId","getContext","getExtension","loseContext","makeImageSnapshot","rect","clear","TRANSPARENT","renderInCanvas","ref","flush","_redrawRequests","touches","_touches","Float32Array","of","save","scale","restore","requestAnimationFrame","bind","setDrawMode","registerValues","_values","v","push","addListener","handleTouchEvent","touchType","id","pointerId","x","clientX","currentTarget","getClientRects","left","y","clientY","top","force","pressure","type","timestamp","Date","now","createTouchHandler","render","debug","viewProps","display","flex","Start","Active","End","Cancelled"],"sources":["SkiaBaseWebView.tsx"],"sourcesContent":["/* global HTMLCanvasElement */\nimport React from \"react\";\nimport type { PointerEvent } from \"react\";\nimport type { LayoutChangeEvent } from \"react-native\";\nimport { PixelRatio, View } from \"react-native\";\n\nimport type { SkRect, SkCanvas } from \"../skia/types\";\nimport type { SkiaValue } from \"../values\";\nimport { JsiSkSurface } from \"../skia/web/JsiSkSurface\";\n\nimport type { DrawMode, SkiaBaseViewProps, TouchInfo } from \"./types\";\nimport { TouchType } from \"./types\";\n\nconst pd = PixelRatio.get();\n\nexport abstract class SkiaBaseWebView<\n TProps extends SkiaBaseViewProps\n> extends React.Component<TProps> {\n constructor(props: TProps) {\n super(props);\n this._mode = props.mode ?? \"default\";\n }\n\n private _surface: JsiSkSurface | null = null;\n private _unsubscriptions: Array<() => void> = [];\n private _touches: Array<TouchInfo> = [];\n private _canvas: SkCanvas | null = null;\n private _canvasRef = React.createRef<HTMLCanvasElement>();\n private _mode: DrawMode;\n private _redrawRequests = 0;\n private requestId = 0;\n\n protected width = 0;\n protected height = 0;\n\n private unsubscribeAll() {\n this._unsubscriptions.forEach((u) => u());\n this._unsubscriptions = [];\n }\n\n private onLayout(evt: LayoutChangeEvent) {\n const { CanvasKit } = global;\n const { width, height } = evt.nativeEvent.layout;\n this.width = width;\n this.height = height;\n // Reset canvas / surface on layout change\n if (this._canvasRef.current) {\n const canvas = this._canvasRef.current;\n canvas.width = width * pd;\n canvas.height = height * pd;\n const surface = CanvasKit.MakeWebGLCanvasSurface(this._canvasRef.current);\n if (!surface) {\n throw new Error(\"Could not create surface\");\n }\n this._surface = new JsiSkSurface(CanvasKit, surface);\n this._canvas = this._surface.getCanvas();\n this.redraw();\n }\n // Call onLayout callback if it exists\n if (this.props.onLayout) {\n this.props.onLayout(evt);\n }\n }\n\n protected getSize() {\n return { width: this.width, height: this.height };\n }\n\n componentDidMount() {\n // Start render loop\n this.tick();\n }\n\n componentDidUpdate() {\n this.redraw();\n }\n\n componentWillUnmount() {\n this.unsubscribeAll();\n cancelAnimationFrame(this.requestId);\n // https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_lose_context\n this._canvasRef.current\n ?.getContext(\"webgl2\")\n ?.getExtension(\"WEBGL_lose_context\")\n ?.loseContext();\n }\n\n /**\n * Creates a snapshot from the canvas in the surface\n * @param rect Rect to use as bounds. Optional.\n * @returns An Image object.\n */\n public makeImageSnapshot(rect?: SkRect) {\n this._canvas!.clear(CanvasKit.TRANSPARENT);\n this.renderInCanvas(this._canvas!, []);\n this._surface?.ref.flush();\n return this._surface?.makeImageSnapshot(rect);\n }\n\n /**\n * Override to render\n */\n protected abstract renderInCanvas(\n canvas: SkCanvas,\n touches: TouchInfo[]\n ): void;\n\n /**\n * Sends a redraw request to the native SkiaView.\n */\n private tick() {\n if (this._mode === \"continuous\" || this._redrawRequests > 0) {\n this._redrawRequests = 0;\n if (this._canvas) {\n const touches = [...this._touches];\n this._touches = [];\n const canvas = this._canvas!;\n canvas.clear(Float32Array.of(0, 0, 0, 0));\n canvas.save();\n canvas.scale(pd, pd);\n this.renderInCanvas(canvas, touches);\n canvas.restore();\n this._surface?.ref.flush();\n }\n }\n this.requestId = requestAnimationFrame(this.tick.bind(this));\n }\n\n public redraw() {\n this._redrawRequests++;\n }\n\n /**\n * Updates the drawing mode for the skia view. This is the same\n * as declaratively setting the mode property on the SkiaView.\n * There are two drawing modes, \"continuous\" and \"default\",\n * where the continuous mode will continuously redraw the view and\n * the default mode will only redraw when any of the regular react\n * properties are changed like size and margins.\n * @param mode Drawing mode to use.\n */\n public setDrawMode(mode: DrawMode) {\n this._mode = mode;\n this.tick();\n }\n\n /**\n * Registers one or move values as a dependant value of the Skia View. The view will\n * The view will redraw itself when any of the values change.\n * @param values Values to register\n */\n public registerValues(_values: SkiaValue<unknown>[]) {\n // Unsubscribe from dependency values\n this.unsubscribeAll();\n // Register redraw dependencies on values\n _values.forEach((v) => {\n this._unsubscriptions.push(\n v.addListener(() => {\n this.redraw();\n })\n );\n });\n }\n\n private handleTouchEvent(evt: PointerEvent, touchType: TouchType) {\n this._touches.push({\n id: evt.pointerId,\n x: evt.clientX - evt.currentTarget.getClientRects()[0].left,\n y: evt.clientY - evt.currentTarget.getClientRects()[0].top,\n force: evt.pressure,\n type: touchType,\n timestamp: Date.now(),\n });\n this.redraw();\n }\n\n createTouchHandler(touchType: TouchType) {\n return (evt: PointerEvent) => this.handleTouchEvent(evt, touchType);\n }\n\n render() {\n const { mode, debug = false, ...viewProps } = this.props;\n return (\n <View {...viewProps} onLayout={this.onLayout.bind(this)}>\n <canvas\n ref={this._canvasRef}\n style={{ display: \"flex\", flex: 1 }}\n onPointerDown={this.createTouchHandler(TouchType.Start)}\n onPointerMove={this.createTouchHandler(TouchType.Active)}\n onPointerUp={this.createTouchHandler(TouchType.End)}\n onPointerCancel={this.createTouchHandler(TouchType.Cancelled)}\n onPointerLeave={this.createTouchHandler(TouchType.End)}\n onPointerOut={this.createTouchHandler(TouchType.End)}\n />\n </View>\n );\n }\n}\n"],"mappings":";;;;AAAA;AACA,OAAOA,KAAP,MAAkB,OAAlB;AAGA,SAASC,UAAT,EAAqBC,IAArB,QAAiC,cAAjC;AAIA,SAASC,YAAT,QAA6B,0BAA7B;AAGA,SAASC,SAAT,QAA0B,SAA1B;AAEA,MAAMC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ixelRatio","SkiaBaseWebView","Component","constructor","props","createRef","createTouchHandler","Start","Active","Cancelled","End","onLayoutEvent","bind","_mode","mode","unsubscribeAll","_unsubscriptions","forEach","u","evt","CanvasKit","global","canvas","_canvasRef","current","width","clientWidth","height","clientHeight","surface","MakeWebGLCanvasSurface","Error","_surface","_canvas","getCanvas","redraw","onLayout","getSize","componentDidMount","tick","componentDidUpdate","componentWillUnmount","cancelAnimationFrame","requestId","getContext","getExtension","loseContext","makeImageSnapshot","rect","clear","TRANSPARENT","renderInCanvas","ref","flush","_redrawRequests","touches","_touches","Float32Array","of","save","scale","restore","requestAnimationFrame","setDrawMode","registerValues","_values","v","push","addListener","handleTouchEvent","touchType","id","pointerId","x","clientX","currentTarget","getClientRects","left","y","clientY","top","force","pressure","type","timestamp","Date","now","render","debug","viewProps","display","flex","onStart","onActive","onEnd","onCancel"],"sources":["SkiaBaseWebView.tsx"],"sourcesContent":["/* global HTMLCanvasElement */\nimport React from \"react\";\nimport type { PointerEvent } from \"react\";\nimport type { LayoutChangeEvent } from \"react-native\";\n\nimport type { SkRect, SkCanvas } from \"../skia/types\";\nimport type { SkiaValue } from \"../values\";\nimport { JsiSkSurface } from \"../skia/web/JsiSkSurface\";\nimport { Platform } from \"../Platform\";\n\nimport type { DrawMode, SkiaBaseViewProps, TouchInfo } from \"./types\";\nimport { TouchType } from \"./types\";\n\nconst pd = Platform.PixelRatio;\n\nexport abstract class SkiaBaseWebView<\n TProps extends SkiaBaseViewProps\n> extends React.Component<TProps> {\n constructor(props: TProps) {\n super(props);\n this._mode = props.mode ?? \"default\";\n }\n\n private _surface: JsiSkSurface | null = null;\n private _unsubscriptions: Array<() => void> = [];\n private _touches: Array<TouchInfo> = [];\n private _canvas: SkCanvas | null = null;\n private _canvasRef = React.createRef<HTMLCanvasElement>();\n private _mode: DrawMode;\n private _redrawRequests = 0;\n private requestId = 0;\n\n protected width = 0;\n protected height = 0;\n\n private unsubscribeAll() {\n this._unsubscriptions.forEach((u) => u());\n this._unsubscriptions = [];\n }\n\n private onLayoutEvent(evt: LayoutChangeEvent) {\n const { CanvasKit } = global;\n // Reset canvas / surface on layout change\n const canvas = this._canvasRef.current;\n if (canvas) {\n this.width = canvas.clientWidth;\n this.height = canvas.clientHeight;\n canvas.width = this.width * pd;\n canvas.height = this.height * pd;\n const surface = CanvasKit.MakeWebGLCanvasSurface(canvas);\n if (!surface) {\n throw new Error(\"Could not create surface\");\n }\n this._surface = new JsiSkSurface(CanvasKit, surface);\n this._canvas = this._surface.getCanvas();\n this.redraw();\n }\n // Call onLayout callback if it exists\n if (this.props.onLayout) {\n this.props.onLayout(evt);\n }\n }\n\n protected getSize() {\n return { width: this.width, height: this.height };\n }\n\n componentDidMount() {\n // Start render loop\n this.tick();\n }\n\n componentDidUpdate() {\n this.redraw();\n }\n\n componentWillUnmount() {\n this.unsubscribeAll();\n cancelAnimationFrame(this.requestId);\n // https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_lose_context\n this._canvasRef.current\n ?.getContext(\"webgl2\")\n ?.getExtension(\"WEBGL_lose_context\")\n ?.loseContext();\n }\n\n /**\n * Creates a snapshot from the canvas in the surface\n * @param rect Rect to use as bounds. Optional.\n * @returns An Image object.\n */\n public makeImageSnapshot(rect?: SkRect) {\n this._canvas!.clear(CanvasKit.TRANSPARENT);\n this.renderInCanvas(this._canvas!, []);\n this._surface?.ref.flush();\n return this._surface?.makeImageSnapshot(rect);\n }\n\n /**\n * Override to render\n */\n protected abstract renderInCanvas(\n canvas: SkCanvas,\n touches: TouchInfo[]\n ): void;\n\n /**\n * Sends a redraw request to the native SkiaView.\n */\n private tick() {\n if (this._mode === \"continuous\" || this._redrawRequests > 0) {\n this._redrawRequests = 0;\n if (this._canvas) {\n const touches = [...this._touches];\n this._touches = [];\n const canvas = this._canvas!;\n canvas.clear(Float32Array.of(0, 0, 0, 0));\n canvas.save();\n canvas.scale(pd, pd);\n this.renderInCanvas(canvas, touches);\n canvas.restore();\n this._surface?.ref.flush();\n }\n }\n this.requestId = requestAnimationFrame(this.tick.bind(this));\n }\n\n public redraw() {\n this._redrawRequests++;\n }\n\n /**\n * Updates the drawing mode for the skia view. This is the same\n * as declaratively setting the mode property on the SkiaView.\n * There are two drawing modes, \"continuous\" and \"default\",\n * where the continuous mode will continuously redraw the view and\n * the default mode will only redraw when any of the regular react\n * properties are changed like size and margins.\n * @param mode Drawing mode to use.\n */\n public setDrawMode(mode: DrawMode) {\n this._mode = mode;\n this.tick();\n }\n\n /**\n * Registers one or move values as a dependant value of the Skia View. The view will\n * The view will redraw itself when any of the values change.\n * @param values Values to register\n */\n public registerValues(_values: SkiaValue<unknown>[]) {\n // Unsubscribe from dependency values\n this.unsubscribeAll();\n // Register redraw dependencies on values\n _values.forEach((v) => {\n this._unsubscriptions.push(\n v.addListener(() => {\n this.redraw();\n })\n );\n });\n }\n\n private handleTouchEvent(evt: PointerEvent, touchType: TouchType) {\n this._touches.push({\n id: evt.pointerId,\n x: evt.clientX - evt.currentTarget.getClientRects()[0].left,\n y: evt.clientY - evt.currentTarget.getClientRects()[0].top,\n force: evt.pressure,\n type: touchType,\n timestamp: Date.now(),\n });\n this.redraw();\n }\n\n createTouchHandler(touchType: TouchType) {\n return (evt: PointerEvent) => this.handleTouchEvent(evt, touchType);\n }\n\n private onStart = this.createTouchHandler(TouchType.Start);\n private onActive = this.createTouchHandler(TouchType.Active);\n private onCancel = this.createTouchHandler(TouchType.Cancelled);\n private onEnd = this.createTouchHandler(TouchType.End);\n private onLayout = this.onLayoutEvent.bind(this);\n\n render() {\n const { mode, debug = false, ...viewProps } = this.props;\n return (\n <Platform.View {...viewProps} onLayout={this.onLayout}>\n <canvas\n ref={this._canvasRef}\n style={{ display: \"flex\", flex: 1 }}\n onPointerDown={this.onStart}\n onPointerMove={this.onActive}\n onPointerUp={this.onEnd}\n onPointerCancel={this.onCancel}\n onPointerLeave={this.onEnd}\n onPointerOut={this.onEnd}\n />\n </Platform.View>\n );\n }\n}\n"],"mappings":";;;;AAAA;AACA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,KAAKD,KAPvB;MAQE,YAAY,EAAE,KAAKA;IARrB,EADF,CADF;EAcD;;AAxL+B"}
|
@@ -3,10 +3,10 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
|
|
3
3
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
4
4
|
|
5
5
|
import React from "react";
|
6
|
-
import {
|
6
|
+
import { Platform } from "../Platform";
|
7
7
|
import { SkiaViewApi } from "./api";
|
8
8
|
import { SkiaViewNativeId } from "./SkiaView";
|
9
|
-
const NativeSkiaDomView = Platform.OS !== "web" ? requireNativeComponent("SkiaDomView") : // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
9
|
+
const NativeSkiaDomView = Platform.OS !== "web" ? Platform.requireNativeComponent("SkiaDomView") : // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
10
10
|
null;
|
11
11
|
export class SkiaDomView extends React.Component {
|
12
12
|
constructor(props) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["React","
|
1
|
+
{"version":3,"names":["React","Platform","SkiaViewApi","SkiaViewNativeId","NativeSkiaDomView","OS","requireNativeComponent","SkiaDomView","Component","constructor","props","_nativeId","current","root","onTouch","onSize","assertSkiaViewApi","setJsiProperty","nativeId","componentDidUpdate","prevProps","makeImageSnapshot","rect","redraw","requestRedraw","registerValues","values","registerValuesInView","componentWillUnmount","render","mode","debug","viewProps","callJsiMethod","Error"],"sources":["SkiaDomView.tsx"],"sourcesContent":["import React from \"react\";\nimport type { HostComponent } from \"react-native\";\n\nimport type { SkRect } from \"../skia/types\";\nimport type { SkiaValue } from \"../values\";\nimport { Platform } from \"../Platform\";\n\nimport { SkiaViewApi } from \"./api\";\nimport { SkiaViewNativeId } from \"./SkiaView\";\nimport type { NativeSkiaViewProps, SkiaDomViewProps } from \"./types\";\n\nconst NativeSkiaDomView: HostComponent<SkiaDomViewProps> =\n Platform.OS !== \"web\"\n ? Platform.requireNativeComponent<NativeSkiaViewProps>(\"SkiaDomView\")\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (null as any);\n\nexport class SkiaDomView extends React.Component<SkiaDomViewProps> {\n constructor(props: SkiaDomViewProps) {\n super(props);\n this._nativeId = SkiaViewNativeId.current++;\n const { root, onTouch, onSize } = props;\n if (root) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"root\", root);\n }\n if (onTouch) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onTouch\", onTouch);\n }\n if (onSize) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onSize\", onSize);\n }\n }\n\n private _nativeId: number;\n\n public get nativeId() {\n return this._nativeId;\n }\n\n componentDidUpdate(prevProps: SkiaDomViewProps) {\n const { root, onTouch, onSize } = this.props;\n if (root !== prevProps.root) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"root\", root);\n }\n if (onTouch !== prevProps.onTouch) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onTouch\", onTouch);\n }\n if (onSize !== prevProps.onSize) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onSize\", onSize);\n }\n }\n\n /**\n * Creates a snapshot from the canvas in the surface\n * @param rect Rect to use as bounds. Optional.\n * @returns An Image object.\n */\n public makeImageSnapshot(rect?: SkRect) {\n assertSkiaViewApi();\n return SkiaViewApi.makeImageSnapshot(this._nativeId, rect);\n }\n\n /**\n * Sends a redraw request to the native SkiaView.\n */\n public redraw() {\n assertSkiaViewApi();\n SkiaViewApi.requestRedraw(this._nativeId);\n }\n\n /**\n * Registers one or move values as a dependant value of the Skia View. The view will\n * The view will redraw itself when any of the values change.\n * @param values Values to register\n */\n public registerValues(values: SkiaValue<unknown>[]): () => void {\n assertSkiaViewApi();\n return SkiaViewApi.registerValuesInView(this._nativeId, values);\n }\n\n /**\n * Clear up the dom node when unmounting to release resources.\n */\n componentWillUnmount(): void {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"root\", null);\n }\n\n render() {\n const { mode, debug = false, ...viewProps } = this.props;\n return (\n <NativeSkiaDomView\n collapsable={false}\n nativeID={`${this._nativeId}`}\n mode={mode}\n debug={debug}\n {...viewProps}\n />\n );\n }\n}\n\nconst assertSkiaViewApi = () => {\n if (\n SkiaViewApi === null ||\n SkiaViewApi.setJsiProperty === null ||\n SkiaViewApi.callJsiMethod === null ||\n SkiaViewApi.registerValuesInView === null ||\n SkiaViewApi.requestRedraw === null ||\n SkiaViewApi.makeImageSnapshot === null\n ) {\n throw Error(\"Skia View Api was not found.\");\n }\n};\n"],"mappings":";;;;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AAKA,SAASC,QAAT,QAAyB,aAAzB;AAEA,SAASC,WAAT,QAA4B,OAA5B;AACA,SAASC,gBAAT,QAAiC,YAAjC;AAGA,MAAMC,iBAAkD,GACtDH,QAAQ,CAACI,EAAT,KAAgB,KAAhB,GACIJ,QAAQ,CAACK,sBAAT,CAAqD,aAArD,CADJ,GAEI;AACC,IAJP;AAMA,OAAO,MAAMC,WAAN,SAA0BP,KAAK,CAACQ,SAAhC,CAA4D;EACjEC,WAAW,CAACC,KAAD,EAA0B;IACnC,MAAMA,KAAN;;IADmC;;IAEnC,KAAKC,SAAL,GAAiBR,gBAAgB,CAACS,OAAjB,EAAjB;IACA,MAAM;MAAEC,IAAF;MAAQC,OAAR;MAAiBC;IAAjB,IAA4BL,KAAlC;;IACA,IAAIG,IAAJ,EAAU;MACRG,iBAAiB;MACjBd,WAAW,CAACe,cAAZ,CAA2B,KAAKN,SAAhC,EAA2C,MAA3C,EAAmDE,IAAnD;IACD;;IACD,IAAIC,OAAJ,EAAa;MACXE,iBAAiB;MACjBd,WAAW,CAACe,cAAZ,CAA2B,KAAKN,SAAhC,EAA2C,SAA3C,EAAsDG,OAAtD;IACD;;IACD,IAA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Bd,WAAW,CAACe,cAAZ,CAA2B,KAAKN,SAAhC,EAA2C,MAA3C,EAAmD,IAAnD;EACD;;EAEDkB,MAAM,GAAG;IACP,MAAM;MAAEC,IAAF;MAAQC,KAAK,GAAG,KAAhB;MAAuB,GAAGC;IAA1B,IAAwC,KAAKtB,KAAnD;IACA,oBACE,oBAAC,iBAAD;MACE,WAAW,EAAE,KADf;MAEE,QAAQ,EAAG,GAAE,KAAKC,SAAU,EAF9B;MAGE,IAAI,EAAEmB,IAHR;MAIE,KAAK,EAAEC;IAJT,GAKMC,SALN,EADF;EASD;;AAxFgE;;AA2FnE,MAAMhB,iBAAiB,GAAG,MAAM;EAC9B,IACEd,WAAW,KAAK,IAAhB,IACAA,WAAW,CAACe,cAAZ,KAA+B,IAD/B,IAEAf,WAAW,CAAC+B,aAAZ,KAA8B,IAF9B,IAGA/B,WAAW,CAACyB,oBAAZ,KAAqC,IAHrC,IAIAzB,WAAW,CAACsB,aAAZ,KAA8B,IAJ9B,IAKAtB,WAAW,CAACmB,iBAAZ,KAAkC,IANpC,EAOE;IACA,MAAMa,KAAK,CAAC,8BAAD,CAAX;EACD;AACF,CAXD"}
|
@@ -3,10 +3,10 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
|
|
3
3
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
4
4
|
|
5
5
|
import React from "react";
|
6
|
-
import {
|
6
|
+
import { Platform } from "../Platform";
|
7
7
|
import { SkiaViewApi } from "./api";
|
8
8
|
import { SkiaViewNativeId } from "./SkiaView";
|
9
|
-
const NativeSkiaPictureView = requireNativeComponent("SkiaPictureView");
|
9
|
+
const NativeSkiaPictureView = Platform.requireNativeComponent("SkiaPictureView");
|
10
10
|
export class SkiaPictureView extends React.Component {
|
11
11
|
constructor(props) {
|
12
12
|
super(props);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["React","
|
1
|
+
{"version":3,"names":["React","Platform","SkiaViewApi","SkiaViewNativeId","NativeSkiaPictureView","requireNativeComponent","SkiaPictureView","Component","constructor","props","_nativeId","current","picture","onSize","assertSkiaViewApi","setJsiProperty","nativeId","componentDidUpdate","prevProps","makeImageSnapshot","rect","redraw","requestRedraw","registerValues","values","registerValuesInView","render","mode","debug","viewProps","callJsiMethod","Error"],"sources":["SkiaPictureView.tsx"],"sourcesContent":["import React from \"react\";\n\nimport type { SkRect } from \"../skia/types\";\nimport type { SkiaValue } from \"../values\";\nimport { Platform } from \"../Platform\";\n\nimport { SkiaViewApi } from \"./api\";\nimport { SkiaViewNativeId } from \"./SkiaView\";\nimport type { NativeSkiaViewProps, SkiaPictureViewProps } from \"./types\";\n\nconst NativeSkiaPictureView =\n Platform.requireNativeComponent<NativeSkiaViewProps>(\"SkiaPictureView\");\n\nexport class SkiaPictureView extends React.Component<SkiaPictureViewProps> {\n constructor(props: SkiaPictureViewProps) {\n super(props);\n this._nativeId = SkiaViewNativeId.current++;\n const { picture, onSize } = props;\n if (picture) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"picture\", picture);\n }\n if (onSize) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onSize\", onSize);\n }\n }\n\n private _nativeId: number;\n\n public get nativeId() {\n return this._nativeId;\n }\n\n componentDidUpdate(prevProps: SkiaPictureViewProps) {\n const { picture, onSize } = this.props;\n if (picture !== prevProps.picture) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"picture\", picture);\n }\n if (onSize !== prevProps.onSize) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onSize\", onSize);\n }\n }\n\n /**\n * Creates a snapshot from the canvas in the surface\n * @param rect Rect to use as bounds. Optional.\n * @returns An Image object.\n */\n public makeImageSnapshot(rect?: SkRect) {\n assertSkiaViewApi();\n return SkiaViewApi.makeImageSnapshot(this._nativeId, rect);\n }\n\n /**\n * Sends a redraw request to the native SkiaView.\n */\n public redraw() {\n assertSkiaViewApi();\n SkiaViewApi.requestRedraw(this._nativeId);\n }\n\n /**\n * Registers one or move values as a dependant value of the Skia View. The view will\n * The view will redraw itself when any of the values change.\n * @param values Values to register\n */\n public registerValues(values: SkiaValue<unknown>[]): () => void {\n assertSkiaViewApi();\n return SkiaViewApi.registerValuesInView(this._nativeId, values);\n }\n\n render() {\n const { mode, debug = false, ...viewProps } = this.props;\n return (\n <NativeSkiaPictureView\n collapsable={false}\n nativeID={`${this._nativeId}`}\n mode={mode}\n debug={debug}\n {...viewProps}\n />\n );\n }\n}\n\nconst assertSkiaViewApi = () => {\n if (\n SkiaViewApi === null ||\n SkiaViewApi.setJsiProperty === null ||\n SkiaViewApi.callJsiMethod === null ||\n SkiaViewApi.registerValuesInView === null ||\n SkiaViewApi.requestRedraw === null ||\n SkiaViewApi.makeImageSnapshot === null\n ) {\n throw Error(\"Skia View Api was not found.\");\n }\n};\n"],"mappings":";;;;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AAIA,SAASC,QAAT,QAAyB,aAAzB;AAEA,SAASC,WAAT,QAA4B,OAA5B;AACA,SAASC,gBAAT,QAAiC,YAAjC;AAGA,MAAMC,qBAAqB,GACzBH,QAAQ,CAACI,sBAAT,CAAqD,iBAArD,CADF;AAGA,OAAO,MAAMC,eAAN,SAA8BN,KAAK,CAACO,SAApC,CAAoE;EACzEC,WAAW,CAACC,KAAD,EAA8B;IACvC,MAAMA,KAAN;;IADuC;;IAEvC,KAAKC,SAAL,GAAiBP,gBAAgB,CAACQ,OAAjB,EAAjB;IACA,MAAM;MAAEC,OAAF;MAAWC;IAAX,IAAsBJ,KAA5B;;IACA,IAAIG,OAAJ,EAAa;MACXE,iBAAiB;MACjBZ,WAAW,CAACa,cAAZ,CAA2B,KAAKL,SAAhC,EAA2C,SAA3C,EAAsDE,OAAtD;IACD;;IACD,IAAIC,MAAJ,EAAY;MACVC,iBAAiB;MACjBZ,WA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MC,SALN,EADF;EASD;;AAxEwE;;AA2E3E,MAAMf,iBAAiB,GAAG,MAAM;EAC9B,IACEZ,WAAW,KAAK,IAAhB,IACAA,WAAW,CAACa,cAAZ,KAA+B,IAD/B,IAEAb,WAAW,CAAC4B,aAAZ,KAA8B,IAF9B,IAGA5B,WAAW,CAACuB,oBAAZ,KAAqC,IAHrC,IAIAvB,WAAW,CAACoB,aAAZ,KAA8B,IAJ9B,IAKApB,WAAW,CAACiB,iBAAZ,KAAkC,IANpC,EAOE;IACA,MAAMY,KAAK,CAAC,8BAAD,CAAX;EACD;AACF,CAXD"}
|
@@ -3,12 +3,12 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
|
|
3
3
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
4
4
|
|
5
5
|
import React from "react";
|
6
|
-
import {
|
6
|
+
import { Platform } from "../Platform";
|
7
7
|
import { SkiaViewApi } from "./api";
|
8
8
|
export const SkiaViewNativeId = {
|
9
9
|
current: 1000
|
10
10
|
};
|
11
|
-
const NativeSkiaView = requireNativeComponent("SkiaDrawView");
|
11
|
+
const NativeSkiaView = Platform.requireNativeComponent("SkiaDrawView");
|
12
12
|
export class SkiaView extends React.Component {
|
13
13
|
constructor(props) {
|
14
14
|
super(props);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["React","
|
1
|
+
{"version":3,"names":["React","Platform","SkiaViewApi","SkiaViewNativeId","current","NativeSkiaView","requireNativeComponent","SkiaView","Component","constructor","props","_nativeId","onDraw","onSize","assertSkiaViewApi","setJsiProperty","nativeId","componentDidUpdate","prevProps","makeImageSnapshot","rect","redraw","requestRedraw","registerValues","values","registerValuesInView","render","mode","debug","viewProps","callJsiMethod","Error"],"sources":["SkiaView.tsx"],"sourcesContent":["import React from \"react\";\n\nimport type { SkRect } from \"../skia/types\";\nimport type { SkiaValue } from \"../values\";\nimport { Platform } from \"../Platform\";\n\nimport { SkiaViewApi } from \"./api\";\nimport type { NativeSkiaViewProps, SkiaDrawViewProps } from \"./types\";\n\nexport const SkiaViewNativeId = { current: 1000 };\n\nconst NativeSkiaView =\n Platform.requireNativeComponent<NativeSkiaViewProps>(\"SkiaDrawView\");\n\nexport class SkiaView extends React.Component<SkiaDrawViewProps> {\n constructor(props: SkiaDrawViewProps) {\n super(props);\n this._nativeId = SkiaViewNativeId.current++;\n const { onDraw, onSize } = props;\n if (onDraw) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"drawCallback\", onDraw);\n }\n if (onSize) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onSize\", onSize);\n }\n }\n\n private _nativeId: number;\n\n public get nativeId() {\n return this._nativeId;\n }\n\n componentDidUpdate(prevProps: SkiaDrawViewProps) {\n const { onDraw, onSize } = this.props;\n if (onDraw !== prevProps.onDraw) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"drawCallback\", onDraw);\n }\n if (onSize !== prevProps.onSize) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onSize\", onSize);\n }\n }\n\n /**\n * Creates a snapshot from the canvas in the surface\n * @param rect Rect to use as bounds. Optional.\n * @returns An Image object.\n */\n public makeImageSnapshot(rect?: SkRect) {\n assertSkiaViewApi();\n return SkiaViewApi.makeImageSnapshot(this._nativeId, rect);\n }\n\n /**\n * Sends a redraw request to the native SkiaView.\n */\n public redraw() {\n assertSkiaViewApi();\n SkiaViewApi.requestRedraw(this._nativeId);\n }\n\n /**\n * Registers one or move values as a dependant value of the Skia View. The view will\n * The view will redraw itself when any of the values change.\n * @param values Values to register\n */\n public registerValues(values: SkiaValue<unknown>[]): () => void {\n assertSkiaViewApi();\n return SkiaViewApi.registerValuesInView(this._nativeId, values);\n }\n\n render() {\n const { mode, debug = false, onSize, ...viewProps } = this.props;\n return (\n <NativeSkiaView\n collapsable={false}\n nativeID={`${this._nativeId}`}\n mode={mode}\n debug={debug}\n {...viewProps}\n />\n );\n }\n}\n\nconst assertSkiaViewApi = () => {\n if (\n SkiaViewApi === null ||\n SkiaViewApi.setJsiProperty === null ||\n SkiaViewApi.callJsiMethod === null ||\n SkiaViewApi.registerValuesInView === null ||\n SkiaViewApi.requestRedraw === null ||\n SkiaViewApi.makeImageSnapshot === null\n ) {\n throw Error(\"Skia View Api was not found.\");\n }\n};\n"],"mappings":";;;;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AAIA,SAASC,QAAT,QAAyB,aAAzB;AAEA,SAASC,WAAT,QAA4B,OAA5B;AAGA,OAAO,MAAMC,gBAAgB,GAAG;EAAEC,OAAO,EAAE;AAAX,CAAzB;AAEP,MAAMC,cAAc,GAClBJ,QAAQ,CAACK,sBAAT,CAAqD,cAArD,CADF;AAGA,OAAO,MAAMC,QAAN,SAAuBP,KAAK,CAACQ,SAA7B,CAA0D;EAC/DC,WAAW,CAACC,KAAD,EAA2B;IACpC,MAAMA,KAAN;;IADoC;;IAEpC,KAAKC,SAAL,GAAiBR,gBAAgB,CAACC,OAAjB,EAAjB;IACA,MAAM;MAAEQ,MAAF;MAAUC;IAAV,IAAqBH,KAA3B;;IACA,IAAIE,MAAJ,EAAY;MACVE,iBAAiB;MACjBZ,WAAW,CAACa,cAAZ,CAA2B,KAAKJ,SAAhC,EAA2C,cAA3C,EAA2DC,MAA3D;IACD;;IACD,IAAIC,MAAJ,EAAY;MACVC,iBAAiB;MACjBZ,WAAW,CAACa,cAAZ,CAA2B,KAAKJ,SAAhC,EAA2C,QAA3C,EAAqDE,MAArD;IACD;EACF;;EAIkB,IAARG,QAAQ,GAAG;IACpB,OAAO,KAAKL,SAAZ;EACD;;EAEDM,kBAAkB,CAACC,SAAD,EAA+B;IAC/C,MAAM;MAAEN,MAAF;MAAUC;IAAV,IAAqB,KAAKH,KAAhC;;IACA,IAAIE,MAAM,KAAKM,SAAS,CAACN,MAAzB,EAAiC;MAC/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KApB,WAAW,CAACiB,iBAAZ,KAAkC,IANpC,EAOE;IACA,MAAMY,KAAK,CAAC,8BAAD,CAAX;EACD;AACF,CAXD"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { useCallback, useRef } from "react";
|
2
|
-
import {
|
2
|
+
import { Platform } from "../Platform";
|
3
3
|
import { TouchType } from "./types";
|
4
4
|
|
5
5
|
const useInternalTouchHandler = function (handlers) {
|
@@ -27,8 +27,8 @@ const useInternalTouchHandler = function (handlers) {
|
|
27
27
|
|
28
28
|
if (touch.type !== TouchType.Start && touch.type !== TouchType.End && touch.type !== TouchType.Cancelled && timeDiffseconds > 0) {
|
29
29
|
prevVelocityRef.current[touch.id] = {
|
30
|
-
x: distX / timeDiffseconds / PixelRatio
|
31
|
-
y: distY / timeDiffseconds / PixelRatio
|
30
|
+
x: distX / timeDiffseconds / Platform.PixelRatio,
|
31
|
+
y: distY / timeDiffseconds / Platform.PixelRatio
|
32
32
|
};
|
33
33
|
}
|
34
34
|
|