@shopify/react-native-skia 1.5.7 → 1.5.9
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/android/CMakeLists.txt +1 -2
- package/android/cpp/jni/JniPlatformContext.cpp +0 -49
- package/android/cpp/jni/include/JniPlatformContext.h +1 -17
- package/android/cpp/jni/include/JniSkiaBaseView.h +0 -2
- package/android/cpp/jni/include/JniSkiaDomView.h +0 -3
- package/android/cpp/jni/include/JniSkiaManager.h +0 -2
- package/android/cpp/jni/include/JniSkiaPictureView.h +0 -3
- package/android/cpp/rnskia-android/MainThreadDispatcher.h +69 -0
- package/android/cpp/rnskia-android/OpenGLContext.h +3 -1
- package/android/cpp/rnskia-android/OpenGLWindowContext.cpp +1 -1
- package/android/cpp/rnskia-android/OpenGLWindowContext.h +4 -5
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +10 -11
- package/android/cpp/rnskia-android/RNSkAndroidView.h +3 -13
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +0 -1
- package/android/src/main/java/com/shopify/reactnative/skia/PlatformContext.java +0 -85
- package/android/src/main/java/com/shopify/reactnative/skia/RNSkiaModule.java +1 -21
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaManager.java +0 -4
- package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaDomViewManagerDelegate.java +1 -4
- package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaDomViewManagerInterface.java +0 -1
- package/cpp/api/JsiSkImage.h +20 -4
- package/cpp/rnskia/RNSkManager.cpp +2 -3
- package/cpp/rnskia/RNSkPlatformContext.h +6 -114
- package/cpp/rnskia/RNSkView.h +21 -77
- package/ios/RNSkia-iOS/MetalContext.h +2 -0
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +4 -10
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +6 -16
- package/ios/RNSkia-iOS/SkiaDomView.mm +0 -1
- package/ios/RNSkia-iOS/SkiaDomViewManager.mm +0 -6
- package/ios/RNSkia-iOS/SkiaPictureView.mm +0 -1
- package/ios/RNSkia-iOS/SkiaPictureViewManager.mm +0 -6
- package/ios/RNSkia-iOS/SkiaUIView.h +0 -1
- package/ios/RNSkia-iOS/SkiaUIView.mm +1 -14
- package/lib/commonjs/renderer/Canvas.d.ts +1 -0
- package/lib/commonjs/renderer/Canvas.js +5 -5
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.d.ts +0 -1
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js.map +1 -1
- package/lib/commonjs/views/SkiaBaseWebView.d.ts +1 -12
- package/lib/commonjs/views/SkiaBaseWebView.js +1 -19
- package/lib/commonjs/views/SkiaBaseWebView.js.map +1 -1
- package/lib/commonjs/views/SkiaDomView.d.ts +8 -1
- package/lib/commonjs/views/SkiaDomView.js +14 -2
- package/lib/commonjs/views/SkiaDomView.js.map +1 -1
- package/lib/commonjs/views/SkiaDomView.web.d.ts +3 -3
- package/lib/commonjs/views/SkiaDomView.web.js.map +1 -1
- package/lib/commonjs/views/SkiaJSDomView.d.ts +12 -6
- package/lib/commonjs/views/SkiaJSDomView.js +12 -3
- package/lib/commonjs/views/SkiaJSDomView.js.map +1 -1
- package/lib/commonjs/views/SkiaPictureView.d.ts +8 -1
- package/lib/commonjs/views/SkiaPictureView.js +14 -1
- package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
- package/lib/commonjs/views/SkiaPictureView.web.d.ts +3 -3
- package/lib/commonjs/views/SkiaPictureView.web.js.map +1 -1
- package/lib/commonjs/views/types.d.ts +2 -12
- package/lib/commonjs/views/types.js.map +1 -1
- package/lib/module/renderer/Canvas.d.ts +1 -0
- package/lib/module/renderer/Canvas.js +5 -5
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/specs/SkiaPictureViewNativeComponent.d.ts +0 -1
- package/lib/module/specs/SkiaPictureViewNativeComponent.js.map +1 -1
- package/lib/module/views/SkiaBaseWebView.d.ts +1 -12
- package/lib/module/views/SkiaBaseWebView.js +1 -19
- package/lib/module/views/SkiaBaseWebView.js.map +1 -1
- package/lib/module/views/SkiaDomView.d.ts +8 -1
- package/lib/module/views/SkiaDomView.js +14 -2
- package/lib/module/views/SkiaDomView.js.map +1 -1
- package/lib/module/views/SkiaDomView.web.d.ts +3 -3
- package/lib/module/views/SkiaDomView.web.js.map +1 -1
- package/lib/module/views/SkiaJSDomView.d.ts +12 -6
- package/lib/module/views/SkiaJSDomView.js +12 -3
- package/lib/module/views/SkiaJSDomView.js.map +1 -1
- package/lib/module/views/SkiaPictureView.d.ts +8 -1
- package/lib/module/views/SkiaPictureView.js +14 -1
- package/lib/module/views/SkiaPictureView.js.map +1 -1
- package/lib/module/views/SkiaPictureView.web.d.ts +3 -3
- package/lib/module/views/SkiaPictureView.web.js.map +1 -1
- package/lib/module/views/types.d.ts +2 -12
- package/lib/module/views/types.js.map +1 -1
- package/lib/typescript/lib/commonjs/views/SkiaBaseWebView.d.ts +0 -11
- package/lib/typescript/lib/commonjs/views/SkiaDomView.d.ts +3 -0
- package/lib/typescript/lib/commonjs/views/SkiaJSDomView.d.ts +2 -0
- package/lib/typescript/lib/commonjs/views/SkiaPictureView.d.ts +3 -0
- package/lib/typescript/lib/module/views/SkiaBaseWebView.d.ts +0 -11
- package/lib/typescript/lib/module/views/SkiaDomView.d.ts +3 -0
- package/lib/typescript/lib/module/views/SkiaJSDomView.d.ts +2 -0
- package/lib/typescript/lib/module/views/SkiaPictureView.d.ts +3 -0
- package/lib/typescript/src/renderer/Canvas.d.ts +1 -0
- package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.d.ts +0 -1
- package/lib/typescript/src/views/SkiaBaseWebView.d.ts +1 -12
- package/lib/typescript/src/views/SkiaDomView.d.ts +8 -1
- package/lib/typescript/src/views/SkiaDomView.web.d.ts +3 -3
- package/lib/typescript/src/views/SkiaJSDomView.d.ts +12 -6
- package/lib/typescript/src/views/SkiaPictureView.d.ts +8 -1
- package/lib/typescript/src/views/SkiaPictureView.web.d.ts +3 -3
- package/lib/typescript/src/views/types.d.ts +2 -12
- package/package.json +1 -1
- package/react-native-skia.podspec +2 -2
- package/src/renderer/Canvas.tsx +4 -3
- package/src/renderer/__tests__/e2e/Image.spec.tsx +2 -64
- package/src/skia/__tests__/assets/oslo-mini.jpg +0 -0
- package/src/specs/SkiaPictureViewNativeComponent.ts +0 -1
- package/src/views/SkiaBaseWebView.tsx +3 -19
- package/src/views/SkiaDomView.tsx +23 -4
- package/src/views/SkiaDomView.web.tsx +3 -3
- package/src/views/SkiaJSDomView.tsx +30 -9
- package/src/views/SkiaPictureView.tsx +22 -2
- package/src/views/SkiaPictureView.web.tsx +3 -3
- package/src/views/types.ts +2 -13
- package/cpp/rnskia/RNSkDispatchQueue.cpp +0 -73
- package/cpp/rnskia/RNSkDispatchQueue.h +0 -49
- package/ios/RNSkia-iOS/DisplayLink.h +0 -17
- package/ios/RNSkia-iOS/DisplayLink.mm +0 -41
|
@@ -3,7 +3,6 @@ declare const SkiaBaseWebView_base: any;
|
|
|
3
3
|
export class SkiaBaseWebView extends SkiaBaseWebView_base {
|
|
4
4
|
[x: string]: any;
|
|
5
5
|
constructor(props: any);
|
|
6
|
-
_mode: any;
|
|
7
6
|
unsubscribeAll(): void;
|
|
8
7
|
_unsubscriptions: any[] | undefined;
|
|
9
8
|
onLayoutEvent(evt: any): void;
|
|
@@ -34,16 +33,6 @@ export class SkiaBaseWebView extends SkiaBaseWebView_base {
|
|
|
34
33
|
_redrawRequests: number | undefined;
|
|
35
34
|
requestId: number | undefined;
|
|
36
35
|
redraw(): void;
|
|
37
|
-
/**
|
|
38
|
-
* Updates the drawing mode for the skia view. This is the same
|
|
39
|
-
* as declaratively setting the mode property on the SkiaView.
|
|
40
|
-
* There are two drawing modes, "continuous" and "default",
|
|
41
|
-
* where the continuous mode will continuously redraw the view and
|
|
42
|
-
* the default mode will only redraw when any of the regular react
|
|
43
|
-
* properties are changed like size and margins.
|
|
44
|
-
* @param mode Drawing mode to use.
|
|
45
|
-
*/
|
|
46
|
-
setDrawMode(mode: any): void;
|
|
47
36
|
render(): any;
|
|
48
37
|
}
|
|
49
38
|
import _JsiSkSurface = require("../skia/web/JsiSkSurface");
|
|
@@ -6,6 +6,9 @@ export class SkiaDomView extends SkiaDomView_base {
|
|
|
6
6
|
_nativeId: number;
|
|
7
7
|
get nativeId(): number;
|
|
8
8
|
componentDidUpdate(prevProps: any): void;
|
|
9
|
+
componentWillUnmount(): void;
|
|
10
|
+
tick(): void;
|
|
11
|
+
requestId: number | undefined;
|
|
9
12
|
/**
|
|
10
13
|
* Creates a snapshot from the canvas in the surface
|
|
11
14
|
* @param rect Rect to use as bounds. Optional.
|
|
@@ -6,6 +6,9 @@ export class SkiaPictureView extends SkiaPictureView_base {
|
|
|
6
6
|
_nativeId: number;
|
|
7
7
|
get nativeId(): number;
|
|
8
8
|
componentDidUpdate(prevProps: any): void;
|
|
9
|
+
componentWillUnmount(): void;
|
|
10
|
+
tick(): void;
|
|
11
|
+
requestId: number | undefined;
|
|
9
12
|
/**
|
|
10
13
|
* Creates a snapshot from the canvas in the surface
|
|
11
14
|
* @param rect Rect to use as bounds. Optional.
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export class SkiaBaseWebView extends React.Component<any, any, any> {
|
|
2
2
|
constructor(props: any);
|
|
3
|
-
_mode: any;
|
|
4
3
|
unsubscribeAll(): void;
|
|
5
4
|
_unsubscriptions: any[] | undefined;
|
|
6
5
|
onLayoutEvent(evt: any): void;
|
|
@@ -31,16 +30,6 @@ export class SkiaBaseWebView extends React.Component<any, any, any> {
|
|
|
31
30
|
_redrawRequests: number | undefined;
|
|
32
31
|
requestId: number | undefined;
|
|
33
32
|
redraw(): void;
|
|
34
|
-
/**
|
|
35
|
-
* Updates the drawing mode for the skia view. This is the same
|
|
36
|
-
* as declaratively setting the mode property on the SkiaView.
|
|
37
|
-
* There are two drawing modes, "continuous" and "default",
|
|
38
|
-
* where the continuous mode will continuously redraw the view and
|
|
39
|
-
* the default mode will only redraw when any of the regular react
|
|
40
|
-
* properties are changed like size and margins.
|
|
41
|
-
* @param mode Drawing mode to use.
|
|
42
|
-
*/
|
|
43
|
-
setDrawMode(mode: any): void;
|
|
44
33
|
render(): React.CElement<import("react-native").ViewProps, import("react-native").View>;
|
|
45
34
|
}
|
|
46
35
|
import React from "react";
|
|
@@ -3,6 +3,9 @@ export class SkiaDomView extends React.Component<any, any, any> {
|
|
|
3
3
|
_nativeId: number;
|
|
4
4
|
get nativeId(): number;
|
|
5
5
|
componentDidUpdate(prevProps: any): void;
|
|
6
|
+
componentWillUnmount(): void;
|
|
7
|
+
tick(): void;
|
|
8
|
+
requestId: number | undefined;
|
|
6
9
|
/**
|
|
7
10
|
* Creates a snapshot from the canvas in the surface
|
|
8
11
|
* @param rect Rect to use as bounds. Optional.
|
|
@@ -3,6 +3,9 @@ export class SkiaPictureView extends React.Component<any, any, any> {
|
|
|
3
3
|
_nativeId: number;
|
|
4
4
|
get nativeId(): number;
|
|
5
5
|
componentDidUpdate(prevProps: any): void;
|
|
6
|
+
componentWillUnmount(): void;
|
|
7
|
+
tick(): void;
|
|
8
|
+
requestId: number | undefined;
|
|
6
9
|
/**
|
|
7
10
|
* Creates a snapshot from the canvas in the surface
|
|
8
11
|
* @param rect Rect to use as bounds. Optional.
|
|
@@ -6,5 +6,6 @@ export declare const useCanvasRef: () => React.RefObject<SkiaDomView>;
|
|
|
6
6
|
export interface CanvasProps extends SkiaBaseViewProps {
|
|
7
7
|
ref?: RefObject<SkiaDomView>;
|
|
8
8
|
children: ReactNode;
|
|
9
|
+
mode?: "default" | "continuous";
|
|
9
10
|
}
|
|
10
11
|
export declare const Canvas: FunctionComponent<CanvasProps & React.RefAttributes<SkiaDomView>>;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { SkRect, SkCanvas } from "../skia/types";
|
|
3
|
-
import type {
|
|
3
|
+
import type { SkiaBaseViewProps } from "./types";
|
|
4
4
|
export declare abstract class SkiaBaseWebView<TProps extends SkiaBaseViewProps> extends React.Component<TProps> {
|
|
5
5
|
constructor(props: TProps);
|
|
6
6
|
private _surface;
|
|
7
7
|
private _unsubscriptions;
|
|
8
8
|
private _canvas;
|
|
9
9
|
private _canvasRef;
|
|
10
|
-
private _mode;
|
|
11
10
|
private _redrawRequests;
|
|
12
11
|
private requestId;
|
|
13
12
|
protected width: number;
|
|
@@ -36,16 +35,6 @@ export declare abstract class SkiaBaseWebView<TProps extends SkiaBaseViewProps>
|
|
|
36
35
|
*/
|
|
37
36
|
private tick;
|
|
38
37
|
redraw(): void;
|
|
39
|
-
/**
|
|
40
|
-
* Updates the drawing mode for the skia view. This is the same
|
|
41
|
-
* as declaratively setting the mode property on the SkiaView.
|
|
42
|
-
* There are two drawing modes, "continuous" and "default",
|
|
43
|
-
* where the continuous mode will continuously redraw the view and
|
|
44
|
-
* the default mode will only redraw when any of the regular react
|
|
45
|
-
* properties are changed like size and margins.
|
|
46
|
-
* @param mode Drawing mode to use.
|
|
47
|
-
*/
|
|
48
|
-
setDrawMode(mode: DrawMode): void;
|
|
49
38
|
private onLayout;
|
|
50
39
|
render(): React.JSX.Element;
|
|
51
40
|
}
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { SkRect } from "../skia/types";
|
|
3
|
-
import type {
|
|
3
|
+
import type { SkiaDomViewNativeProps } from "./types";
|
|
4
|
+
interface SkiaDomViewProps extends SkiaDomViewNativeProps {
|
|
5
|
+
mode?: "default" | "continuous";
|
|
6
|
+
}
|
|
4
7
|
export declare class SkiaDomView extends React.Component<SkiaDomViewProps> {
|
|
5
8
|
constructor(props: SkiaDomViewProps);
|
|
6
9
|
private _nativeId;
|
|
10
|
+
private requestId;
|
|
7
11
|
get nativeId(): number;
|
|
8
12
|
componentDidUpdate(prevProps: SkiaDomViewProps): void;
|
|
13
|
+
componentWillUnmount(): void;
|
|
14
|
+
private tick;
|
|
9
15
|
/**
|
|
10
16
|
* Creates a snapshot from the canvas in the surface
|
|
11
17
|
* @param rect Rect to use as bounds. Optional.
|
|
@@ -24,3 +30,4 @@ export declare class SkiaDomView extends React.Component<SkiaDomViewProps> {
|
|
|
24
30
|
redraw(): void;
|
|
25
31
|
render(): React.JSX.Element;
|
|
26
32
|
}
|
|
33
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { SkCanvas } from "../skia/types";
|
|
2
2
|
import { SkiaBaseWebView } from "./SkiaBaseWebView";
|
|
3
|
-
import type {
|
|
4
|
-
export declare class SkiaDomView extends SkiaBaseWebView<
|
|
5
|
-
constructor(props:
|
|
3
|
+
import type { SkiaDomViewNativeProps } from "./types";
|
|
4
|
+
export declare class SkiaDomView extends SkiaBaseWebView<SkiaDomViewNativeProps> {
|
|
5
|
+
constructor(props: SkiaDomViewNativeProps);
|
|
6
6
|
protected renderInCanvas(canvas: SkCanvas): void;
|
|
7
7
|
}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { Skia, SkRect } from "../skia/types";
|
|
3
|
-
import type {
|
|
4
|
-
|
|
3
|
+
import type { SkiaDomViewNativeProps } from "./types";
|
|
4
|
+
interface SkiaDomViewProps extends SkiaDomViewNativeProps {
|
|
5
|
+
mode?: "default" | "continuous";
|
|
6
|
+
}
|
|
7
|
+
type SkiaJSDomViewProps = SkiaDomViewProps & {
|
|
5
8
|
Skia: Skia;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
mode?: "default" | "continuous";
|
|
10
|
+
};
|
|
11
|
+
export declare class SkiaJSDomView extends React.Component<SkiaJSDomViewProps> {
|
|
12
|
+
constructor(props: SkiaJSDomViewProps);
|
|
10
13
|
private _nativeId;
|
|
14
|
+
private requestId;
|
|
15
|
+
private tick;
|
|
11
16
|
get nativeId(): number;
|
|
12
17
|
componentDidUpdate(prevProps: SkiaDomViewProps & {
|
|
13
18
|
Skia: Skia;
|
|
@@ -29,3 +34,4 @@ export declare class SkiaJSDomView extends React.Component<SkiaDomViewProps & {
|
|
|
29
34
|
componentWillUnmount(): void;
|
|
30
35
|
render(): React.JSX.Element;
|
|
31
36
|
}
|
|
37
|
+
export {};
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { SkRect } from "../skia/types";
|
|
3
|
-
import type {
|
|
3
|
+
import type { SkiaPictureViewNativeProps } from "./types";
|
|
4
|
+
interface SkiaPictureViewProps extends SkiaPictureViewNativeProps {
|
|
5
|
+
mode?: "default" | "continuous";
|
|
6
|
+
}
|
|
4
7
|
export declare class SkiaPictureView extends React.Component<SkiaPictureViewProps> {
|
|
8
|
+
private requestId;
|
|
5
9
|
constructor(props: SkiaPictureViewProps);
|
|
6
10
|
private _nativeId;
|
|
7
11
|
get nativeId(): number;
|
|
8
12
|
componentDidUpdate(prevProps: SkiaPictureViewProps): void;
|
|
13
|
+
componentWillUnmount(): void;
|
|
14
|
+
private tick;
|
|
9
15
|
/**
|
|
10
16
|
* Creates a snapshot from the canvas in the surface
|
|
11
17
|
* @param rect Rect to use as bounds. Optional.
|
|
@@ -18,3 +24,4 @@ export declare class SkiaPictureView extends React.Component<SkiaPictureViewProp
|
|
|
18
24
|
redraw(): void;
|
|
19
25
|
render(): React.JSX.Element;
|
|
20
26
|
}
|
|
27
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { SkCanvas } from "../skia/types";
|
|
2
|
-
import type {
|
|
2
|
+
import type { SkiaPictureViewNativeProps } from "./types";
|
|
3
3
|
import { SkiaBaseWebView } from "./SkiaBaseWebView";
|
|
4
|
-
export declare class SkiaPictureView extends SkiaBaseWebView<
|
|
5
|
-
constructor(props:
|
|
4
|
+
export declare class SkiaPictureView extends SkiaBaseWebView<SkiaPictureViewNativeProps> {
|
|
5
|
+
constructor(props: SkiaPictureViewNativeProps);
|
|
6
6
|
protected renderInCanvas(canvas: SkCanvas): void;
|
|
7
7
|
}
|
|
@@ -2,9 +2,7 @@ import type { ViewProps } from "react-native";
|
|
|
2
2
|
import type { GroupProps, RenderNode } from "../dom/types";
|
|
3
3
|
import type { SkImage, SkPicture, SkRect, SkSize } from "../skia/types";
|
|
4
4
|
import type { SharedValueType } from "../renderer/processors/Animations/Animations";
|
|
5
|
-
export type DrawMode = "continuous" | "default";
|
|
6
5
|
export type NativeSkiaViewProps = ViewProps & {
|
|
7
|
-
mode?: DrawMode;
|
|
8
6
|
debug?: boolean;
|
|
9
7
|
};
|
|
10
8
|
export interface DrawingInfo {
|
|
@@ -19,14 +17,6 @@ export interface ISkiaViewApi {
|
|
|
19
17
|
makeImageSnapshotAsync: (nativeId: number, rect?: SkRect) => Promise<SkImage>;
|
|
20
18
|
}
|
|
21
19
|
export interface SkiaBaseViewProps extends ViewProps {
|
|
22
|
-
/**
|
|
23
|
-
* Sets the drawing mode for the skia view. There are two drawing
|
|
24
|
-
* modes, "continuous" and "default", where the continuous mode will
|
|
25
|
-
* continuously redraw the view, and the default mode will only
|
|
26
|
-
* redraw when any of the regular react properties are changed like
|
|
27
|
-
* sizes and margins.
|
|
28
|
-
*/
|
|
29
|
-
mode?: DrawMode;
|
|
30
20
|
/**
|
|
31
21
|
* When set to true the view will display information about the
|
|
32
22
|
* average time it takes to render.
|
|
@@ -38,9 +28,9 @@ export interface SkiaBaseViewProps extends ViewProps {
|
|
|
38
28
|
*/
|
|
39
29
|
onSize?: SharedValueType<SkSize>;
|
|
40
30
|
}
|
|
41
|
-
export interface
|
|
31
|
+
export interface SkiaPictureViewNativeProps extends SkiaBaseViewProps {
|
|
42
32
|
picture?: SkPicture;
|
|
43
33
|
}
|
|
44
|
-
export interface
|
|
34
|
+
export interface SkiaDomViewNativeProps extends SkiaBaseViewProps {
|
|
45
35
|
root?: RenderNode<GroupProps>;
|
|
46
36
|
}
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"setup-skia-web": "./scripts/setup-canvaskit.js"
|
|
8
8
|
},
|
|
9
9
|
"title": "React Native Skia",
|
|
10
|
-
"version": "1.5.
|
|
10
|
+
"version": "1.5.9",
|
|
11
11
|
"description": "High-performance React Native Graphics using Skia",
|
|
12
12
|
"main": "lib/module/index.js",
|
|
13
13
|
"react-native": "src/index.ts",
|
|
@@ -9,8 +9,8 @@ use_graphite = ENV['SK_GRAPHITE'] == '1'
|
|
|
9
9
|
|
|
10
10
|
# Set preprocessor definitions based on GRAPHITE flag
|
|
11
11
|
preprocessor_defs = use_graphite ?
|
|
12
|
-
'$(inherited) SK_GRAPHITE=1' :
|
|
13
|
-
'$(inherited) SK_METAL=1 SK_GANESH=1'
|
|
12
|
+
'$(inherited) SK_GRAPHITE=1 SK_IMAGE_READ_PIXELS_DISABLE_LEGACY_API=1' :
|
|
13
|
+
'$(inherited) SK_METAL=1 SK_GANESH=1 SK_IMAGE_READ_PIXELS_DISABLE_LEGACY_API=1'
|
|
14
14
|
|
|
15
15
|
# Define base frameworks
|
|
16
16
|
base_frameworks = ['libs/ios/libskia.xcframework',
|
package/src/renderer/Canvas.tsx
CHANGED
|
@@ -27,6 +27,7 @@ export const useCanvasRef = () => useRef<SkiaDomView>(null);
|
|
|
27
27
|
export interface CanvasProps extends SkiaBaseViewProps {
|
|
28
28
|
ref?: RefObject<SkiaDomView>;
|
|
29
29
|
children: ReactNode;
|
|
30
|
+
mode?: "default" | "continuous";
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
const useOnSizeEvent = (
|
|
@@ -54,7 +55,7 @@ export const Canvas = forwardRef<SkiaDomView, CanvasProps>(
|
|
|
54
55
|
children,
|
|
55
56
|
style,
|
|
56
57
|
debug,
|
|
57
|
-
mode,
|
|
58
|
+
mode = "default",
|
|
58
59
|
onSize: _onSize,
|
|
59
60
|
onLayout: _onLayout,
|
|
60
61
|
...props
|
|
@@ -95,8 +96,8 @@ export const Canvas = forwardRef<SkiaDomView, CanvasProps>(
|
|
|
95
96
|
style={style}
|
|
96
97
|
root={root.dom}
|
|
97
98
|
onLayout={onLayout}
|
|
98
|
-
mode={mode}
|
|
99
99
|
debug={debug}
|
|
100
|
+
mode={mode}
|
|
100
101
|
{...props}
|
|
101
102
|
/>
|
|
102
103
|
);
|
|
@@ -104,12 +105,12 @@ export const Canvas = forwardRef<SkiaDomView, CanvasProps>(
|
|
|
104
105
|
return (
|
|
105
106
|
<SkiaJSDomView
|
|
106
107
|
Skia={Skia}
|
|
108
|
+
mode={mode}
|
|
107
109
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
108
110
|
ref={ref as any}
|
|
109
111
|
style={style}
|
|
110
112
|
root={root.dom}
|
|
111
113
|
onLayout={onLayout}
|
|
112
|
-
mode={mode}
|
|
113
114
|
debug={debug}
|
|
114
115
|
{...props}
|
|
115
116
|
/>
|
|
@@ -43,51 +43,17 @@ describe("Image loading from bundles", () => {
|
|
|
43
43
|
},
|
|
44
44
|
{
|
|
45
45
|
data: Array.from(
|
|
46
|
-
loadImage("skia/__tests__/assets/oslo.jpg").encodeToBytes()
|
|
46
|
+
loadImage("skia/__tests__/assets/oslo-mini.jpg").encodeToBytes()
|
|
47
47
|
),
|
|
48
48
|
}
|
|
49
49
|
);
|
|
50
50
|
expect(pixels).toBeDefined();
|
|
51
51
|
expect(pixels).toEqual([
|
|
52
|
-
|
|
52
|
+
171, 188, 198, 255, 171, 188, 198, 255, 171, 188, 198, 255, 171, 188, 198,
|
|
53
53
|
255,
|
|
54
54
|
]);
|
|
55
55
|
});
|
|
56
56
|
|
|
57
|
-
// it("should read pixels from an image using a preallocated buffer", async () => {
|
|
58
|
-
// const pixels = await surface.eval(
|
|
59
|
-
// (Skia, { colorType, alphaType, data }) => {
|
|
60
|
-
// const image = Skia.Image.MakeImageFromEncoded(
|
|
61
|
-
// Skia.Data.fromBytes(new Uint8Array(data))
|
|
62
|
-
// )!;
|
|
63
|
-
// const result = new Uint8Array(16);
|
|
64
|
-
// image.readPixels(
|
|
65
|
-
// 0,
|
|
66
|
-
// 0,
|
|
67
|
-
// {
|
|
68
|
-
// width: 2,
|
|
69
|
-
// height: 2,
|
|
70
|
-
// colorType,
|
|
71
|
-
// alphaType,
|
|
72
|
-
// },
|
|
73
|
-
// result
|
|
74
|
-
// );
|
|
75
|
-
// return result;
|
|
76
|
-
// },
|
|
77
|
-
// {
|
|
78
|
-
// colorType: ColorType.RGBA_8888,
|
|
79
|
-
// alphaType: AlphaType.Unpremul,
|
|
80
|
-
// data: Array.from(
|
|
81
|
-
// loadImage("skia/__tests__/assets/oslo.jpg").encodeToBytes()
|
|
82
|
-
// ),
|
|
83
|
-
// }
|
|
84
|
-
// );
|
|
85
|
-
// expect(pixels).toBeDefined();
|
|
86
|
-
// expect(Array.from(pixels!)).toEqual([
|
|
87
|
-
// 170, 186, 199, 255, 170, 186, 199, 255, 170, 186, 199, 255, 170, 186, 199,
|
|
88
|
-
// 255,
|
|
89
|
-
// ]);
|
|
90
|
-
// });
|
|
91
57
|
it("should read pixels from a canvas", async () => {
|
|
92
58
|
const pixels = await surface.eval(
|
|
93
59
|
(Skia, { colorType, alphaType }) => {
|
|
@@ -108,32 +74,4 @@ describe("Image loading from bundles", () => {
|
|
|
108
74
|
expect(pixels).toBeDefined();
|
|
109
75
|
expect(Array.from(pixels!)).toEqual([255, 0, 0, 255]);
|
|
110
76
|
});
|
|
111
|
-
// it("should read pixels from a canvas using a preallocated buffer", async () => {
|
|
112
|
-
// const pixels = await surface.eval(
|
|
113
|
-
// (Skia, { colorType, alphaType }) => {
|
|
114
|
-
// const offscreen = Skia.Surface.MakeOffscreen(10, 10)!;
|
|
115
|
-
// const canvas = offscreen.getCanvas();
|
|
116
|
-
// canvas.drawColor(Skia.Color("red"));
|
|
117
|
-
// const result = new Uint8Array(4);
|
|
118
|
-
// canvas.readPixels(0, 0, {
|
|
119
|
-
// width: 1,
|
|
120
|
-
// height: 1,
|
|
121
|
-
// colorType,
|
|
122
|
-
// alphaType,
|
|
123
|
-
// }, result);
|
|
124
|
-
// },
|
|
125
|
-
// { colorType: ColorType.RGBA_8888, alphaType: AlphaType.Unpremul }
|
|
126
|
-
// );
|
|
127
|
-
// expect(pixels).toBeDefined();
|
|
128
|
-
// expect(Array.from(pixels!)).toEqual([255, 0, 0, 255]);
|
|
129
|
-
// });
|
|
130
|
-
// This test should only run on CI because it will trigger a redbox.
|
|
131
|
-
// While this is fine on CI, it is undesirable on local dev.
|
|
132
|
-
// it("should not crash with an invalid viewTag", async () => {
|
|
133
|
-
// const result = await surface.eval((Skia) => {
|
|
134
|
-
// Skia.Image.MakeImageFromViewTag(-1);
|
|
135
|
-
// return true;
|
|
136
|
-
// });
|
|
137
|
-
// expect(result).toBe(true);
|
|
138
|
-
// });
|
|
139
77
|
});
|
|
Binary file
|
|
@@ -6,7 +6,7 @@ import type { SkRect, SkCanvas } from "../skia/types";
|
|
|
6
6
|
import { JsiSkSurface } from "../skia/web/JsiSkSurface";
|
|
7
7
|
import { Platform } from "../Platform";
|
|
8
8
|
|
|
9
|
-
import type {
|
|
9
|
+
import type { SkiaBaseViewProps } from "./types";
|
|
10
10
|
|
|
11
11
|
const pd = Platform.PixelRatio;
|
|
12
12
|
|
|
@@ -15,14 +15,12 @@ export abstract class SkiaBaseWebView<
|
|
|
15
15
|
> extends React.Component<TProps> {
|
|
16
16
|
constructor(props: TProps) {
|
|
17
17
|
super(props);
|
|
18
|
-
this._mode = props.mode ?? "default";
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
private _surface: JsiSkSurface | null = null;
|
|
22
21
|
private _unsubscriptions: Array<() => void> = [];
|
|
23
22
|
private _canvas: SkCanvas | null = null;
|
|
24
23
|
private _canvasRef = React.createRef<HTMLCanvasElement>();
|
|
25
|
-
private _mode: DrawMode;
|
|
26
24
|
private _redrawRequests = 0;
|
|
27
25
|
private requestId = 0;
|
|
28
26
|
|
|
@@ -106,7 +104,7 @@ export abstract class SkiaBaseWebView<
|
|
|
106
104
|
* Sends a redraw request to the native SkiaView.
|
|
107
105
|
*/
|
|
108
106
|
private tick() {
|
|
109
|
-
if (this.
|
|
107
|
+
if (this._redrawRequests > 0) {
|
|
110
108
|
this._redrawRequests = 0;
|
|
111
109
|
if (this._canvas) {
|
|
112
110
|
const canvas = this._canvas!;
|
|
@@ -125,24 +123,10 @@ export abstract class SkiaBaseWebView<
|
|
|
125
123
|
this._redrawRequests++;
|
|
126
124
|
}
|
|
127
125
|
|
|
128
|
-
/**
|
|
129
|
-
* Updates the drawing mode for the skia view. This is the same
|
|
130
|
-
* as declaratively setting the mode property on the SkiaView.
|
|
131
|
-
* There are two drawing modes, "continuous" and "default",
|
|
132
|
-
* where the continuous mode will continuously redraw the view and
|
|
133
|
-
* the default mode will only redraw when any of the regular react
|
|
134
|
-
* properties are changed like size and margins.
|
|
135
|
-
* @param mode Drawing mode to use.
|
|
136
|
-
*/
|
|
137
|
-
public setDrawMode(mode: DrawMode) {
|
|
138
|
-
this._mode = mode;
|
|
139
|
-
this.tick();
|
|
140
|
-
}
|
|
141
|
-
|
|
142
126
|
private onLayout = this.onLayoutEvent.bind(this);
|
|
143
127
|
|
|
144
128
|
render() {
|
|
145
|
-
const {
|
|
129
|
+
const { debug = false, ...viewProps } = this.props;
|
|
146
130
|
return (
|
|
147
131
|
<Platform.View {...viewProps} onLayout={this.onLayout}>
|
|
148
132
|
<canvas ref={this._canvasRef} style={{ display: "flex", flex: 1 }} />
|
|
@@ -6,15 +6,19 @@ import { Platform } from "../Platform";
|
|
|
6
6
|
import SkiaDomViewNativeComponent from "../specs/SkiaDomViewNativeComponent";
|
|
7
7
|
|
|
8
8
|
import { SkiaViewApi } from "./api";
|
|
9
|
-
import type {
|
|
9
|
+
import type { SkiaDomViewNativeProps } from "./types";
|
|
10
10
|
import { SkiaViewNativeId } from "./SkiaViewNativeId";
|
|
11
11
|
|
|
12
|
-
const NativeSkiaDomView: HostComponent<
|
|
12
|
+
const NativeSkiaDomView: HostComponent<SkiaDomViewNativeProps> =
|
|
13
13
|
Platform.OS !== "web"
|
|
14
14
|
? SkiaDomViewNativeComponent
|
|
15
15
|
: // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
16
|
(null as any);
|
|
17
17
|
|
|
18
|
+
interface SkiaDomViewProps extends SkiaDomViewNativeProps {
|
|
19
|
+
mode?: "default" | "continuous";
|
|
20
|
+
}
|
|
21
|
+
|
|
18
22
|
export class SkiaDomView extends React.Component<SkiaDomViewProps> {
|
|
19
23
|
constructor(props: SkiaDomViewProps) {
|
|
20
24
|
super(props);
|
|
@@ -28,9 +32,11 @@ export class SkiaDomView extends React.Component<SkiaDomViewProps> {
|
|
|
28
32
|
assertSkiaViewApi();
|
|
29
33
|
SkiaViewApi.setJsiProperty(this._nativeId, "onSize", onSize);
|
|
30
34
|
}
|
|
35
|
+
this.tick();
|
|
31
36
|
}
|
|
32
37
|
|
|
33
38
|
private _nativeId: number;
|
|
39
|
+
private requestId = 0;
|
|
34
40
|
|
|
35
41
|
public get nativeId() {
|
|
36
42
|
return this._nativeId;
|
|
@@ -46,6 +52,20 @@ export class SkiaDomView extends React.Component<SkiaDomViewProps> {
|
|
|
46
52
|
assertSkiaViewApi();
|
|
47
53
|
SkiaViewApi.setJsiProperty(this._nativeId, "onSize", onSize);
|
|
48
54
|
}
|
|
55
|
+
this.tick();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
componentWillUnmount(): void {
|
|
59
|
+
if (this.requestId) {
|
|
60
|
+
cancelAnimationFrame(this.requestId);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private tick() {
|
|
65
|
+
this.redraw();
|
|
66
|
+
if (this.props.mode === "continuous") {
|
|
67
|
+
this.requestId = requestAnimationFrame(this.tick.bind(this));
|
|
68
|
+
}
|
|
49
69
|
}
|
|
50
70
|
|
|
51
71
|
/**
|
|
@@ -77,12 +97,11 @@ export class SkiaDomView extends React.Component<SkiaDomViewProps> {
|
|
|
77
97
|
}
|
|
78
98
|
|
|
79
99
|
render() {
|
|
80
|
-
const {
|
|
100
|
+
const { debug = false, ...viewProps } = this.props;
|
|
81
101
|
return (
|
|
82
102
|
<NativeSkiaDomView
|
|
83
103
|
collapsable={false}
|
|
84
104
|
nativeID={`${this._nativeId}`}
|
|
85
|
-
mode={mode}
|
|
86
105
|
debug={debug}
|
|
87
106
|
{...viewProps}
|
|
88
107
|
/>
|
|
@@ -3,10 +3,10 @@ import type { SkCanvas } from "../skia/types";
|
|
|
3
3
|
import { JsiDrawingContext } from "../dom/types/DrawingContext";
|
|
4
4
|
|
|
5
5
|
import { SkiaBaseWebView } from "./SkiaBaseWebView";
|
|
6
|
-
import type {
|
|
6
|
+
import type { SkiaDomViewNativeProps } from "./types";
|
|
7
7
|
|
|
8
|
-
export class SkiaDomView extends SkiaBaseWebView<
|
|
9
|
-
constructor(props:
|
|
8
|
+
export class SkiaDomView extends SkiaBaseWebView<SkiaDomViewNativeProps> {
|
|
9
|
+
constructor(props: SkiaDomViewNativeProps) {
|
|
10
10
|
super(props);
|
|
11
11
|
}
|
|
12
12
|
|