@shopify/react-native-skia 1.5.8 → 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.
Files changed (104) hide show
  1. package/android/CMakeLists.txt +0 -1
  2. package/android/cpp/jni/JniPlatformContext.cpp +0 -49
  3. package/android/cpp/jni/include/JniPlatformContext.h +1 -17
  4. package/android/cpp/jni/include/JniSkiaBaseView.h +0 -2
  5. package/android/cpp/jni/include/JniSkiaDomView.h +0 -3
  6. package/android/cpp/jni/include/JniSkiaManager.h +0 -2
  7. package/android/cpp/jni/include/JniSkiaPictureView.h +0 -3
  8. package/android/cpp/rnskia-android/MainThreadDispatcher.h +69 -0
  9. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +4 -11
  10. package/android/cpp/rnskia-android/RNSkAndroidView.h +3 -13
  11. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +0 -1
  12. package/android/src/main/java/com/shopify/reactnative/skia/PlatformContext.java +0 -85
  13. package/android/src/main/java/com/shopify/reactnative/skia/RNSkiaModule.java +1 -21
  14. package/android/src/main/java/com/shopify/reactnative/skia/SkiaManager.java +0 -4
  15. package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaDomViewManagerDelegate.java +1 -4
  16. package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaDomViewManagerInterface.java +0 -1
  17. package/cpp/rnskia/RNSkManager.cpp +2 -3
  18. package/cpp/rnskia/RNSkPlatformContext.h +2 -114
  19. package/cpp/rnskia/RNSkView.h +16 -75
  20. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +1 -10
  21. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +0 -16
  22. package/ios/RNSkia-iOS/SkiaDomView.mm +0 -1
  23. package/ios/RNSkia-iOS/SkiaDomViewManager.mm +0 -6
  24. package/ios/RNSkia-iOS/SkiaPictureView.mm +0 -1
  25. package/ios/RNSkia-iOS/SkiaPictureViewManager.mm +0 -6
  26. package/ios/RNSkia-iOS/SkiaUIView.h +0 -1
  27. package/ios/RNSkia-iOS/SkiaUIView.mm +1 -14
  28. package/lib/commonjs/renderer/Canvas.d.ts +1 -0
  29. package/lib/commonjs/renderer/Canvas.js +5 -5
  30. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  31. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.d.ts +0 -1
  32. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js.map +1 -1
  33. package/lib/commonjs/views/SkiaBaseWebView.d.ts +1 -12
  34. package/lib/commonjs/views/SkiaBaseWebView.js +1 -19
  35. package/lib/commonjs/views/SkiaBaseWebView.js.map +1 -1
  36. package/lib/commonjs/views/SkiaDomView.d.ts +8 -1
  37. package/lib/commonjs/views/SkiaDomView.js +14 -2
  38. package/lib/commonjs/views/SkiaDomView.js.map +1 -1
  39. package/lib/commonjs/views/SkiaDomView.web.d.ts +3 -3
  40. package/lib/commonjs/views/SkiaDomView.web.js.map +1 -1
  41. package/lib/commonjs/views/SkiaJSDomView.d.ts +12 -6
  42. package/lib/commonjs/views/SkiaJSDomView.js +12 -3
  43. package/lib/commonjs/views/SkiaJSDomView.js.map +1 -1
  44. package/lib/commonjs/views/SkiaPictureView.d.ts +8 -1
  45. package/lib/commonjs/views/SkiaPictureView.js +14 -1
  46. package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
  47. package/lib/commonjs/views/SkiaPictureView.web.d.ts +3 -3
  48. package/lib/commonjs/views/SkiaPictureView.web.js.map +1 -1
  49. package/lib/commonjs/views/types.d.ts +2 -12
  50. package/lib/commonjs/views/types.js.map +1 -1
  51. package/lib/module/renderer/Canvas.d.ts +1 -0
  52. package/lib/module/renderer/Canvas.js +5 -5
  53. package/lib/module/renderer/Canvas.js.map +1 -1
  54. package/lib/module/specs/SkiaPictureViewNativeComponent.d.ts +0 -1
  55. package/lib/module/specs/SkiaPictureViewNativeComponent.js.map +1 -1
  56. package/lib/module/views/SkiaBaseWebView.d.ts +1 -12
  57. package/lib/module/views/SkiaBaseWebView.js +1 -19
  58. package/lib/module/views/SkiaBaseWebView.js.map +1 -1
  59. package/lib/module/views/SkiaDomView.d.ts +8 -1
  60. package/lib/module/views/SkiaDomView.js +14 -2
  61. package/lib/module/views/SkiaDomView.js.map +1 -1
  62. package/lib/module/views/SkiaDomView.web.d.ts +3 -3
  63. package/lib/module/views/SkiaDomView.web.js.map +1 -1
  64. package/lib/module/views/SkiaJSDomView.d.ts +12 -6
  65. package/lib/module/views/SkiaJSDomView.js +12 -3
  66. package/lib/module/views/SkiaJSDomView.js.map +1 -1
  67. package/lib/module/views/SkiaPictureView.d.ts +8 -1
  68. package/lib/module/views/SkiaPictureView.js +14 -1
  69. package/lib/module/views/SkiaPictureView.js.map +1 -1
  70. package/lib/module/views/SkiaPictureView.web.d.ts +3 -3
  71. package/lib/module/views/SkiaPictureView.web.js.map +1 -1
  72. package/lib/module/views/types.d.ts +2 -12
  73. package/lib/module/views/types.js.map +1 -1
  74. package/lib/typescript/lib/commonjs/views/SkiaBaseWebView.d.ts +0 -11
  75. package/lib/typescript/lib/commonjs/views/SkiaDomView.d.ts +3 -0
  76. package/lib/typescript/lib/commonjs/views/SkiaJSDomView.d.ts +2 -0
  77. package/lib/typescript/lib/commonjs/views/SkiaPictureView.d.ts +3 -0
  78. package/lib/typescript/lib/module/views/SkiaBaseWebView.d.ts +0 -11
  79. package/lib/typescript/lib/module/views/SkiaDomView.d.ts +3 -0
  80. package/lib/typescript/lib/module/views/SkiaJSDomView.d.ts +2 -0
  81. package/lib/typescript/lib/module/views/SkiaPictureView.d.ts +3 -0
  82. package/lib/typescript/src/renderer/Canvas.d.ts +1 -0
  83. package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.d.ts +0 -1
  84. package/lib/typescript/src/views/SkiaBaseWebView.d.ts +1 -12
  85. package/lib/typescript/src/views/SkiaDomView.d.ts +8 -1
  86. package/lib/typescript/src/views/SkiaDomView.web.d.ts +3 -3
  87. package/lib/typescript/src/views/SkiaJSDomView.d.ts +12 -6
  88. package/lib/typescript/src/views/SkiaPictureView.d.ts +8 -1
  89. package/lib/typescript/src/views/SkiaPictureView.web.d.ts +3 -3
  90. package/lib/typescript/src/views/types.d.ts +2 -12
  91. package/package.json +1 -1
  92. package/src/renderer/Canvas.tsx +4 -3
  93. package/src/specs/SkiaPictureViewNativeComponent.ts +0 -1
  94. package/src/views/SkiaBaseWebView.tsx +3 -19
  95. package/src/views/SkiaDomView.tsx +23 -4
  96. package/src/views/SkiaDomView.web.tsx +3 -3
  97. package/src/views/SkiaJSDomView.tsx +30 -9
  98. package/src/views/SkiaPictureView.tsx +22 -2
  99. package/src/views/SkiaPictureView.web.tsx +3 -3
  100. package/src/views/types.ts +2 -13
  101. package/cpp/rnskia/RNSkDispatchQueue.cpp +0 -73
  102. package/cpp/rnskia/RNSkDispatchQueue.h +0 -49
  103. package/ios/RNSkia-iOS/DisplayLink.h +0 -17
  104. package/ios/RNSkia-iOS/DisplayLink.mm +0 -41
@@ -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.
@@ -1,6 +1,8 @@
1
1
  export class SkiaJSDomView extends React.Component<any, any, any> {
2
2
  constructor(props: any);
3
3
  _nativeId: number;
4
+ tick(): void;
5
+ requestId: number | undefined;
4
6
  get nativeId(): number;
5
7
  componentDidUpdate(prevProps: any): void;
6
8
  /**
@@ -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,6 +1,5 @@
1
1
  import type { ViewProps } from "react-native";
2
2
  export interface NativeProps extends ViewProps {
3
- mode: string;
4
3
  debug?: boolean;
5
4
  }
6
5
  declare const _default: import("react-native/Libraries/Utilities/codegenNativeComponent").NativeComponentType<NativeProps>;
@@ -1,13 +1,12 @@
1
1
  import React from "react";
2
2
  import type { SkRect, SkCanvas } from "../skia/types";
3
- import type { DrawMode, SkiaBaseViewProps } from "./types";
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 { SkiaDomViewProps } from "./types";
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 { SkiaDomViewProps } from "./types";
4
- export declare class SkiaDomView extends SkiaBaseWebView<SkiaDomViewProps> {
5
- constructor(props: SkiaDomViewProps);
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 { SkiaDomViewProps } from "./types";
4
- export declare class SkiaJSDomView extends React.Component<SkiaDomViewProps & {
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
- constructor(props: SkiaDomViewProps & {
8
- Skia: Skia;
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 { SkiaPictureViewProps } from "./types";
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 { SkiaPictureViewProps } from "./types";
2
+ import type { SkiaPictureViewNativeProps } from "./types";
3
3
  import { SkiaBaseWebView } from "./SkiaBaseWebView";
4
- export declare class SkiaPictureView extends SkiaBaseWebView<SkiaPictureViewProps> {
5
- constructor(props: SkiaPictureViewProps);
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 SkiaPictureViewProps extends SkiaBaseViewProps {
31
+ export interface SkiaPictureViewNativeProps extends SkiaBaseViewProps {
42
32
  picture?: SkPicture;
43
33
  }
44
- export interface SkiaDomViewProps extends SkiaBaseViewProps {
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.8",
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",
@@ -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
  />
@@ -2,7 +2,6 @@ import codegenNativeComponent from "react-native/Libraries/Utilities/codegenNati
2
2
  import type { ViewProps } from "react-native";
3
3
 
4
4
  export interface NativeProps extends ViewProps {
5
- mode: string;
6
5
  debug?: boolean;
7
6
  }
8
7
 
@@ -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 { DrawMode, SkiaBaseViewProps } from "./types";
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._mode === "continuous" || this._redrawRequests > 0) {
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 { mode, debug = false, ...viewProps } = this.props;
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 { SkiaDomViewProps } from "./types";
9
+ import type { SkiaDomViewNativeProps } from "./types";
10
10
  import { SkiaViewNativeId } from "./SkiaViewNativeId";
11
11
 
12
- const NativeSkiaDomView: HostComponent<SkiaDomViewProps> =
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 { mode, debug = false, ...viewProps } = this.props;
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 { SkiaDomViewProps } from "./types";
6
+ import type { SkiaDomViewNativeProps } from "./types";
7
7
 
8
- export class SkiaDomView extends SkiaBaseWebView<SkiaDomViewProps> {
9
- constructor(props: SkiaDomViewProps) {
8
+ export class SkiaDomView extends SkiaBaseWebView<SkiaDomViewNativeProps> {
9
+ constructor(props: SkiaDomViewNativeProps) {
10
10
  super(props);
11
11
  }
12
12
 
@@ -7,19 +7,29 @@ import SkiaPictureViewNativeComponent from "../specs/SkiaPictureViewNativeCompon
7
7
  import { JsiDrawingContext } from "../dom/types";
8
8
 
9
9
  import { SkiaViewApi } from "./api";
10
- import type { SkiaPictureViewProps, SkiaDomViewProps } from "./types";
10
+ import type {
11
+ SkiaPictureViewNativeProps,
12
+ SkiaDomViewNativeProps,
13
+ } from "./types";
11
14
  import { SkiaViewNativeId } from "./SkiaViewNativeId";
12
15
 
13
- const NativeSkiaPictureView: HostComponent<SkiaPictureViewProps> =
16
+ const NativeSkiaPictureView: HostComponent<SkiaPictureViewNativeProps> =
14
17
  Platform.OS !== "web"
15
18
  ? SkiaPictureViewNativeComponent
16
19
  : // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
20
  (null as any);
18
21
 
19
- export class SkiaJSDomView extends React.Component<
20
- SkiaDomViewProps & { Skia: Skia }
21
- > {
22
- constructor(props: SkiaDomViewProps & { Skia: Skia }) {
22
+ interface SkiaDomViewProps extends SkiaDomViewNativeProps {
23
+ mode?: "default" | "continuous";
24
+ }
25
+
26
+ type SkiaJSDomViewProps = SkiaDomViewProps & {
27
+ Skia: Skia;
28
+ mode?: "default" | "continuous";
29
+ };
30
+
31
+ export class SkiaJSDomView extends React.Component<SkiaJSDomViewProps> {
32
+ constructor(props: SkiaJSDomViewProps) {
23
33
  super(props);
24
34
  this._nativeId = SkiaViewNativeId.current++;
25
35
  const { root, onSize } = props;
@@ -31,9 +41,18 @@ export class SkiaJSDomView extends React.Component<
31
41
  assertSkiaViewApi();
32
42
  SkiaViewApi.setJsiProperty(this._nativeId, "onSize", onSize);
33
43
  }
44
+ this.tick();
34
45
  }
35
46
 
36
47
  private _nativeId: number;
48
+ private requestId = 0;
49
+
50
+ private tick() {
51
+ this.redraw();
52
+ if (this.props.mode === "continuous") {
53
+ this.requestId = requestAnimationFrame(this.tick.bind(this));
54
+ }
55
+ }
37
56
 
38
57
  public get nativeId() {
39
58
  return this._nativeId;
@@ -49,6 +68,7 @@ export class SkiaJSDomView extends React.Component<
49
68
  assertSkiaViewApi();
50
69
  SkiaViewApi.setJsiProperty(this._nativeId, "onSize", onSize);
51
70
  }
71
+ this.tick();
52
72
  }
53
73
 
54
74
  /**
@@ -67,7 +87,6 @@ export class SkiaJSDomView extends React.Component<
67
87
  public redraw() {
68
88
  assertSkiaViewApi();
69
89
  this.draw();
70
- //SkiaViewApi.requestRedraw(this._nativeId);
71
90
  }
72
91
 
73
92
  private draw() {
@@ -89,15 +108,17 @@ export class SkiaJSDomView extends React.Component<
89
108
  componentWillUnmount(): void {
90
109
  assertSkiaViewApi();
91
110
  SkiaViewApi.setJsiProperty(this._nativeId, "picture", null);
111
+ if (this.requestId) {
112
+ cancelAnimationFrame(this.requestId);
113
+ }
92
114
  }
93
115
 
94
116
  render() {
95
- const { mode, debug = false, ...viewProps } = this.props;
117
+ const { debug = false, ...viewProps } = this.props;
96
118
  return (
97
119
  <NativeSkiaPictureView
98
120
  collapsable={false}
99
121
  nativeID={`${this._nativeId}`}
100
- mode={mode}
101
122
  debug={debug}
102
123
  {...viewProps}
103
124
  />
@@ -4,12 +4,18 @@ import type { SkRect } from "../skia/types";
4
4
  import SkiaPictureViewNativeComponent from "../specs/SkiaPictureViewNativeComponent";
5
5
 
6
6
  import { SkiaViewApi } from "./api";
7
- import type { SkiaPictureViewProps } from "./types";
7
+ import type { SkiaPictureViewNativeProps } from "./types";
8
8
  import { SkiaViewNativeId } from "./SkiaViewNativeId";
9
9
 
10
10
  const NativeSkiaPictureView = SkiaPictureViewNativeComponent;
11
11
 
12
+ interface SkiaPictureViewProps extends SkiaPictureViewNativeProps {
13
+ mode?: "default" | "continuous";
14
+ }
15
+
12
16
  export class SkiaPictureView extends React.Component<SkiaPictureViewProps> {
17
+ private requestId = 0;
18
+
13
19
  constructor(props: SkiaPictureViewProps) {
14
20
  super(props);
15
21
  this._nativeId = SkiaViewNativeId.current++;
@@ -22,6 +28,7 @@ export class SkiaPictureView extends React.Component<SkiaPictureViewProps> {
22
28
  assertSkiaViewApi();
23
29
  SkiaViewApi.setJsiProperty(this._nativeId, "onSize", onSize);
24
30
  }
31
+ this.tick();
25
32
  }
26
33
 
27
34
  private _nativeId: number;
@@ -40,6 +47,20 @@ export class SkiaPictureView extends React.Component<SkiaPictureViewProps> {
40
47
  assertSkiaViewApi();
41
48
  SkiaViewApi.setJsiProperty(this._nativeId, "onSize", onSize);
42
49
  }
50
+ this.tick();
51
+ }
52
+
53
+ componentWillUnmount() {
54
+ if (this.requestId) {
55
+ cancelAnimationFrame(this.requestId);
56
+ }
57
+ }
58
+
59
+ private tick() {
60
+ this.redraw();
61
+ if (this.props.mode === "continuous") {
62
+ this.requestId = requestAnimationFrame(this.tick.bind(this));
63
+ }
43
64
  }
44
65
 
45
66
  /**
@@ -66,7 +87,6 @@ export class SkiaPictureView extends React.Component<SkiaPictureViewProps> {
66
87
  <NativeSkiaPictureView
67
88
  collapsable={false}
68
89
  nativeID={`${this._nativeId}`}
69
- mode={mode ?? "default"}
70
90
  debug={debug}
71
91
  {...viewProps}
72
92
  />
@@ -1,10 +1,10 @@
1
1
  import type { SkCanvas } from "../skia/types";
2
2
 
3
- import type { SkiaPictureViewProps } from "./types";
3
+ import type { SkiaPictureViewNativeProps } from "./types";
4
4
  import { SkiaBaseWebView } from "./SkiaBaseWebView";
5
5
 
6
- export class SkiaPictureView extends SkiaBaseWebView<SkiaPictureViewProps> {
7
- constructor(props: SkiaPictureViewProps) {
6
+ export class SkiaPictureView extends SkiaBaseWebView<SkiaPictureViewNativeProps> {
7
+ constructor(props: SkiaPictureViewNativeProps) {
8
8
  super(props);
9
9
  }
10
10
 
@@ -4,10 +4,7 @@ import type { GroupProps, RenderNode } from "../dom/types";
4
4
  import type { SkImage, SkPicture, SkRect, SkSize } from "../skia/types";
5
5
  import type { SharedValueType } from "../renderer/processors/Animations/Animations";
6
6
 
7
- export type DrawMode = "continuous" | "default";
8
-
9
7
  export type NativeSkiaViewProps = ViewProps & {
10
- mode?: DrawMode;
11
8
  debug?: boolean;
12
9
  };
13
10
 
@@ -25,14 +22,6 @@ export interface ISkiaViewApi {
25
22
  }
26
23
 
27
24
  export interface SkiaBaseViewProps extends ViewProps {
28
- /**
29
- * Sets the drawing mode for the skia view. There are two drawing
30
- * modes, "continuous" and "default", where the continuous mode will
31
- * continuously redraw the view, and the default mode will only
32
- * redraw when any of the regular react properties are changed like
33
- * sizes and margins.
34
- */
35
- mode?: DrawMode;
36
25
  /**
37
26
  * When set to true the view will display information about the
38
27
  * average time it takes to render.
@@ -45,10 +34,10 @@ export interface SkiaBaseViewProps extends ViewProps {
45
34
  onSize?: SharedValueType<SkSize>;
46
35
  }
47
36
 
48
- export interface SkiaPictureViewProps extends SkiaBaseViewProps {
37
+ export interface SkiaPictureViewNativeProps extends SkiaBaseViewProps {
49
38
  picture?: SkPicture;
50
39
  }
51
40
 
52
- export interface SkiaDomViewProps extends SkiaBaseViewProps {
41
+ export interface SkiaDomViewNativeProps extends SkiaBaseViewProps {
53
42
  root?: RenderNode<GroupProps>;
54
43
  }