@shopify/react-native-skia 2.2.10 → 2.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cpp/api/JsiNativeBuffer.h +2 -0
- package/cpp/api/JsiSkAnimatedImage.h +6 -2
- package/cpp/api/JsiSkAnimatedImageFactory.h +6 -3
- package/cpp/api/JsiSkApi.h +2 -0
- package/cpp/api/JsiSkCanvas.h +2 -0
- package/cpp/api/JsiSkColorFilter.h +2 -0
- package/cpp/api/JsiSkColorFilterFactory.h +31 -23
- package/cpp/api/JsiSkContourMeasure.h +8 -4
- package/cpp/api/JsiSkContourMeasureIter.h +10 -4
- package/cpp/api/JsiSkData.h +5 -0
- package/cpp/api/JsiSkDataFactory.h +14 -7
- package/cpp/api/JsiSkFont.h +17 -10
- package/cpp/api/JsiSkFontMgr.h +6 -2
- package/cpp/api/JsiSkFontMgrFactory.h +5 -2
- package/cpp/api/JsiSkFontStyle.h +6 -3
- package/cpp/api/JsiSkHostObjects.h +21 -44
- package/cpp/api/JsiSkImage.h +17 -8
- package/cpp/api/JsiSkImageFactory.h +26 -13
- package/cpp/api/JsiSkImageFilter.h +2 -0
- package/cpp/api/JsiSkImageFilterFactory.h +160 -143
- package/cpp/api/JsiSkImageInfo.h +6 -3
- package/cpp/api/JsiSkMaskFilter.h +2 -0
- package/cpp/api/JsiSkMaskFilterFactory.h +7 -5
- package/cpp/api/JsiSkMatrix.h +6 -2
- package/cpp/api/JsiSkPaint.h +9 -4
- package/cpp/api/JsiSkParagraph.h +26 -23
- package/cpp/api/JsiSkParagraphBuilder.h +6 -3
- package/cpp/api/JsiSkParagraphBuilderFactory.h +6 -3
- package/cpp/api/JsiSkPath.h +33 -15
- package/cpp/api/JsiSkPathEffect.h +2 -0
- package/cpp/api/JsiSkPathEffectFactory.h +37 -32
- package/cpp/api/JsiSkPathFactory.h +22 -10
- package/cpp/api/JsiSkPicture.h +13 -2
- package/cpp/api/JsiSkPictureFactory.h +6 -2
- package/cpp/api/JsiSkPictureRecorder.h +14 -6
- package/cpp/api/JsiSkPoint.h +9 -5
- package/cpp/api/JsiSkRRect.h +13 -8
- package/cpp/api/JsiSkRSXform.h +14 -8
- package/cpp/api/JsiSkRect.h +13 -8
- package/cpp/api/JsiSkRuntimeEffect.h +10 -6
- package/cpp/api/JsiSkRuntimeEffectFactory.h +6 -3
- package/cpp/api/JsiSkRuntimeShaderBuilder.h +12 -6
- package/cpp/api/JsiSkSVG.h +24 -0
- package/cpp/api/JsiSkSVGFactory.h +8 -4
- package/cpp/api/JsiSkShader.h +2 -0
- package/cpp/api/JsiSkShaderFactory.h +34 -24
- package/cpp/api/JsiSkSkottie.h +29 -0
- package/cpp/api/JsiSkSurface.h +21 -5
- package/cpp/api/JsiSkSurfaceFactory.h +10 -6
- package/cpp/api/JsiSkTextBlob.h +12 -0
- package/cpp/api/JsiSkTextBlobFactory.h +18 -12
- package/cpp/api/JsiSkTypeface.h +19 -3
- package/cpp/api/JsiSkTypefaceFactory.h +6 -2
- package/cpp/api/JsiSkTypefaceFontProvider.h +10 -5
- package/cpp/api/JsiSkTypefaceFontProviderFactory.h +6 -3
- package/cpp/api/JsiSkVertices.h +16 -5
- package/cpp/api/JsiSkiaContext.h +10 -6
- package/cpp/api/JsiSkottieFactory.h +6 -3
- package/cpp/api/JsiVideo.h +10 -5
- package/cpp/api/recorder/DrawingCtx.h +2 -2
- package/cpp/api/recorder/JsiRecorder.h +12 -8
- package/cpp/api/recorder/Shaders.h +3 -2
- package/cpp/rnskia/RNSkJsiViewApi.h +22 -10
- package/lib/commonjs/renderer/Canvas.js +18 -1
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/sksg/Container.d.ts +1 -1
- package/lib/commonjs/sksg/Container.js +2 -2
- package/lib/commonjs/sksg/Container.js.map +1 -1
- package/lib/commonjs/sksg/Container.native.js +2 -5
- package/lib/commonjs/sksg/Container.native.js.map +1 -1
- package/lib/commonjs/sksg/Container.web.d.ts +2 -3
- package/lib/commonjs/sksg/Container.web.js +7 -14
- package/lib/commonjs/sksg/Container.web.js.map +1 -1
- package/lib/commonjs/sksg/StaticContainer.d.ts +2 -4
- package/lib/commonjs/sksg/StaticContainer.js +1 -8
- package/lib/commonjs/sksg/StaticContainer.js.map +1 -1
- package/lib/commonjs/specs/NativeSkiaModule.web.js +1 -0
- package/lib/commonjs/specs/NativeSkiaModule.web.js.map +1 -1
- package/lib/module/renderer/Canvas.js +19 -2
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/sksg/Container.d.ts +1 -1
- package/lib/module/sksg/Container.js +2 -2
- package/lib/module/sksg/Container.js.map +1 -1
- package/lib/module/sksg/Container.native.js +2 -5
- package/lib/module/sksg/Container.native.js.map +1 -1
- package/lib/module/sksg/Container.web.d.ts +2 -3
- package/lib/module/sksg/Container.web.js +7 -14
- package/lib/module/sksg/Container.web.js.map +1 -1
- package/lib/module/sksg/StaticContainer.d.ts +2 -4
- package/lib/module/sksg/StaticContainer.js +1 -8
- package/lib/module/sksg/StaticContainer.js.map +1 -1
- package/lib/module/specs/NativeSkiaModule.web.js +1 -0
- package/lib/module/specs/NativeSkiaModule.web.js.map +1 -1
- package/lib/typescript/lib/commonjs/sksg/Container.d.ts +1 -1
- package/lib/typescript/lib/commonjs/sksg/Container.web.d.ts +2 -3
- package/lib/typescript/lib/commonjs/sksg/StaticContainer.d.ts +1 -2
- package/lib/typescript/lib/module/sksg/Container.d.ts +1 -1
- package/lib/typescript/lib/module/sksg/Container.web.d.ts +2 -3
- package/lib/typescript/lib/module/sksg/StaticContainer.d.ts +1 -2
- package/lib/typescript/src/sksg/Container.d.ts +1 -1
- package/lib/typescript/src/sksg/Container.web.d.ts +2 -3
- package/lib/typescript/src/sksg/StaticContainer.d.ts +2 -4
- package/package.json +1 -1
- package/src/renderer/Canvas.tsx +17 -0
- package/src/sksg/Container.native.ts +2 -9
- package/src/sksg/Container.ts +2 -2
- package/src/sksg/Container.web.ts +7 -25
- package/src/sksg/StaticContainer.ts +2 -17
- package/src/specs/NativeSkiaModule.web.ts +1 -0
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["global","SkiaViewApi","views","deferedPictures","web","registerView","nativeId","view","setPicture","setJsiProperty","name","value","size","getSize","width","height","requestRedraw","redraw","makeImageSnapshot","rect","makeImageSnapshotAsync","Promise","resolve","reject","result","Error","_default","exports","default"],"sources":["NativeSkiaModule.web.ts"],"sourcesContent":["/* eslint-disable import/no-anonymous-default-export */\nimport type { SkPicture, SkRect } from \"../skia/types\";\nimport type { ISkiaViewApi } from \"../views/types\";\nimport type { SkiaPictureViewHandle } from \"../views/SkiaPictureView.web\";\n\nexport type ISkiaViewApiWeb = ISkiaViewApi & {\n views: Record<string, SkiaPictureViewHandle>;\n deferedPictures: Record<string, SkPicture>;\n registerView(nativeId: string, view: SkiaPictureViewHandle): void;\n};\n\nglobal.SkiaViewApi = {\n views: {},\n deferedPictures: {},\n web: true,\n registerView(nativeId: string, view: SkiaPictureViewHandle) {\n // Maybe a picture for this view was already set\n if (this.deferedPictures[nativeId]) {\n view.setPicture(this.deferedPictures[nativeId] as SkPicture);\n }\n this.views[nativeId] = view;\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n setJsiProperty(nativeId: number, name: string, value: any) {\n if (name === \"picture\") {\n if (!this.views[`${nativeId}`]) {\n this.deferedPictures[`${nativeId}`] = value;\n } else {\n this.views[`${nativeId}`].setPicture(value);\n }\n }\n },\n size(nativeId: number) {\n if (this.views[`${nativeId}`]) {\n return this.views[`${nativeId}`].getSize();\n } else {\n return { width: 0, height: 0 };\n }\n },\n requestRedraw(nativeId: number) {\n this.views[`${nativeId}`].redraw();\n },\n makeImageSnapshot(nativeId: number, rect?: SkRect) {\n return this.views[`${nativeId}`].makeImageSnapshot(rect);\n },\n makeImageSnapshotAsync(nativeId: number, rect?: SkRect) {\n return new Promise((resolve, reject) => {\n const result = this.views[`${nativeId}`].makeImageSnapshot(rect);\n if (result) {\n resolve(result);\n } else {\n reject(new Error(\"Failed to make image snapshot\"));\n }\n });\n },\n} as ISkiaViewApiWeb;\n\n// eslint-disable-next-line import/no-default-export\nexport default {};\n"],"mappings":";;;;;;AAAA;;AAWAA,MAAM,CAACC,WAAW,GAAG;EACnBC,KAAK,EAAE,CAAC,CAAC;EACTC,eAAe,EAAE,CAAC,CAAC;EACnBC,GAAG,EAAE,IAAI;EACTC,YAAYA,CAACC,QAAgB,EAAEC,IAA2B,EAAE;IAC1D;IACA,IAAI,IAAI,
|
1
|
+
{"version":3,"names":["global","SkiaViewApi","views","deferedPictures","deferedOnSize","web","registerView","nativeId","view","setPicture","setJsiProperty","name","value","size","getSize","width","height","requestRedraw","redraw","makeImageSnapshot","rect","makeImageSnapshotAsync","Promise","resolve","reject","result","Error","_default","exports","default"],"sources":["NativeSkiaModule.web.ts"],"sourcesContent":["/* eslint-disable import/no-anonymous-default-export */\nimport type { SkPicture, SkRect } from \"../skia/types\";\nimport type { ISkiaViewApi } from \"../views/types\";\nimport type { SkiaPictureViewHandle } from \"../views/SkiaPictureView.web\";\n\nexport type ISkiaViewApiWeb = ISkiaViewApi & {\n views: Record<string, SkiaPictureViewHandle>;\n deferedPictures: Record<string, SkPicture>;\n registerView(nativeId: string, view: SkiaPictureViewHandle): void;\n};\n\nglobal.SkiaViewApi = {\n views: {},\n deferedPictures: {},\n deferedOnSize: {},\n web: true,\n registerView(nativeId: string, view: SkiaPictureViewHandle) {\n // Maybe a picture for this view was already set\n if (this.deferedPictures[nativeId]) {\n view.setPicture(this.deferedPictures[nativeId] as SkPicture);\n }\n this.views[nativeId] = view;\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n setJsiProperty(nativeId: number, name: string, value: any) {\n if (name === \"picture\") {\n if (!this.views[`${nativeId}`]) {\n this.deferedPictures[`${nativeId}`] = value;\n } else {\n this.views[`${nativeId}`].setPicture(value);\n }\n }\n },\n size(nativeId: number) {\n if (this.views[`${nativeId}`]) {\n return this.views[`${nativeId}`].getSize();\n } else {\n return { width: 0, height: 0 };\n }\n },\n requestRedraw(nativeId: number) {\n this.views[`${nativeId}`].redraw();\n },\n makeImageSnapshot(nativeId: number, rect?: SkRect) {\n return this.views[`${nativeId}`].makeImageSnapshot(rect);\n },\n makeImageSnapshotAsync(nativeId: number, rect?: SkRect) {\n return new Promise((resolve, reject) => {\n const result = this.views[`${nativeId}`].makeImageSnapshot(rect);\n if (result) {\n resolve(result);\n } else {\n reject(new Error(\"Failed to make image snapshot\"));\n }\n });\n },\n} as ISkiaViewApiWeb;\n\n// eslint-disable-next-line import/no-default-export\nexport default {};\n"],"mappings":";;;;;;AAAA;;AAWAA,MAAM,CAACC,WAAW,GAAG;EACnBC,KAAK,EAAE,CAAC,CAAC;EACTC,eAAe,EAAE,CAAC,CAAC;EACnBC,aAAa,EAAE,CAAC,CAAC;EACjBC,GAAG,EAAE,IAAI;EACTC,YAAYA,CAACC,QAAgB,EAAEC,IAA2B,EAAE;IAC1D;IACA,IAAI,IAAI,CAACL,eAAe,CAACI,QAAQ,CAAC,EAAE;MAClCC,IAAI,CAACC,UAAU,CAAC,IAAI,CAACN,eAAe,CAACI,QAAQ,CAAc,CAAC;IAC9D;IACA,IAAI,CAACL,KAAK,CAACK,QAAQ,CAAC,GAAGC,IAAI;EAC7B,CAAC;EACD;EACAE,cAAcA,CAACH,QAAgB,EAAEI,IAAY,EAAEC,KAAU,EAAE;IACzD,IAAID,IAAI,KAAK,SAAS,EAAE;MACtB,IAAI,CAAC,IAAI,CAACT,KAAK,CAAC,GAAGK,QAAQ,EAAE,CAAC,EAAE;QAC9B,IAAI,CAACJ,eAAe,CAAC,GAAGI,QAAQ,EAAE,CAAC,GAAGK,KAAK;MAC7C,CAAC,MAAM;QACL,IAAI,CAACV,KAAK,CAAC,GAAGK,QAAQ,EAAE,CAAC,CAACE,UAAU,CAACG,KAAK,CAAC;MAC7C;IACF;EACF,CAAC;EACDC,IAAIA,CAACN,QAAgB,EAAE;IACrB,IAAI,IAAI,CAACL,KAAK,CAAC,GAAGK,QAAQ,EAAE,CAAC,EAAE;MAC7B,OAAO,IAAI,CAACL,KAAK,CAAC,GAAGK,QAAQ,EAAE,CAAC,CAACO,OAAO,CAAC,CAAC;IAC5C,CAAC,MAAM;MACL,OAAO;QAAEC,KAAK,EAAE,CAAC;QAAEC,MAAM,EAAE;MAAE,CAAC;IAChC;EACF,CAAC;EACDC,aAAaA,CAACV,QAAgB,EAAE;IAC9B,IAAI,CAACL,KAAK,CAAC,GAAGK,QAAQ,EAAE,CAAC,CAACW,MAAM,CAAC,CAAC;EACpC,CAAC;EACDC,iBAAiBA,CAACZ,QAAgB,EAAEa,IAAa,EAAE;IACjD,OAAO,IAAI,CAAClB,KAAK,CAAC,GAAGK,QAAQ,EAAE,CAAC,CAACY,iBAAiB,CAACC,IAAI,CAAC;EAC1D,CAAC;EACDC,sBAAsBA,CAACd,QAAgB,EAAEa,IAAa,EAAE;IACtD,OAAO,IAAIE,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;MACtC,MAAMC,MAAM,GAAG,IAAI,CAACvB,KAAK,CAAC,GAAGK,QAAQ,EAAE,CAAC,CAACY,iBAAiB,CAACC,IAAI,CAAC;MAChE,IAAIK,MAAM,EAAE;QACVF,OAAO,CAACE,MAAM,CAAC;MACjB,CAAC,MAAM;QACLD,MAAM,CAAC,IAAIE,KAAK,CAAC,+BAA+B,CAAC,CAAC;MACpD;IACF,CAAC,CAAC;EACJ;AACF,CAAoB;;AAEpB;AAAA,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GACe,CAAC,CAAC","ignoreList":[]}
|
@@ -1,10 +1,11 @@
|
|
1
1
|
var _global;
|
2
2
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
3
|
-
import React, { useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from "react";
|
3
|
+
import React, { useCallback, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from "react";
|
4
4
|
import { SkiaViewNativeId } from "../views/SkiaViewNativeId";
|
5
5
|
import SkiaPictureViewNativeComponent from "../specs/SkiaPictureViewNativeComponent";
|
6
6
|
import { SkiaSGRoot } from "../sksg/Reconciler";
|
7
7
|
import { Skia } from "../skia";
|
8
|
+
import { Platform } from "../Platform";
|
8
9
|
export const useCanvasRef = () => useRef(null);
|
9
10
|
export const useCanvasSize = userRef => {
|
10
11
|
const ourRef = useCanvasRef();
|
@@ -92,13 +93,29 @@ export const Canvas = ({
|
|
92
93
|
(_viewRef$current2 = viewRef.current) === null || _viewRef$current2 === void 0 || _viewRef$current2.measureInWindow(callback);
|
93
94
|
}
|
94
95
|
}));
|
96
|
+
const onLayoutWeb = useCallback(e => {
|
97
|
+
if (onLayout) {
|
98
|
+
onLayout(e);
|
99
|
+
}
|
100
|
+
if (Platform.OS === "web" && onSize) {
|
101
|
+
const {
|
102
|
+
width,
|
103
|
+
height
|
104
|
+
} = e.nativeEvent.layout;
|
105
|
+
onSize.value = {
|
106
|
+
width,
|
107
|
+
height
|
108
|
+
};
|
109
|
+
}
|
110
|
+
}, [onLayout, onSize]);
|
95
111
|
return /*#__PURE__*/React.createElement(SkiaPictureViewNativeComponent, _extends({
|
96
112
|
ref: viewRef,
|
97
113
|
collapsable: false,
|
98
114
|
nativeID: `${nativeId}`,
|
99
115
|
debug: debug,
|
100
116
|
opaque: opaque,
|
101
|
-
colorSpace: colorSpace
|
117
|
+
colorSpace: colorSpace,
|
118
|
+
onLayout: onLayoutWeb
|
102
119
|
}, viewProps));
|
103
120
|
};
|
104
121
|
//# sourceMappingURL=Canvas.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["React","useEffect","useImperativeHandle","useLayoutEffect","useMemo","useRef","useState","SkiaViewNativeId","SkiaPictureViewNativeComponent","SkiaSGRoot","Skia","useCanvasRef","useCanvasSize","userRef","ourRef","ref","size","setSize","width","height","current","measure","_x","_y","isFabric","Boolean","_global","global","nativeFabricUIManager","Canvas","debug","opaque","children","onSize","colorSpace","onLayout","viewProps","console","error","viewRef","nativeId","root","render","unmount","makeImageSnapshot","rect","SkiaViewApi","makeImageSnapshotAsync","redraw","requestRedraw","getNativeId","callback","_viewRef$current","measureInWindow","_viewRef$current2","createElement","_extends","collapsable","nativeID"],"sources":["Canvas.tsx"],"sourcesContent":["import type { FC, RefObject } from \"react\";\nimport React, {\n useEffect,\n useImperativeHandle,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport type {\n MeasureInWindowOnSuccessCallback,\n MeasureOnSuccessCallback,\n View,\n ViewProps,\n} from \"react-native\";\nimport { type SharedValue } from \"react-native-reanimated\";\n\nimport { SkiaViewNativeId } from \"../views/SkiaViewNativeId\";\nimport SkiaPictureViewNativeComponent from \"../specs/SkiaPictureViewNativeComponent\";\nimport type { SkImage, SkRect, SkSize } from \"../skia/types\";\nimport { SkiaSGRoot } from \"../sksg/Reconciler\";\nimport { Skia } from \"../skia\";\n\nexport interface CanvasRef extends FC<CanvasProps> {\n makeImageSnapshot(rect?: SkRect): SkImage;\n makeImageSnapshotAsync(rect?: SkRect): Promise<SkImage>;\n redraw(): void;\n getNativeId(): number;\n measure(callback: MeasureOnSuccessCallback): void;\n measureInWindow(callback: MeasureInWindowOnSuccessCallback): void;\n}\n\nexport const useCanvasRef = () => useRef<CanvasRef>(null);\n\nexport const useCanvasSize = (userRef?: RefObject<CanvasRef | null>) => {\n const ourRef = useCanvasRef();\n const ref = userRef ?? ourRef;\n const [size, setSize] = useState<SkSize>({ width: 0, height: 0 });\n useLayoutEffect(() => {\n if (ref.current) {\n ref.current.measure((_x, _y, width, height) => {\n setSize({ width, height });\n });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n return { ref, size };\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const isFabric = Boolean((global as any)?.nativeFabricUIManager);\n\nexport interface CanvasProps extends Omit<ViewProps, \"onLayout\"> {\n debug?: boolean;\n opaque?: boolean;\n onSize?: SharedValue<SkSize>;\n colorSpace?: \"p3\" | \"srgb\";\n ref?: React.Ref<CanvasRef>;\n __destroyWebGLContextAfterRender?: boolean;\n}\n\nexport const Canvas = ({\n debug,\n opaque,\n children,\n onSize,\n colorSpace = \"p3\",\n ref,\n // Here know this is a type error but this is done on purpose to check it at runtime\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n onLayout,\n ...viewProps\n}: CanvasProps) => {\n if (onLayout && isFabric) {\n console.error(\n // eslint-disable-next-line max-len\n \"<Canvas onLayout={onLayout} /> is not supported on the new architecture, to fix the issue, see: https://shopify.github.io/react-native-skia/docs/canvas/overview/#getting-the-canvas-size\"\n );\n }\n const viewRef = useRef<View>(null);\n // Native ID\n const nativeId = useMemo(() => {\n return SkiaViewNativeId.current++;\n }, []);\n\n // Root\n const root = useMemo(\n () => new SkiaSGRoot(Skia, nativeId, onSize),\n [nativeId, onSize]\n );\n\n // Render effects\n useLayoutEffect(() => {\n root.render(children);\n }, [children, root, nativeId]);\n\n useEffect(() => {\n return () => {\n root.unmount();\n };\n }, [root]);\n\n // Component methods\n useImperativeHandle(\n ref,\n () =>\n ({\n makeImageSnapshot: (rect?: SkRect) => {\n return SkiaViewApi.makeImageSnapshot(nativeId, rect);\n },\n makeImageSnapshotAsync: (rect?: SkRect) => {\n return SkiaViewApi.makeImageSnapshotAsync(nativeId, rect);\n },\n redraw: () => {\n SkiaViewApi.requestRedraw(nativeId);\n },\n getNativeId: () => {\n return nativeId;\n },\n measure: (callback) => {\n viewRef.current?.measure(callback);\n },\n measureInWindow: (callback) => {\n viewRef.current?.measureInWindow(callback);\n },\n } as CanvasRef)\n );\n\n return (\n <SkiaPictureViewNativeComponent\n ref={viewRef}\n collapsable={false}\n nativeID={`${nativeId}`}\n debug={debug}\n opaque={opaque}\n colorSpace={colorSpace}\n {...viewProps}\n />\n );\n};\n"],"mappings":";;AACA,OAAOA,KAAK,IACVC,SAAS,EACTC,mBAAmB,EACnBC,eAAe,EACfC,OAAO,EACPC,MAAM,EACNC,QAAQ,QACH,OAAO;
|
1
|
+
{"version":3,"names":["React","useCallback","useEffect","useImperativeHandle","useLayoutEffect","useMemo","useRef","useState","SkiaViewNativeId","SkiaPictureViewNativeComponent","SkiaSGRoot","Skia","Platform","useCanvasRef","useCanvasSize","userRef","ourRef","ref","size","setSize","width","height","current","measure","_x","_y","isFabric","Boolean","_global","global","nativeFabricUIManager","Canvas","debug","opaque","children","onSize","colorSpace","onLayout","viewProps","console","error","viewRef","nativeId","root","render","unmount","makeImageSnapshot","rect","SkiaViewApi","makeImageSnapshotAsync","redraw","requestRedraw","getNativeId","callback","_viewRef$current","measureInWindow","_viewRef$current2","onLayoutWeb","e","OS","nativeEvent","layout","value","createElement","_extends","collapsable","nativeID"],"sources":["Canvas.tsx"],"sourcesContent":["import type { FC, RefObject } from \"react\";\nimport React, {\n useCallback,\n useEffect,\n useImperativeHandle,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport type {\n LayoutChangeEvent,\n MeasureInWindowOnSuccessCallback,\n MeasureOnSuccessCallback,\n View,\n ViewProps,\n} from \"react-native\";\nimport { type SharedValue } from \"react-native-reanimated\";\n\nimport { SkiaViewNativeId } from \"../views/SkiaViewNativeId\";\nimport SkiaPictureViewNativeComponent from \"../specs/SkiaPictureViewNativeComponent\";\nimport type { SkImage, SkRect, SkSize } from \"../skia/types\";\nimport { SkiaSGRoot } from \"../sksg/Reconciler\";\nimport { Skia } from \"../skia\";\nimport { Platform } from \"../Platform\";\n\nexport interface CanvasRef extends FC<CanvasProps> {\n makeImageSnapshot(rect?: SkRect): SkImage;\n makeImageSnapshotAsync(rect?: SkRect): Promise<SkImage>;\n redraw(): void;\n getNativeId(): number;\n measure(callback: MeasureOnSuccessCallback): void;\n measureInWindow(callback: MeasureInWindowOnSuccessCallback): void;\n}\n\nexport const useCanvasRef = () => useRef<CanvasRef>(null);\n\nexport const useCanvasSize = (userRef?: RefObject<CanvasRef | null>) => {\n const ourRef = useCanvasRef();\n const ref = userRef ?? ourRef;\n const [size, setSize] = useState<SkSize>({ width: 0, height: 0 });\n useLayoutEffect(() => {\n if (ref.current) {\n ref.current.measure((_x, _y, width, height) => {\n setSize({ width, height });\n });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n return { ref, size };\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const isFabric = Boolean((global as any)?.nativeFabricUIManager);\n\nexport interface CanvasProps extends Omit<ViewProps, \"onLayout\"> {\n debug?: boolean;\n opaque?: boolean;\n onSize?: SharedValue<SkSize>;\n colorSpace?: \"p3\" | \"srgb\";\n ref?: React.Ref<CanvasRef>;\n __destroyWebGLContextAfterRender?: boolean;\n}\n\nexport const Canvas = ({\n debug,\n opaque,\n children,\n onSize,\n colorSpace = \"p3\",\n ref,\n // Here know this is a type error but this is done on purpose to check it at runtime\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n onLayout,\n ...viewProps\n}: CanvasProps) => {\n if (onLayout && isFabric) {\n console.error(\n // eslint-disable-next-line max-len\n \"<Canvas onLayout={onLayout} /> is not supported on the new architecture, to fix the issue, see: https://shopify.github.io/react-native-skia/docs/canvas/overview/#getting-the-canvas-size\"\n );\n }\n const viewRef = useRef<View>(null);\n // Native ID\n const nativeId = useMemo(() => {\n return SkiaViewNativeId.current++;\n }, []);\n\n // Root\n const root = useMemo(\n () => new SkiaSGRoot(Skia, nativeId, onSize),\n [nativeId, onSize]\n );\n\n // Render effects\n useLayoutEffect(() => {\n root.render(children);\n }, [children, root, nativeId]);\n\n useEffect(() => {\n return () => {\n root.unmount();\n };\n }, [root]);\n\n // Component methods\n useImperativeHandle(\n ref,\n () =>\n ({\n makeImageSnapshot: (rect?: SkRect) => {\n return SkiaViewApi.makeImageSnapshot(nativeId, rect);\n },\n makeImageSnapshotAsync: (rect?: SkRect) => {\n return SkiaViewApi.makeImageSnapshotAsync(nativeId, rect);\n },\n redraw: () => {\n SkiaViewApi.requestRedraw(nativeId);\n },\n getNativeId: () => {\n return nativeId;\n },\n measure: (callback) => {\n viewRef.current?.measure(callback);\n },\n measureInWindow: (callback) => {\n viewRef.current?.measureInWindow(callback);\n },\n } as CanvasRef)\n );\n\n const onLayoutWeb = useCallback(\n (e: LayoutChangeEvent) => {\n if (onLayout) {\n onLayout(e);\n }\n if (Platform.OS === \"web\" && onSize) {\n const { width, height } = e.nativeEvent.layout;\n onSize.value = { width, height };\n }\n },\n [onLayout, onSize]\n );\n\n return (\n <SkiaPictureViewNativeComponent\n ref={viewRef}\n collapsable={false}\n nativeID={`${nativeId}`}\n debug={debug}\n opaque={opaque}\n colorSpace={colorSpace}\n onLayout={onLayoutWeb}\n {...viewProps}\n />\n );\n};\n"],"mappings":";;AACA,OAAOA,KAAK,IACVC,WAAW,EACXC,SAAS,EACTC,mBAAmB,EACnBC,eAAe,EACfC,OAAO,EACPC,MAAM,EACNC,QAAQ,QACH,OAAO;AAUd,SAASC,gBAAgB,QAAQ,2BAA2B;AAC5D,OAAOC,8BAA8B,MAAM,yCAAyC;AAEpF,SAASC,UAAU,QAAQ,oBAAoB;AAC/C,SAASC,IAAI,QAAQ,SAAS;AAC9B,SAASC,QAAQ,QAAQ,aAAa;AAWtC,OAAO,MAAMC,YAAY,GAAGA,CAAA,KAAMP,MAAM,CAAY,IAAI,CAAC;AAEzD,OAAO,MAAMQ,aAAa,GAAIC,OAAqC,IAAK;EACtE,MAAMC,MAAM,GAAGH,YAAY,CAAC,CAAC;EAC7B,MAAMI,GAAG,GAAGF,OAAO,aAAPA,OAAO,cAAPA,OAAO,GAAIC,MAAM;EAC7B,MAAM,CAACE,IAAI,EAAEC,OAAO,CAAC,GAAGZ,QAAQ,CAAS;IAAEa,KAAK,EAAE,CAAC;IAAEC,MAAM,EAAE;EAA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AK,GAAG;QAAE1C,KAAK;QAAEC;MAAO,CAAC;IAClC;EACF,CAAC,EACD,CAACgB,QAAQ,EAAEF,MAAM,CACnB,CAAC;EAED,oBACEnC,KAAA,CAAA+D,aAAA,CAACtD,8BAA8B,EAAAuD,QAAA;IAC7B/C,GAAG,EAAEwB,OAAQ;IACbwB,WAAW,EAAE,KAAM;IACnBC,QAAQ,EAAE,GAAGxB,QAAQ,EAAG;IACxBV,KAAK,EAAEA,KAAM;IACbC,MAAM,EAAEA,MAAO;IACfG,UAAU,EAAEA,UAAW;IACvBC,QAAQ,EAAEoB;EAAY,GAClBnB,SAAS,CACd,CAAC;AAEN,CAAC","ignoreList":[]}
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import type { SharedValue } from "react-native-reanimated";
|
2
2
|
import type { Skia, SkSize } from "../skia/types";
|
3
3
|
import { StaticContainer } from "./StaticContainer";
|
4
|
-
export declare const createContainer: (Skia: Skia, nativeId: number,
|
4
|
+
export declare const createContainer: (Skia: Skia, nativeId: number, _onSize?: SharedValue<SkSize>) => StaticContainer;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { StaticContainer } from "./StaticContainer";
|
2
|
-
export const createContainer = (Skia, nativeId,
|
3
|
-
return new StaticContainer(Skia, nativeId
|
2
|
+
export const createContainer = (Skia, nativeId, _onSize) => {
|
3
|
+
return new StaticContainer(Skia, nativeId);
|
4
4
|
};
|
5
5
|
//# sourceMappingURL=Container.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["StaticContainer","createContainer","Skia","nativeId","
|
1
|
+
{"version":3,"names":["StaticContainer","createContainer","Skia","nativeId","_onSize"],"sources":["Container.ts"],"sourcesContent":["import type { SharedValue } from \"react-native-reanimated\";\n\nimport type { Skia, SkSize } from \"../skia/types\";\n\nimport { StaticContainer } from \"./StaticContainer\";\n\nexport const createContainer = (\n Skia: Skia,\n nativeId: number,\n _onSize?: SharedValue<SkSize>\n) => {\n return new StaticContainer(Skia, nativeId);\n};\n"],"mappings":"AAIA,SAASA,eAAe,QAAQ,mBAAmB;AAEnD,OAAO,MAAMC,eAAe,GAAGA,CAC7BC,IAAU,EACVC,QAAgB,EAChBC,OAA6B,KAC1B;EACH,OAAO,IAAIJ,eAAe,CAACE,IAAI,EAAEC,QAAQ,CAAC;AAC5C,CAAC","ignoreList":[]}
|
@@ -11,13 +11,10 @@ import "../views/api";
|
|
11
11
|
const nativeDrawOnscreen = (nativeId, recorder, onSize) => {
|
12
12
|
"worklet";
|
13
13
|
|
14
|
-
//const start = performance.now();
|
15
14
|
if (onSize) {
|
16
|
-
|
17
|
-
if (size.width !== onSize.value.width || size.height !== onSize.value.height) {
|
18
|
-
onSize.value = size;
|
19
|
-
}
|
15
|
+
SkiaViewApi.setJsiProperty(nativeId, "onSize", onSize);
|
20
16
|
}
|
17
|
+
//const start = performance.now();
|
21
18
|
const picture = recorder.play();
|
22
19
|
//const end = performance.now();
|
23
20
|
//console.log("Recording time: ", end - start);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["Rea","HAS_REANIMATED_3","ReanimatedRecorder","Container","StaticContainer","visit","nativeDrawOnscreen","nativeId","recorder","onSize","
|
1
|
+
{"version":3,"names":["Rea","HAS_REANIMATED_3","ReanimatedRecorder","Container","StaticContainer","visit","nativeDrawOnscreen","nativeId","recorder","onSize","SkiaViewApi","setJsiProperty","picture","play","NativeReanimatedContainer","constructor","Skia","_defineProperty","redraw","mapperId","stopMapper","unmounted","root","sharedValues","getSharedValues","sharedRecorder","getRecorder","runOnUI","length","startMapper","applyUpdates","createContainer"],"sources":["Container.native.ts"],"sourcesContent":["import type { SharedValue } from \"react-native-reanimated\";\n\nimport Rea from \"../external/reanimated/ReanimatedProxy\";\nimport type { Skia, SkSize } from \"../skia/types\";\nimport { HAS_REANIMATED_3 } from \"../external/reanimated/renderHelpers\";\nimport type { JsiRecorder } from \"../skia/types/Recorder\";\n\nimport { ReanimatedRecorder } from \"./Recorder/ReanimatedRecorder\";\nimport { Container, StaticContainer } from \"./StaticContainer\";\nimport { visit } from \"./Recorder/Visitor\";\n\nimport \"../skia/NativeSetup\";\nimport \"../views/api\";\n\nconst nativeDrawOnscreen = (\n nativeId: number,\n recorder: JsiRecorder,\n onSize?: SharedValue<SkSize>\n) => {\n \"worklet\";\n if (onSize) {\n SkiaViewApi.setJsiProperty(nativeId, \"onSize\", onSize);\n }\n //const start = performance.now();\n const picture = recorder.play();\n //const end = performance.now();\n //console.log(\"Recording time: \", end - start);\n SkiaViewApi.setJsiProperty(nativeId, \"picture\", picture);\n};\n\nclass NativeReanimatedContainer extends Container {\n private mapperId: number | null = null;\n\n constructor(\n Skia: Skia,\n private nativeId: number,\n private onSize?: SharedValue<SkSize>\n ) {\n super(Skia);\n }\n\n redraw() {\n if (this.mapperId !== null) {\n Rea.stopMapper(this.mapperId);\n }\n if (this.unmounted) {\n return;\n }\n const { nativeId, Skia } = this;\n const recorder = new ReanimatedRecorder(Skia);\n visit(recorder, this.root);\n const sharedValues = recorder.getSharedValues();\n const sharedRecorder = recorder.getRecorder();\n Rea.runOnUI((onSize?: SharedValue<SkSize>) => {\n \"worklet\";\n nativeDrawOnscreen(nativeId, sharedRecorder, onSize);\n })(this.onSize);\n if (sharedValues.length > 0) {\n const { onSize } = this;\n this.mapperId = Rea.startMapper(() => {\n \"worklet\";\n sharedRecorder.applyUpdates(sharedValues);\n nativeDrawOnscreen(nativeId, sharedRecorder, onSize);\n }, sharedValues);\n }\n }\n}\n\nexport const createContainer = (\n Skia: Skia,\n nativeId: number,\n onSize?: SharedValue<SkSize>\n) => {\n if (HAS_REANIMATED_3 && nativeId !== -1) {\n return new NativeReanimatedContainer(Skia, nativeId, onSize);\n } else {\n return new StaticContainer(Skia, nativeId);\n }\n};\n"],"mappings":";;;AAEA,OAAOA,GAAG,MAAM,wCAAwC;AAExD,SAASC,gBAAgB,QAAQ,sCAAsC;AAGvE,SAASC,kBAAkB,QAAQ,+BAA+B;AAClE,SAASC,SAAS,EAAEC,eAAe,Q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AkB,CAACC,QAAQ,EAAEkB,cAAc,EAAEhB,MAAM,CAAC;IACtD,CAAC,CAAC,CAAC,IAAI,CAACA,MAAM,CAAC;IACf,IAAIc,YAAY,CAACK,MAAM,GAAG,CAAC,EAAE;MAC3B,MAAM;QAAEnB;MAAO,CAAC,GAAG,IAAI;MACvB,IAAI,CAACU,QAAQ,GAAGnB,GAAG,CAAC6B,WAAW,CAAC,MAAM;QACpC,SAAS;;QACTJ,cAAc,CAACK,YAAY,CAACP,YAAY,CAAC;QACzCjB,kBAAkB,CAACC,QAAQ,EAAEkB,cAAc,EAAEhB,MAAM,CAAC;MACtD,CAAC,EAAEc,YAAY,CAAC;IAClB;EACF;AACF;AAEA,OAAO,MAAMQ,eAAe,GAAGA,CAC7Bf,IAAU,EACVT,QAAgB,EAChBE,MAA4B,KACzB;EACH,IAAIR,gBAAgB,IAAIM,QAAQ,KAAK,CAAC,CAAC,EAAE;IACvC,OAAO,IAAIO,yBAAyB,CAACE,IAAI,EAAET,QAAQ,EAAEE,MAAM,CAAC;EAC9D,CAAC,MAAM;IACL,OAAO,IAAIL,eAAe,CAACY,IAAI,EAAET,QAAQ,CAAC;EAC5C;AACF,CAAC","ignoreList":[]}
|
@@ -5,10 +5,9 @@ import "../skia/NativeSetup";
|
|
5
5
|
import "../views/api";
|
6
6
|
declare class ReanimatedContainer extends Container {
|
7
7
|
private nativeId;
|
8
|
-
private onSize?;
|
9
8
|
private mapperId;
|
10
|
-
constructor(Skia: Skia, nativeId: number
|
9
|
+
constructor(Skia: Skia, nativeId: number);
|
11
10
|
redraw(): void;
|
12
11
|
}
|
13
|
-
export declare const createContainer: (Skia: Skia, nativeId: number,
|
12
|
+
export declare const createContainer: (Skia: Skia, nativeId: number, _onSize?: SharedValue<SkSize>) => StaticContainer | ReanimatedContainer;
|
14
13
|
export {};
|
@@ -10,15 +10,9 @@ import { createDrawingContext } from "./Recorder/DrawingContext";
|
|
10
10
|
import { Container, StaticContainer } from "./StaticContainer";
|
11
11
|
import "../skia/NativeSetup";
|
12
12
|
import "../views/api";
|
13
|
-
const drawOnscreen = (Skia, nativeId, recording
|
13
|
+
const drawOnscreen = (Skia, nativeId, recording) => {
|
14
14
|
"worklet";
|
15
15
|
|
16
|
-
if (onSize) {
|
17
|
-
const size = SkiaViewApi.size(nativeId);
|
18
|
-
if (size.width !== onSize.value.width || size.height !== onSize.value.height) {
|
19
|
-
onSize.value = size;
|
20
|
-
}
|
21
|
-
}
|
22
16
|
const rec = Skia.PictureRecorder();
|
23
17
|
const canvas = rec.beginRecording();
|
24
18
|
//const start = performance.now();
|
@@ -31,10 +25,9 @@ const drawOnscreen = (Skia, nativeId, recording, onSize) => {
|
|
31
25
|
SkiaViewApi.setJsiProperty(nativeId, "picture", picture);
|
32
26
|
};
|
33
27
|
class ReanimatedContainer extends Container {
|
34
|
-
constructor(Skia, nativeId
|
28
|
+
constructor(Skia, nativeId) {
|
35
29
|
super(Skia);
|
36
30
|
this.nativeId = nativeId;
|
37
|
-
this.onSize = onSize;
|
38
31
|
_defineProperty(this, "mapperId", null);
|
39
32
|
}
|
40
33
|
redraw() {
|
@@ -66,16 +59,16 @@ class ReanimatedContainer extends Container {
|
|
66
59
|
drawOnscreen(Skia, nativeId, recording);
|
67
60
|
}, Array.from(animationValues));
|
68
61
|
}
|
69
|
-
Rea.runOnUI(
|
62
|
+
Rea.runOnUI(() => {
|
70
63
|
"worklet";
|
71
64
|
|
72
|
-
drawOnscreen(Skia, nativeId, recording
|
73
|
-
})(
|
65
|
+
drawOnscreen(Skia, nativeId, recording);
|
66
|
+
})();
|
74
67
|
}
|
75
68
|
}
|
76
|
-
export const createContainer = (Skia, nativeId,
|
69
|
+
export const createContainer = (Skia, nativeId, _onSize) => {
|
77
70
|
if (HAS_REANIMATED_3 && nativeId !== -1) {
|
78
|
-
return new ReanimatedContainer(Skia, nativeId
|
71
|
+
return new ReanimatedContainer(Skia, nativeId);
|
79
72
|
} else {
|
80
73
|
return new StaticContainer(Skia, nativeId);
|
81
74
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["Rea","HAS_REANIMATED_3","Recorder","visit","replay","createDrawingContext","Container","StaticContainer","drawOnscreen","Skia","nativeId","recording","
|
1
|
+
{"version":3,"names":["Rea","HAS_REANIMATED_3","Recorder","visit","replay","createDrawingContext","Container","StaticContainer","drawOnscreen","Skia","nativeId","recording","rec","PictureRecorder","canvas","beginRecording","ctx","paintPool","commands","picture","finishRecordingAsPicture","SkiaViewApi","setJsiProperty","ReanimatedContainer","constructor","_defineProperty","redraw","mapperId","stopMapper","unmounted","recorder","root","record","getRecording","animationValues","size","startMapper","Array","from","runOnUI","createContainer","_onSize"],"sources":["Container.web.ts"],"sourcesContent":["import type { SharedValue } from \"react-native-reanimated\";\n\nimport Rea from \"../external/reanimated/ReanimatedProxy\";\nimport type { Skia, SkSize } from \"../skia/types\";\nimport { HAS_REANIMATED_3 } from \"../external/reanimated/renderHelpers\";\n\nimport type { Recording } from \"./Recorder/Recorder\";\nimport { Recorder } from \"./Recorder/Recorder\";\nimport { visit } from \"./Recorder/Visitor\";\nimport { replay } from \"./Recorder/Player\";\nimport { createDrawingContext } from \"./Recorder/DrawingContext\";\nimport { Container, StaticContainer } from \"./StaticContainer\";\n\nimport \"../skia/NativeSetup\";\nimport \"../views/api\";\n\nconst drawOnscreen = (Skia: Skia, nativeId: number, recording: Recording) => {\n \"worklet\";\n const rec = Skia.PictureRecorder();\n const canvas = rec.beginRecording();\n //const start = performance.now();\n\n const ctx = createDrawingContext(Skia, recording.paintPool, canvas);\n replay(ctx, recording.commands);\n const picture = rec.finishRecordingAsPicture();\n //const end = performance.now();\n //console.log(\"Recording time: \", end - start);\n SkiaViewApi.setJsiProperty(nativeId, \"picture\", picture);\n};\n\nclass ReanimatedContainer extends Container {\n private mapperId: number | null = null;\n\n constructor(Skia: Skia, private nativeId: number) {\n super(Skia);\n }\n\n redraw() {\n if (this.mapperId !== null) {\n Rea.stopMapper(this.mapperId);\n }\n if (this.unmounted) {\n return;\n }\n const recorder = new Recorder();\n visit(recorder, this.root);\n const record = recorder.getRecording();\n const { animationValues } = record;\n this.recording = {\n commands: record.commands,\n paintPool: record.paintPool,\n };\n const { nativeId, Skia, recording } = this;\n if (animationValues.size > 0) {\n this.mapperId = Rea.startMapper(() => {\n \"worklet\";\n drawOnscreen(Skia, nativeId, recording!);\n }, Array.from(animationValues));\n }\n Rea.runOnUI(() => {\n \"worklet\";\n drawOnscreen(Skia, nativeId, recording!);\n })();\n }\n}\n\nexport const createContainer = (\n Skia: Skia,\n nativeId: number,\n _onSize?: SharedValue<SkSize>\n) => {\n if (HAS_REANIMATED_3 && nativeId !== -1) {\n return new ReanimatedContainer(Skia, nativeId);\n } else {\n return new StaticContainer(Skia, nativeId);\n }\n};\n"],"mappings":";;;AAEA,OAAOA,GAAG,MAAM,wCAAwC;AAExD,SAASC,gBAAgB,QAAQ,sCAAsC;AAGvE,SAASC,QAAQ,QAAQ,qBAAqB;AAC9C,SAASC,KAAK,QAAQ,oBAAoB;AAC1C,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,oBAAoB,QAAQ,2BAA2B;AAChE,SAASC,SAAS,EAAEC,eAAe,QAAQ,mBAAmB;AAE9D,OAAO,qBAAqB;AAC5B,OAAO,cAAc;AAErB,MAAMC,YAAY,GAAGA,CAACC,IAAU,EAAEC,QAAgB,EAAEC,SAAoB,KAAK;EAC3E,SAAS;;EACT,MAAMC,GAAG,GAAGH,IAAI,CAACI,eAAe,CAAC,CAAC;EAClC,MAAMC,MAAM,GAAGF,GAAG,CAACG,cAAc,CAAC,CAAC;EACnC;;EAEA,MAAMC,GAAG,GAAGX,oBAAoB,CAACI,IAAI,EAAEE,SAAS,CAACM,SAAS,EAAEH,MAAM,CAAC;EACnEV,MAAM,CAACY,GAAG,EAAEL,SAAS,CAACO,QAAQ,CAAC;EAC/B,MAAMC,OAAO,GAAGP,GAAG,CAACQ,wBAAwB,CAAC,CAAC;EAC9C;EACA;EACAC,WAAW,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,CAAC,CAAC,CAAC;EACN;AACF;AAEA,OAAO,MAAM6B,eAAe,GAAGA,CAC7B/B,IAAU,EACVC,QAAgB,EAChB+B,OAA6B,KAC1B;EACH,IAAIxC,gBAAgB,IAAIS,QAAQ,KAAK,CAAC,CAAC,EAAE;IACvC,OAAO,IAAIa,mBAAmB,CAACd,IAAI,EAAEC,QAAQ,CAAC;EAChD,CAAC,MAAM;IACL,OAAO,IAAIH,eAAe,CAACE,IAAI,EAAEC,QAAQ,CAAC;EAC5C;AACF,CAAC","ignoreList":[]}
|
@@ -1,5 +1,4 @@
|
|
1
|
-
import type {
|
2
|
-
import type { Skia, SkCanvas, SkSize } from "../skia/types";
|
1
|
+
import type { Skia, SkCanvas } from "../skia/types";
|
3
2
|
import type { Node } from "./Node";
|
4
3
|
import type { Recording } from "./Recorder/Recorder";
|
5
4
|
import "../views/api";
|
@@ -18,7 +17,6 @@ export declare abstract class Container {
|
|
18
17
|
}
|
19
18
|
export declare class StaticContainer extends Container {
|
20
19
|
private nativeId;
|
21
|
-
|
22
|
-
constructor(Skia: Skia, nativeId: number, onSize?: SharedValue<SkSize> | undefined);
|
20
|
+
constructor(Skia: Skia, nativeId: number);
|
23
21
|
redraw(): void;
|
24
22
|
}
|
@@ -34,10 +34,9 @@ export class Container {
|
|
34
34
|
}
|
35
35
|
}
|
36
36
|
export class StaticContainer extends Container {
|
37
|
-
constructor(Skia, nativeId
|
37
|
+
constructor(Skia, nativeId) {
|
38
38
|
super(Skia);
|
39
39
|
this.nativeId = nativeId;
|
40
|
-
this.onSize = onSize;
|
41
40
|
}
|
42
41
|
redraw() {
|
43
42
|
const recorder = new Recorder();
|
@@ -45,12 +44,6 @@ export class StaticContainer extends Container {
|
|
45
44
|
this.recording = recorder.getRecording();
|
46
45
|
const isOnScreen = this.nativeId !== -1;
|
47
46
|
if (isOnScreen) {
|
48
|
-
if (this.onSize) {
|
49
|
-
const size = SkiaViewApi.size(this.nativeId);
|
50
|
-
if (size.width !== this.onSize.value.width || size.height !== this.onSize.value.height) {
|
51
|
-
this.onSize.value = size;
|
52
|
-
}
|
53
|
-
}
|
54
47
|
const rec = this.Skia.PictureRecorder();
|
55
48
|
const canvas = rec.beginRecording();
|
56
49
|
this.drawOnCanvas(canvas);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["Recorder","visit","replay","createDrawingContext","Container","constructor","Skia","_defineProperty","root","_root","value","mount","unmounted","unmount","drawOnCanvas","canvas","recording","Error","ctx","paintPool","commands","StaticContainer","nativeId","
|
1
|
+
{"version":3,"names":["Recorder","visit","replay","createDrawingContext","Container","constructor","Skia","_defineProperty","root","_root","value","mount","unmounted","unmount","drawOnCanvas","canvas","recording","Error","ctx","paintPool","commands","StaticContainer","nativeId","redraw","recorder","getRecording","isOnScreen","rec","PictureRecorder","beginRecording","picture","finishRecordingAsPicture","SkiaViewApi","setJsiProperty"],"sources":["StaticContainer.ts"],"sourcesContent":["import type { Skia, SkCanvas } from \"../skia/types\";\n\nimport type { Node } from \"./Node\";\nimport type { Recording } from \"./Recorder/Recorder\";\nimport { Recorder } from \"./Recorder/Recorder\";\nimport { visit } from \"./Recorder/Visitor\";\nimport { replay } from \"./Recorder/Player\";\nimport { createDrawingContext } from \"./Recorder/DrawingContext\";\n\nimport \"../views/api\";\n\nexport abstract class Container {\n private _root: Node[] = [];\n protected recording: Recording | null = null;\n protected unmounted = false;\n\n constructor(protected Skia: Skia) {}\n\n get root() {\n return this._root;\n }\n\n set root(value: Node[]) {\n this._root = value;\n }\n\n mount() {\n this.unmounted = false;\n }\n\n unmount() {\n this.unmounted = true;\n }\n\n drawOnCanvas(canvas: SkCanvas) {\n if (!this.recording) {\n throw new Error(\"No recording to draw\");\n }\n const ctx = createDrawingContext(\n this.Skia,\n this.recording.paintPool,\n canvas\n );\n replay(ctx, this.recording.commands);\n }\n\n abstract redraw(): void;\n}\n\nexport class StaticContainer extends Container {\n constructor(Skia: Skia, private nativeId: number) {\n super(Skia);\n }\n\n redraw() {\n const recorder = new Recorder();\n visit(recorder, this.root);\n this.recording = recorder.getRecording();\n const isOnScreen = this.nativeId !== -1;\n if (isOnScreen) {\n const rec = this.Skia.PictureRecorder();\n const canvas = rec.beginRecording();\n this.drawOnCanvas(canvas);\n const picture = rec.finishRecordingAsPicture();\n SkiaViewApi.setJsiProperty(this.nativeId, \"picture\", picture);\n }\n }\n}\n"],"mappings":";;;AAIA,SAASA,QAAQ,QAAQ,qBAAqB;AAC9C,SAASC,KAAK,QAAQ,oBAAoB;AAC1C,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,oBAAoB,QAAQ,2BAA2B;AAEhE,OAAO,cAAc;AAErB,OAAO,MAAeC,SAAS,CAAC;EAK9BC,WAAWA,CAAWC,IAAU,EAAE;IAAA,KAAZA,IAAU,GAAVA,IAAU;IAAAC,eAAA,gBAJR,EAAE;IAAAA,eAAA,oBACc,IAAI;IAAAA,eAAA,oBACtB,KAAK;EAEQ;EAEnC,IAAIC,IAAIA,CAAA,EAAG;IACT,OAAO,IAAI,CAACC,KAAK;EACnB;EAEA,IAAID,IAAIA,CAACE,KAAa,EAAE;IACtB,IAAI,CAACD,KAAK,GAAGC,KAAK;EACpB;EAEAC,KAAKA,CAAA,EAAG;IACN,IAAI,CAACC,SAAS,GAAG,KAAK;EACxB;EAEAC,OAAOA,CAAA,EAAG;IACR,IAAI,CAACD,SAAS,GAAG,IAAI;EACvB;EAEAE,YAAYA,CAACC,MAAgB,EAAE;IAC7B,IAAI,CAAC,IAAI,CAACC,SAAS,EAAE;MACnB,MAAM,IAAIC,KAAK,CAAC,sBAAsB,CAAC;IACzC;IACA,MAAMC,GAAG,GAAGf,oBAAoB,CAC9B,IAAI,CAACG,IAAI,EACT,IAAI,CAACU,SAAS,CAACG,SAAS,EACxBJ,MACF,CAAC;IACDb,MAAM,CAACgB,GAAG,EAAE,IAAI,CAACF,SAAS,CAACI,QAAQ,CAAC;EACtC;AAGF;AAEA,OAAO,MAAMC,eAAe,SAASjB,SAAS,CAAC;EAC7CC,WAAWA,CAACC,IAAU,EAAUgB,QAAgB,EAAE;IAChD,KAAK,CAAChB,IAAI,CAAC;IAAC,KADkBgB,QAAgB,GAAhBA,QAAgB;EAEhD;EAEAC,MAAMA,CAAA,EAAG;IACP,MAAMC,QAAQ,GAAG,IAAIxB,QAAQ,CAAC,CAAC;IAC/BC,KAAK,CAACuB,QAAQ,EAAE,IAAI,CAAChB,IAAI,CAAC;IAC1B,IAAI,CAACQ,SAAS,GAAGQ,QAAQ,CAACC,YAAY,CAAC,CAAC;IACxC,MAAMC,UAAU,GAAG,IAAI,CAACJ,QAAQ,KAAK,CAAC,CAAC;IACvC,IAAII,UAAU,EAAE;MACd,MAAMC,GAAG,GAAG,IAAI,CAACrB,IAAI,CAACsB,eAAe,CAAC,CAAC;MACvC,MAAMb,MAAM,GAAGY,GAAG,CAACE,cAAc,CAAC,CAAC;MACnC,IAAI,CAACf,YAAY,CAACC,MAAM,CAAC;MACzB,MAAMe,OAAO,GAAGH,GAAG,CAACI,wBAAwB,CAAC,CAAC;MAC9CC,WAAW,CAACC,cAAc,CAAC,IAAI,CAACX,QAAQ,EAAE,SAAS,EAAEQ,OAAO,CAAC;IAC/D;EACF;AACF","ignoreList":[]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["global","SkiaViewApi","views","deferedPictures","web","registerView","nativeId","view","setPicture","setJsiProperty","name","value","size","getSize","width","height","requestRedraw","redraw","makeImageSnapshot","rect","makeImageSnapshotAsync","Promise","resolve","reject","result","Error"],"sources":["NativeSkiaModule.web.ts"],"sourcesContent":["/* eslint-disable import/no-anonymous-default-export */\nimport type { SkPicture, SkRect } from \"../skia/types\";\nimport type { ISkiaViewApi } from \"../views/types\";\nimport type { SkiaPictureViewHandle } from \"../views/SkiaPictureView.web\";\n\nexport type ISkiaViewApiWeb = ISkiaViewApi & {\n views: Record<string, SkiaPictureViewHandle>;\n deferedPictures: Record<string, SkPicture>;\n registerView(nativeId: string, view: SkiaPictureViewHandle): void;\n};\n\nglobal.SkiaViewApi = {\n views: {},\n deferedPictures: {},\n web: true,\n registerView(nativeId: string, view: SkiaPictureViewHandle) {\n // Maybe a picture for this view was already set\n if (this.deferedPictures[nativeId]) {\n view.setPicture(this.deferedPictures[nativeId] as SkPicture);\n }\n this.views[nativeId] = view;\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n setJsiProperty(nativeId: number, name: string, value: any) {\n if (name === \"picture\") {\n if (!this.views[`${nativeId}`]) {\n this.deferedPictures[`${nativeId}`] = value;\n } else {\n this.views[`${nativeId}`].setPicture(value);\n }\n }\n },\n size(nativeId: number) {\n if (this.views[`${nativeId}`]) {\n return this.views[`${nativeId}`].getSize();\n } else {\n return { width: 0, height: 0 };\n }\n },\n requestRedraw(nativeId: number) {\n this.views[`${nativeId}`].redraw();\n },\n makeImageSnapshot(nativeId: number, rect?: SkRect) {\n return this.views[`${nativeId}`].makeImageSnapshot(rect);\n },\n makeImageSnapshotAsync(nativeId: number, rect?: SkRect) {\n return new Promise((resolve, reject) => {\n const result = this.views[`${nativeId}`].makeImageSnapshot(rect);\n if (result) {\n resolve(result);\n } else {\n reject(new Error(\"Failed to make image snapshot\"));\n }\n });\n },\n} as ISkiaViewApiWeb;\n\n// eslint-disable-next-line import/no-default-export\nexport default {};\n"],"mappings":"AAAA;;AAWAA,MAAM,CAACC,WAAW,GAAG;EACnBC,KAAK,EAAE,CAAC,CAAC;EACTC,eAAe,EAAE,CAAC,CAAC;EACnBC,GAAG,EAAE,IAAI;EACTC,YAAYA,CAACC,QAAgB,EAAEC,IAA2B,EAAE;IAC1D;IACA,IAAI,IAAI,
|
1
|
+
{"version":3,"names":["global","SkiaViewApi","views","deferedPictures","deferedOnSize","web","registerView","nativeId","view","setPicture","setJsiProperty","name","value","size","getSize","width","height","requestRedraw","redraw","makeImageSnapshot","rect","makeImageSnapshotAsync","Promise","resolve","reject","result","Error"],"sources":["NativeSkiaModule.web.ts"],"sourcesContent":["/* eslint-disable import/no-anonymous-default-export */\nimport type { SkPicture, SkRect } from \"../skia/types\";\nimport type { ISkiaViewApi } from \"../views/types\";\nimport type { SkiaPictureViewHandle } from \"../views/SkiaPictureView.web\";\n\nexport type ISkiaViewApiWeb = ISkiaViewApi & {\n views: Record<string, SkiaPictureViewHandle>;\n deferedPictures: Record<string, SkPicture>;\n registerView(nativeId: string, view: SkiaPictureViewHandle): void;\n};\n\nglobal.SkiaViewApi = {\n views: {},\n deferedPictures: {},\n deferedOnSize: {},\n web: true,\n registerView(nativeId: string, view: SkiaPictureViewHandle) {\n // Maybe a picture for this view was already set\n if (this.deferedPictures[nativeId]) {\n view.setPicture(this.deferedPictures[nativeId] as SkPicture);\n }\n this.views[nativeId] = view;\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n setJsiProperty(nativeId: number, name: string, value: any) {\n if (name === \"picture\") {\n if (!this.views[`${nativeId}`]) {\n this.deferedPictures[`${nativeId}`] = value;\n } else {\n this.views[`${nativeId}`].setPicture(value);\n }\n }\n },\n size(nativeId: number) {\n if (this.views[`${nativeId}`]) {\n return this.views[`${nativeId}`].getSize();\n } else {\n return { width: 0, height: 0 };\n }\n },\n requestRedraw(nativeId: number) {\n this.views[`${nativeId}`].redraw();\n },\n makeImageSnapshot(nativeId: number, rect?: SkRect) {\n return this.views[`${nativeId}`].makeImageSnapshot(rect);\n },\n makeImageSnapshotAsync(nativeId: number, rect?: SkRect) {\n return new Promise((resolve, reject) => {\n const result = this.views[`${nativeId}`].makeImageSnapshot(rect);\n if (result) {\n resolve(result);\n } else {\n reject(new Error(\"Failed to make image snapshot\"));\n }\n });\n },\n} as ISkiaViewApiWeb;\n\n// eslint-disable-next-line import/no-default-export\nexport default {};\n"],"mappings":"AAAA;;AAWAA,MAAM,CAACC,WAAW,GAAG;EACnBC,KAAK,EAAE,CAAC,CAAC;EACTC,eAAe,EAAE,CAAC,CAAC;EACnBC,aAAa,EAAE,CAAC,CAAC;EACjBC,GAAG,EAAE,IAAI;EACTC,YAAYA,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,IAAa,EAAE;IACtD,OAAO,IAAIE,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;MACtC,MAAMC,MAAM,GAAG,IAAI,CAACvB,KAAK,CAAC,GAAGK,QAAQ,EAAE,CAAC,CAACY,iBAAiB,CAACC,IAAI,CAAC;MAChE,IAAIK,MAAM,EAAE;QACVF,OAAO,CAACE,MAAM,CAAC;MACjB,CAAC,MAAM;QACLD,MAAM,CAAC,IAAIE,KAAK,CAAC,+BAA+B,CAAC,CAAC;MACpD;IACF,CAAC,CAAC;EACJ;AACF,CAAoB;;AAEpB;AACA,eAAe,CAAC,CAAC","ignoreList":[]}
|
@@ -1,3 +1,3 @@
|
|
1
1
|
export const __esModule: boolean;
|
2
|
-
export function createContainer(Skia: any, nativeId: any,
|
2
|
+
export function createContainer(Skia: any, nativeId: any, _onSize: any): _StaticContainer.StaticContainer;
|
3
3
|
import _StaticContainer = require("./StaticContainer");
|
@@ -1,10 +1,9 @@
|
|
1
1
|
export const __esModule: boolean;
|
2
|
-
export function createContainer(Skia: any, nativeId: any,
|
2
|
+
export function createContainer(Skia: any, nativeId: any, _onSize: any): _StaticContainer.StaticContainer | ReanimatedContainer;
|
3
3
|
import _StaticContainer = require("./StaticContainer");
|
4
4
|
declare class ReanimatedContainer extends _StaticContainer.Container {
|
5
|
-
constructor(Skia: any, nativeId: any
|
5
|
+
constructor(Skia: any, nativeId: any);
|
6
6
|
nativeId: any;
|
7
|
-
onSize: any;
|
8
7
|
redraw(): void;
|
9
8
|
recording: {
|
10
9
|
commands: any;
|
@@ -11,9 +11,8 @@ export class Container {
|
|
11
11
|
drawOnCanvas(canvas: any): void;
|
12
12
|
}
|
13
13
|
export class StaticContainer extends Container {
|
14
|
-
constructor(Skia: any, nativeId: any
|
14
|
+
constructor(Skia: any, nativeId: any);
|
15
15
|
nativeId: any;
|
16
|
-
onSize: any;
|
17
16
|
redraw(): void;
|
18
17
|
recording: {
|
19
18
|
commands: any;
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export function createContainer(Skia: any, nativeId: any,
|
1
|
+
export function createContainer(Skia: any, nativeId: any, _onSize: any): StaticContainer;
|
2
2
|
import { StaticContainer } from "./StaticContainer";
|
@@ -1,9 +1,8 @@
|
|
1
|
-
export function createContainer(Skia: any, nativeId: any,
|
1
|
+
export function createContainer(Skia: any, nativeId: any, _onSize: any): StaticContainer | ReanimatedContainer;
|
2
2
|
import { StaticContainer } from "./StaticContainer";
|
3
3
|
declare class ReanimatedContainer extends Container {
|
4
|
-
constructor(Skia: any, nativeId: any
|
4
|
+
constructor(Skia: any, nativeId: any);
|
5
5
|
nativeId: any;
|
6
|
-
onSize: any;
|
7
6
|
redraw(): void;
|
8
7
|
recording: {
|
9
8
|
commands: any;
|
@@ -10,9 +10,8 @@ export class Container {
|
|
10
10
|
drawOnCanvas(canvas: any): void;
|
11
11
|
}
|
12
12
|
export class StaticContainer extends Container {
|
13
|
-
constructor(Skia: any, nativeId: any
|
13
|
+
constructor(Skia: any, nativeId: any);
|
14
14
|
nativeId: any;
|
15
|
-
onSize: any;
|
16
15
|
redraw(): void;
|
17
16
|
recording: {
|
18
17
|
commands: any;
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import type { SharedValue } from "react-native-reanimated";
|
2
2
|
import type { Skia, SkSize } from "../skia/types";
|
3
3
|
import { StaticContainer } from "./StaticContainer";
|
4
|
-
export declare const createContainer: (Skia: Skia, nativeId: number,
|
4
|
+
export declare const createContainer: (Skia: Skia, nativeId: number, _onSize?: SharedValue<SkSize>) => StaticContainer;
|
@@ -5,10 +5,9 @@ import "../skia/NativeSetup";
|
|
5
5
|
import "../views/api";
|
6
6
|
declare class ReanimatedContainer extends Container {
|
7
7
|
private nativeId;
|
8
|
-
private onSize?;
|
9
8
|
private mapperId;
|
10
|
-
constructor(Skia: Skia, nativeId: number
|
9
|
+
constructor(Skia: Skia, nativeId: number);
|
11
10
|
redraw(): void;
|
12
11
|
}
|
13
|
-
export declare const createContainer: (Skia: Skia, nativeId: number,
|
12
|
+
export declare const createContainer: (Skia: Skia, nativeId: number, _onSize?: SharedValue<SkSize>) => StaticContainer | ReanimatedContainer;
|
14
13
|
export {};
|
@@ -1,5 +1,4 @@
|
|
1
|
-
import type {
|
2
|
-
import type { Skia, SkCanvas, SkSize } from "../skia/types";
|
1
|
+
import type { Skia, SkCanvas } from "../skia/types";
|
3
2
|
import type { Node } from "./Node";
|
4
3
|
import type { Recording } from "./Recorder/Recorder";
|
5
4
|
import "../views/api";
|
@@ -18,7 +17,6 @@ export declare abstract class Container {
|
|
18
17
|
}
|
19
18
|
export declare class StaticContainer extends Container {
|
20
19
|
private nativeId;
|
21
|
-
|
22
|
-
constructor(Skia: Skia, nativeId: number, onSize?: SharedValue<SkSize> | undefined);
|
20
|
+
constructor(Skia: Skia, nativeId: number);
|
23
21
|
redraw(): void;
|
24
22
|
}
|
package/package.json
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
"setup-skia-web": "scripts/setup-canvaskit.js"
|
9
9
|
},
|
10
10
|
"title": "React Native Skia",
|
11
|
-
"version": "2.2.
|
11
|
+
"version": "2.2.12",
|
12
12
|
"description": "High-performance React Native Graphics using Skia",
|
13
13
|
"main": "lib/module/index.js",
|
14
14
|
"react-native": "src/index.ts",
|
package/src/renderer/Canvas.tsx
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import type { FC, RefObject } from "react";
|
2
2
|
import React, {
|
3
|
+
useCallback,
|
3
4
|
useEffect,
|
4
5
|
useImperativeHandle,
|
5
6
|
useLayoutEffect,
|
@@ -8,6 +9,7 @@ import React, {
|
|
8
9
|
useState,
|
9
10
|
} from "react";
|
10
11
|
import type {
|
12
|
+
LayoutChangeEvent,
|
11
13
|
MeasureInWindowOnSuccessCallback,
|
12
14
|
MeasureOnSuccessCallback,
|
13
15
|
View,
|
@@ -20,6 +22,7 @@ import SkiaPictureViewNativeComponent from "../specs/SkiaPictureViewNativeCompon
|
|
20
22
|
import type { SkImage, SkRect, SkSize } from "../skia/types";
|
21
23
|
import { SkiaSGRoot } from "../sksg/Reconciler";
|
22
24
|
import { Skia } from "../skia";
|
25
|
+
import { Platform } from "../Platform";
|
23
26
|
|
24
27
|
export interface CanvasRef extends FC<CanvasProps> {
|
25
28
|
makeImageSnapshot(rect?: SkRect): SkImage;
|
@@ -127,6 +130,19 @@ export const Canvas = ({
|
|
127
130
|
} as CanvasRef)
|
128
131
|
);
|
129
132
|
|
133
|
+
const onLayoutWeb = useCallback(
|
134
|
+
(e: LayoutChangeEvent) => {
|
135
|
+
if (onLayout) {
|
136
|
+
onLayout(e);
|
137
|
+
}
|
138
|
+
if (Platform.OS === "web" && onSize) {
|
139
|
+
const { width, height } = e.nativeEvent.layout;
|
140
|
+
onSize.value = { width, height };
|
141
|
+
}
|
142
|
+
},
|
143
|
+
[onLayout, onSize]
|
144
|
+
);
|
145
|
+
|
130
146
|
return (
|
131
147
|
<SkiaPictureViewNativeComponent
|
132
148
|
ref={viewRef}
|
@@ -135,6 +151,7 @@ export const Canvas = ({
|
|
135
151
|
debug={debug}
|
136
152
|
opaque={opaque}
|
137
153
|
colorSpace={colorSpace}
|
154
|
+
onLayout={onLayoutWeb}
|
138
155
|
{...viewProps}
|
139
156
|
/>
|
140
157
|
);
|
@@ -18,17 +18,10 @@ const nativeDrawOnscreen = (
|
|
18
18
|
onSize?: SharedValue<SkSize>
|
19
19
|
) => {
|
20
20
|
"worklet";
|
21
|
-
|
22
|
-
//const start = performance.now();
|
23
21
|
if (onSize) {
|
24
|
-
|
25
|
-
if (
|
26
|
-
size.width !== onSize.value.width ||
|
27
|
-
size.height !== onSize.value.height
|
28
|
-
) {
|
29
|
-
onSize.value = size;
|
30
|
-
}
|
22
|
+
SkiaViewApi.setJsiProperty(nativeId, "onSize", onSize);
|
31
23
|
}
|
24
|
+
//const start = performance.now();
|
32
25
|
const picture = recorder.play();
|
33
26
|
//const end = performance.now();
|
34
27
|
//console.log("Recording time: ", end - start);
|
package/src/sksg/Container.ts
CHANGED
@@ -7,7 +7,7 @@ import { StaticContainer } from "./StaticContainer";
|
|
7
7
|
export const createContainer = (
|
8
8
|
Skia: Skia,
|
9
9
|
nativeId: number,
|
10
|
-
|
10
|
+
_onSize?: SharedValue<SkSize>
|
11
11
|
) => {
|
12
|
-
return new StaticContainer(Skia, nativeId
|
12
|
+
return new StaticContainer(Skia, nativeId);
|
13
13
|
};
|