@shopify/react-native-skia 0.1.154 → 0.1.156

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 (167) hide show
  1. package/android/cpp/jni/JniLoad.cpp +5 -5
  2. package/android/cpp/jni/JniPlatformContext.cpp +107 -119
  3. package/android/cpp/jni/JniSkiaManager.cpp +18 -20
  4. package/android/cpp/jni/include/JniPlatformContext.h +41 -45
  5. package/android/cpp/jni/include/JniSkiaBaseView.h +52 -55
  6. package/android/cpp/jni/include/JniSkiaDrawView.h +72 -77
  7. package/android/cpp/jni/include/JniSkiaManager.h +51 -53
  8. package/android/cpp/jni/include/JniSkiaPictureView.h +74 -78
  9. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +36 -45
  10. package/android/cpp/rnskia-android/RNSkAndroidView.h +87 -92
  11. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +62 -65
  12. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.h +20 -17
  13. package/android/cpp/rnskia-android/SkiaOpenGLRenderer.cpp +257 -313
  14. package/android/cpp/rnskia-android/SkiaOpenGLRenderer.h +107 -110
  15. package/cpp/api/JsiSkApi.h +66 -62
  16. package/cpp/api/JsiSkCanvas.h +38 -30
  17. package/cpp/api/JsiSkColor.h +58 -56
  18. package/cpp/api/JsiSkColorFilter.h +5 -3
  19. package/cpp/api/JsiSkColorFilterFactory.h +23 -21
  20. package/cpp/api/JsiSkContourMeasure.h +74 -85
  21. package/cpp/api/JsiSkContourMeasureIter.h +68 -75
  22. package/cpp/api/JsiSkData.h +16 -22
  23. package/cpp/api/JsiSkDataFactory.h +86 -79
  24. package/cpp/api/JsiSkFont.h +286 -311
  25. package/cpp/api/JsiSkHostObjects.h +15 -16
  26. package/cpp/api/JsiSkImage.h +107 -103
  27. package/cpp/api/JsiSkImageFactory.h +34 -36
  28. package/cpp/api/JsiSkImageFilter.h +5 -3
  29. package/cpp/api/JsiSkImageFilterFactory.h +71 -68
  30. package/cpp/api/JsiSkImageInfo.h +41 -38
  31. package/cpp/api/JsiSkMaskFilter.h +5 -3
  32. package/cpp/api/JsiSkMaskFilterFactory.h +2 -3
  33. package/cpp/api/JsiSkMatrix.h +26 -36
  34. package/cpp/api/JsiSkPaint.h +20 -13
  35. package/cpp/api/JsiSkPath.h +70 -85
  36. package/cpp/api/JsiSkPathEffect.h +5 -3
  37. package/cpp/api/JsiSkPathEffectFactory.h +33 -28
  38. package/cpp/api/JsiSkPathFactory.h +68 -67
  39. package/cpp/api/JsiSkPicture.h +28 -22
  40. package/cpp/api/JsiSkPictureFactory.h +13 -12
  41. package/cpp/api/JsiSkPictureRecorder.h +21 -19
  42. package/cpp/api/JsiSkPoint.h +6 -8
  43. package/cpp/api/JsiSkRRect.h +11 -7
  44. package/cpp/api/JsiSkRSXform.h +82 -85
  45. package/cpp/api/JsiSkRect.h +9 -9
  46. package/cpp/api/JsiSkRuntimeEffect.h +182 -186
  47. package/cpp/api/JsiSkRuntimeEffectFactory.h +10 -11
  48. package/cpp/api/JsiSkRuntimeShaderBuilder.h +64 -61
  49. package/cpp/api/JsiSkSVG.h +4 -5
  50. package/cpp/api/JsiSkSVGFactory.h +28 -27
  51. package/cpp/api/JsiSkShader.h +3 -2
  52. package/cpp/api/JsiSkShaderFactory.h +37 -25
  53. package/cpp/api/JsiSkSurface.h +44 -40
  54. package/cpp/api/JsiSkSurfaceFactory.h +22 -22
  55. package/cpp/api/JsiSkTextBlob.h +28 -31
  56. package/cpp/api/JsiSkTextBlobFactory.h +88 -87
  57. package/cpp/api/JsiSkTypeface.h +6 -5
  58. package/cpp/api/JsiSkTypefaceFactory.h +22 -21
  59. package/cpp/api/JsiSkVertices.h +137 -124
  60. package/cpp/api/third_party/CSSColorParser.cpp +161 -174
  61. package/cpp/api/third_party/CSSColorParser.h +172 -96
  62. package/cpp/jsi/JsiHostObject.cpp +11 -9
  63. package/cpp/jsi/JsiHostObject.h +31 -24
  64. package/cpp/jsi/JsiSimpleValueWrapper.h +74 -83
  65. package/cpp/jsi/JsiValueWrapper.h +52 -54
  66. package/cpp/rnskia/RNSkAnimation.h +26 -29
  67. package/cpp/rnskia/RNSkDispatchQueue.cpp +50 -61
  68. package/cpp/rnskia/RNSkDispatchQueue.h +3 -1
  69. package/cpp/rnskia/RNSkInfoParameter.h +12 -12
  70. package/cpp/rnskia/RNSkJsView.cpp +82 -81
  71. package/cpp/rnskia/RNSkJsView.h +45 -41
  72. package/cpp/rnskia/RNSkJsiViewApi.h +99 -89
  73. package/cpp/rnskia/RNSkManager.cpp +8 -7
  74. package/cpp/rnskia/RNSkManager.h +8 -6
  75. package/cpp/rnskia/RNSkPictureView.h +44 -37
  76. package/cpp/rnskia/RNSkPlatformContext.h +39 -28
  77. package/cpp/rnskia/RNSkValueApi.h +33 -34
  78. package/cpp/rnskia/RNSkView.h +108 -93
  79. package/cpp/rnskia/values/RNSkClockValue.h +63 -64
  80. package/cpp/rnskia/values/RNSkComputedValue.h +32 -30
  81. package/cpp/rnskia/values/RNSkReadonlyValue.h +60 -59
  82. package/cpp/rnskia/values/RNSkValue.h +38 -40
  83. package/cpp/utils/RNSkLog.h +9 -7
  84. package/cpp/utils/RNSkMeasureTime.h +7 -7
  85. package/cpp/utils/RNSkTimingInfo.h +27 -24
  86. package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.h +8 -9
  87. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +24 -23
  88. package/ios/RNSkia-iOS/RNSkiOSView.h +16 -13
  89. package/ios/RNSkia-iOS/SkiaUIView.h +9 -8
  90. package/lib/commonjs/dom/nodes/JsiSkDOM.js +6 -0
  91. package/lib/commonjs/dom/nodes/JsiSkDOM.js.map +1 -1
  92. package/lib/commonjs/dom/nodes/LayerNode.js +43 -0
  93. package/lib/commonjs/dom/nodes/LayerNode.js.map +1 -0
  94. package/lib/commonjs/dom/nodes/RenderNode.js +1 -1
  95. package/lib/commonjs/dom/nodes/RenderNode.js.map +1 -1
  96. package/lib/commonjs/dom/types/NodeType.js +1 -0
  97. package/lib/commonjs/dom/types/NodeType.js.map +1 -1
  98. package/lib/commonjs/dom/types/SkDOM.js.map +1 -1
  99. package/lib/commonjs/renderer/HostComponents.js +3 -0
  100. package/lib/commonjs/renderer/HostComponents.js.map +1 -1
  101. package/lib/commonjs/renderer/components/Group.js +19 -4
  102. package/lib/commonjs/renderer/components/Group.js.map +1 -1
  103. package/lib/commonjs/renderer/components/Paint.js +6 -1
  104. package/lib/commonjs/renderer/components/Paint.js.map +1 -1
  105. package/lib/commonjs/views/SkiaPictureView.js +3 -2
  106. package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
  107. package/lib/commonjs/views/SkiaView.js +6 -3
  108. package/lib/commonjs/views/SkiaView.js.map +1 -1
  109. package/lib/module/dom/nodes/JsiSkDOM.js +5 -0
  110. package/lib/module/dom/nodes/JsiSkDOM.js.map +1 -1
  111. package/lib/module/dom/nodes/LayerNode.js +32 -0
  112. package/lib/module/dom/nodes/LayerNode.js.map +1 -0
  113. package/lib/module/dom/nodes/RenderNode.js +1 -1
  114. package/lib/module/dom/nodes/RenderNode.js.map +1 -1
  115. package/lib/module/dom/types/NodeType.js +1 -0
  116. package/lib/module/dom/types/NodeType.js.map +1 -1
  117. package/lib/module/dom/types/SkDOM.js.map +1 -1
  118. package/lib/module/renderer/HostComponents.js +3 -0
  119. package/lib/module/renderer/HostComponents.js.map +1 -1
  120. package/lib/module/renderer/components/Group.js +16 -3
  121. package/lib/module/renderer/components/Group.js.map +1 -1
  122. package/lib/module/renderer/components/Paint.js +7 -1
  123. package/lib/module/renderer/components/Paint.js.map +1 -1
  124. package/lib/module/views/SkiaPictureView.js +2 -2
  125. package/lib/module/views/SkiaPictureView.js.map +1 -1
  126. package/lib/module/views/SkiaView.js +4 -2
  127. package/lib/module/views/SkiaView.js.map +1 -1
  128. package/lib/typescript/src/dom/nodes/JsiSkDOM.d.ts +2 -0
  129. package/lib/typescript/src/dom/nodes/LayerNode.d.ts +8 -0
  130. package/lib/typescript/src/dom/types/NodeType.d.ts +1 -0
  131. package/lib/typescript/src/dom/types/SkDOM.d.ts +1 -0
  132. package/lib/typescript/src/renderer/HostComponents.d.ts +2 -1
  133. package/lib/typescript/src/renderer/components/Group.d.ts +5 -1
  134. package/lib/typescript/src/views/SkiaView.d.ts +3 -0
  135. package/libs/android/arm64-v8a/libskottie.a +0 -0
  136. package/libs/android/arm64-v8a/libsksg.a +0 -0
  137. package/libs/android/armeabi-v7a/libskottie.a +0 -0
  138. package/libs/android/armeabi-v7a/libsksg.a +0 -0
  139. package/libs/android/x86/libskottie.a +0 -0
  140. package/libs/android/x86/libsksg.a +0 -0
  141. package/libs/android/x86_64/libskottie.a +0 -0
  142. package/libs/android/x86_64/libsksg.a +0 -0
  143. package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
  144. package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  145. package/libs/ios/libskottie.xcframework/Info.plist +42 -0
  146. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
  147. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
  148. package/libs/ios/libsksg.xcframework/Info.plist +42 -0
  149. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
  150. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
  151. package/libs/ios/libskshaper.xcframework/Info.plist +5 -5
  152. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
  153. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
  154. package/libs/ios/libsvg.xcframework/Info.plist +5 -5
  155. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
  156. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
  157. package/package.json +3 -1
  158. package/src/dom/nodes/JsiSkDOM.ts +5 -0
  159. package/src/dom/nodes/LayerNode.ts +35 -0
  160. package/src/dom/nodes/RenderNode.ts +4 -3
  161. package/src/dom/types/NodeType.ts +1 -0
  162. package/src/dom/types/SkDOM.ts +1 -0
  163. package/src/renderer/HostComponents.ts +3 -0
  164. package/src/renderer/components/Group.tsx +16 -3
  165. package/src/renderer/components/Paint.tsx +7 -1
  166. package/src/views/SkiaPictureView.tsx +2 -3
  167. package/src/views/SkiaView.tsx +2 -2
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "setup-skia-web": "./scripts/setup-canvaskit.js"
8
8
  },
9
9
  "title": "React Native Skia",
10
- "version": "0.1.154",
10
+ "version": "0.1.156",
11
11
  "description": "High-performance React Native Graphics using Skia",
12
12
  "main": "lib/module/index.js",
13
13
  "files": [
@@ -30,6 +30,8 @@
30
30
  "libs/ios/libskia.xcframework",
31
31
  "libs/ios/libskshaper.xcframework",
32
32
  "libs/ios/libsvg.xcframework",
33
+ "libs/ios/libskottie.xcframework",
34
+ "libs/ios/libsksg.xcframework",
33
35
  "react-native-skia.podspec",
34
36
  "scripts/install-npm.js",
35
37
  "scripts/setup-canvaskit.js",
@@ -121,10 +121,15 @@ import { MorphologyImageFilterNode } from "./paint/ImageFilters";
121
121
  import { GroupNode } from "./GroupNode";
122
122
  import { PaintNode } from "./PaintNode";
123
123
  import type { NodeContext } from "./Node";
124
+ import { LayerNode } from "./LayerNode";
124
125
 
125
126
  export class JsiSkDOM implements SkDOM {
126
127
  constructor(private ctx: NodeContext) {}
127
128
 
129
+ Layer(props?: ChildrenProps) {
130
+ return new LayerNode(this.ctx, props ?? {});
131
+ }
132
+
128
133
  Group(props?: GroupProps) {
129
134
  return new GroupNode(this.ctx, props ?? {});
130
135
  }
@@ -0,0 +1,35 @@
1
+ import type { DeclarationNode, DrawingContext, Node } from "../types";
2
+ import { NodeType } from "../types";
3
+ import type { ChildrenProps } from "../types/Common";
4
+ import type { SkPaint } from "../../skia";
5
+
6
+ import { JsiRenderNode } from "./RenderNode";
7
+ import type { NodeContext } from "./Node";
8
+ import { JsiDeclarationNode } from "./Node";
9
+
10
+ const isLayer = (
11
+ node: Node<unknown>
12
+ ): node is DeclarationNode<unknown, SkPaint> =>
13
+ node instanceof JsiDeclarationNode && node.isPaint();
14
+
15
+ export class LayerNode extends JsiRenderNode<ChildrenProps> {
16
+ constructor(ctx: NodeContext, props: ChildrenProps) {
17
+ super(ctx, NodeType.Layer, props);
18
+ }
19
+
20
+ renderNode(ctx: DrawingContext): void {
21
+ const [layer, ...children] = this.children();
22
+ if (isLayer(layer)) {
23
+ const paint = layer.materialize() as SkPaint;
24
+ ctx.canvas.saveLayer(paint);
25
+ }
26
+ children.map((child) => {
27
+ if (child instanceof JsiRenderNode) {
28
+ child.render(ctx);
29
+ }
30
+ });
31
+ if (isLayer(layer)) {
32
+ ctx.canvas.restore();
33
+ }
34
+ }
35
+ }
@@ -211,9 +211,10 @@ export abstract class JsiRenderNode<P extends GroupProps>
211
211
  const { invertClip, layer, matrix, transform } = this.props;
212
212
  const { canvas } = parentCtx;
213
213
 
214
- const opacity = this.props.opacity
215
- ? parentCtx.opacity * this.props.opacity
216
- : parentCtx.opacity;
214
+ const opacity =
215
+ this.props.opacity !== undefined
216
+ ? parentCtx.opacity * this.props.opacity
217
+ : parentCtx.opacity;
217
218
 
218
219
  if (
219
220
  this.paintCache === null ||
@@ -1,5 +1,6 @@
1
1
  export const enum NodeType {
2
2
  // Shaders
3
+ Layer = "skLayer",
3
4
  Shader = "skShader",
4
5
  ImageShader = "skImageShader",
5
6
  ColorShader = "skColorShader",
@@ -76,6 +76,7 @@ type NullablePathEffectNode<P> = DeclarationNode<P, SkPathEffect, null>;
76
76
  type DrawingNode<P extends GroupProps> = RenderNode<P>;
77
77
 
78
78
  export interface SkDOM {
79
+ Layer(props?: ChildrenProps): RenderNode<ChildrenProps>;
79
80
  Group(props?: GroupProps): RenderNode<GroupProps>;
80
81
  Paint(props: PaintProps): DeclarationNode<PaintProps, SkPaint>;
81
82
 
@@ -66,6 +66,7 @@ declare global {
66
66
  namespace JSX {
67
67
  interface IntrinsicElements {
68
68
  skGroup: SkiaProps<GroupProps>;
69
+ skLayer: SkiaProps<ChildrenProps>;
69
70
  skPaint: SkiaProps<PaintProps> & { ref: ForwardedRef<PaintNode> };
70
71
 
71
72
  // Drawings
@@ -146,6 +147,8 @@ export const createNode = (
146
147
  ) => {
147
148
  const { Sk } = container;
148
149
  switch (type) {
150
+ case NodeType.Layer:
151
+ return Sk.Layer(props);
149
152
  case NodeType.Group:
150
153
  return Sk.Group(props);
151
154
  case NodeType.Paint:
@@ -1,8 +1,21 @@
1
- import React from "react";
1
+ import React, { isValidElement } from "react";
2
2
 
3
3
  import type { SkiaProps } from "../processors";
4
4
  import type { GroupProps } from "../../dom/types";
5
+ import type { ChildrenProps } from "../../dom/types/Common";
5
6
 
6
- export const Group = (props: SkiaProps<GroupProps>) => {
7
- return <skGroup {...props} />;
7
+ export interface PublicGroupProps extends Omit<GroupProps, "layer"> {
8
+ layer?: GroupProps["layer"] | ChildrenProps["children"];
9
+ }
10
+
11
+ export const Group = ({ layer, ...props }: SkiaProps<PublicGroupProps>) => {
12
+ if (isValidElement(layer) && typeof layer === "object") {
13
+ return (
14
+ <skLayer>
15
+ {layer}
16
+ <skGroup {...props} />
17
+ </skLayer>
18
+ );
19
+ }
20
+ return <skGroup layer={layer as GroupProps["layer"]} {...props} />;
8
21
  };
@@ -1,10 +1,16 @@
1
+ /* eslint-disable max-len */
1
2
  import React, { useRef, forwardRef } from "react";
2
3
 
3
4
  import type { SkiaProps } from "../processors";
4
5
  import type { DrawingNodeProps } from "../../dom/types";
5
6
  import type { PaintNode } from "../../dom/nodes/PaintNode";
6
7
 
7
- export const usePaintRef = () => useRef<PaintNode>(null);
8
+ export const usePaintRef = () => {
9
+ console.log(`usePaintRef() is now deprecated.
10
+ If you are using the layer property, simply pass the component directly: https://shopify.github.io/react-native-skia/docs/group#layer-effects.
11
+ If you are using the paint property, please the following paint properties directly: https://shopify.github.io/react-native-skia/docs/paint/overview`);
12
+ return useRef<PaintNode>(null);
13
+ };
8
14
 
9
15
  export const Paint = forwardRef<PaintNode, SkiaProps<DrawingNodeProps>>(
10
16
  (props, ref) => {
@@ -5,17 +5,16 @@ import type { SkRect } from "../skia/types";
5
5
  import type { SkiaValue } from "../values";
6
6
 
7
7
  import { SkiaViewApi } from "./api";
8
+ import { SkiaViewNativeId } from "./SkiaView";
8
9
  import type { NativeSkiaViewProps, SkiaPictureViewProps } from "./types";
9
10
 
10
- let SkiaViewNativeId = 1000;
11
-
12
11
  const NativeSkiaPictureView =
13
12
  requireNativeComponent<NativeSkiaViewProps>("SkiaPictureView");
14
13
 
15
14
  export class SkiaPictureView extends React.Component<SkiaPictureViewProps> {
16
15
  constructor(props: SkiaPictureViewProps) {
17
16
  super(props);
18
- this._nativeId = SkiaViewNativeId++;
17
+ this._nativeId = SkiaViewNativeId.current++;
19
18
  const { picture } = props;
20
19
  if (picture) {
21
20
  assertSkiaViewApi();
@@ -7,7 +7,7 @@ import type { SkiaValue } from "../values";
7
7
  import { SkiaViewApi } from "./api";
8
8
  import type { NativeSkiaViewProps, SkiaDrawViewProps } from "./types";
9
9
 
10
- let SkiaViewNativeId = 1000;
10
+ export const SkiaViewNativeId = { current: 1000 };
11
11
 
12
12
  const NativeSkiaView =
13
13
  requireNativeComponent<NativeSkiaViewProps>("SkiaDrawView");
@@ -15,7 +15,7 @@ const NativeSkiaView =
15
15
  export class SkiaView extends React.Component<SkiaDrawViewProps> {
16
16
  constructor(props: SkiaDrawViewProps) {
17
17
  super(props);
18
- this._nativeId = SkiaViewNativeId++;
18
+ this._nativeId = SkiaViewNativeId.current++;
19
19
  const { onDraw } = props;
20
20
  if (onDraw) {
21
21
  assertSkiaViewApi();