@shopify/react-native-skia 0.1.121 → 0.1.124

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. package/android/CMakeLists.txt +3 -1
  2. package/android/cpp/jni/JniSkiaDrawView.cpp +14 -71
  3. package/android/cpp/jni/JniSkiaManager.cpp +1 -1
  4. package/android/cpp/jni/include/JniSkiaDrawView.h +18 -22
  5. package/android/cpp/jni/include/JniSkiaManager.h +4 -4
  6. package/android/cpp/rnskia-android/RNSkDrawViewImpl.cpp +68 -0
  7. package/android/cpp/rnskia-android/RNSkDrawViewImpl.h +48 -0
  8. package/android/cpp/{jni/include/JniPlatformContextWrapper.h → rnskia-android/RNSkPlatformContextImpl.h} +4 -4
  9. package/android/cpp/{jni → rnskia-android}/SkiaOpenGLRenderer.cpp +39 -54
  10. package/android/cpp/{jni/include → rnskia-android}/SkiaOpenGLRenderer.h +2 -31
  11. package/android/src/main/java/com/shopify/reactnative/skia/RNSkiaViewManager.java +1 -1
  12. package/android/src/main/java/com/shopify/reactnative/skia/SkiaDrawView.java +21 -28
  13. package/cpp/api/JsiSkApi.h +2 -0
  14. package/cpp/api/JsiSkColor.h +49 -0
  15. package/cpp/api/JsiSkPath.h +31 -2
  16. package/cpp/api/JsiSkPathFactory.h +96 -1
  17. package/cpp/api/third_party/CSSColorParser.h +324 -0
  18. package/cpp/rnskia/RNSkAnimation.h +3 -8
  19. package/cpp/rnskia/RNSkDrawView.cpp +84 -126
  20. package/cpp/rnskia/RNSkDrawView.h +7 -37
  21. package/cpp/rnskia/RNSkJsiViewApi.h +8 -5
  22. package/cpp/rnskia/RNSkManager.cpp +2 -2
  23. package/cpp/rnskia/RNSkManager.h +2 -2
  24. package/cpp/rnskia/RNSkPlatformContext.h +1 -1
  25. package/cpp/rnskia/RNSkValueApi.h +6 -2
  26. package/cpp/rnskia/values/RNSkClockValue.h +21 -13
  27. package/cpp/rnskia/values/RNSkDerivedValue.h +13 -6
  28. package/cpp/rnskia/values/RNSkReadonlyValue.h +17 -16
  29. package/cpp/rnskia/values/RNSkValue.h +8 -3
  30. package/cpp/utils/RNSkTimingInfo.h +13 -1
  31. package/ios/RNSkia-iOS/RNSkDrawViewImpl.h +8 -10
  32. package/ios/RNSkia-iOS/RNSkDrawViewImpl.mm +25 -10
  33. package/ios/RNSkia-iOS/SkiaDrawView.mm +21 -16
  34. package/lib/commonjs/renderer/Canvas.js +17 -8
  35. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  36. package/lib/commonjs/renderer/components/Paint.js +1 -1
  37. package/lib/commonjs/renderer/components/Paint.js.map +1 -1
  38. package/lib/commonjs/renderer/components/colorFilters/Lerp.js +1 -1
  39. package/lib/commonjs/renderer/components/colorFilters/Lerp.js.map +1 -1
  40. package/lib/commonjs/renderer/components/shaders/Shader.js +2 -2
  41. package/lib/commonjs/renderer/components/shaders/Shader.js.map +1 -1
  42. package/lib/commonjs/renderer/components/shapes/Path.js +10 -2
  43. package/lib/commonjs/renderer/components/shapes/Path.js.map +1 -1
  44. package/lib/commonjs/renderer/nodes/Node.js +3 -3
  45. package/lib/commonjs/renderer/nodes/Node.js.map +1 -1
  46. package/lib/commonjs/renderer/processors/Circles.js +3 -2
  47. package/lib/commonjs/renderer/processors/Circles.js.map +1 -1
  48. package/lib/commonjs/renderer/processors/Font.js +1 -1
  49. package/lib/commonjs/renderer/processors/Font.js.map +1 -1
  50. package/lib/commonjs/renderer/processors/Paint.js +6 -1
  51. package/lib/commonjs/renderer/processors/Paint.js.map +1 -1
  52. package/lib/commonjs/renderer/processors/Rects.js +6 -6
  53. package/lib/commonjs/renderer/processors/Rects.js.map +1 -1
  54. package/lib/commonjs/skia/Color.js +3 -25
  55. package/lib/commonjs/skia/Color.js.map +1 -1
  56. package/lib/commonjs/skia/Image/Image.js.map +1 -1
  57. package/lib/commonjs/skia/ImageFilter/ImageFilterFactory.js.map +1 -1
  58. package/lib/commonjs/skia/Paint/Paint.js +13 -1
  59. package/lib/commonjs/skia/Paint/Paint.js.map +1 -1
  60. package/lib/commonjs/skia/Paint/usePaint.js +2 -4
  61. package/lib/commonjs/skia/Paint/usePaint.js.map +1 -1
  62. package/lib/commonjs/skia/Path/Path.js +13 -1
  63. package/lib/commonjs/skia/Path/Path.js.map +1 -1
  64. package/lib/commonjs/skia/Shader/Shader.js.map +1 -1
  65. package/lib/commonjs/skia/Skia.js +43 -3
  66. package/lib/commonjs/skia/Skia.js.map +1 -1
  67. package/lib/commonjs/values/animation/timing/functions/getResolvedParams.js +3 -3
  68. package/lib/commonjs/values/animation/timing/functions/getResolvedParams.js.map +1 -1
  69. package/lib/module/renderer/Canvas.js +12 -6
  70. package/lib/module/renderer/Canvas.js.map +1 -1
  71. package/lib/module/renderer/components/Paint.js +2 -2
  72. package/lib/module/renderer/components/Paint.js.map +1 -1
  73. package/lib/module/renderer/components/colorFilters/Lerp.js +1 -1
  74. package/lib/module/renderer/components/colorFilters/Lerp.js.map +1 -1
  75. package/lib/module/renderer/components/shaders/Shader.js +3 -2
  76. package/lib/module/renderer/components/shaders/Shader.js.map +1 -1
  77. package/lib/module/renderer/components/shapes/Path.js +10 -3
  78. package/lib/module/renderer/components/shapes/Path.js.map +1 -1
  79. package/lib/module/renderer/nodes/Node.js +3 -3
  80. package/lib/module/renderer/nodes/Node.js.map +1 -1
  81. package/lib/module/renderer/processors/Circles.js +3 -2
  82. package/lib/module/renderer/processors/Circles.js.map +1 -1
  83. package/lib/module/renderer/processors/Font.js +1 -1
  84. package/lib/module/renderer/processors/Font.js.map +1 -1
  85. package/lib/module/renderer/processors/Paint.js +6 -1
  86. package/lib/module/renderer/processors/Paint.js.map +1 -1
  87. package/lib/module/renderer/processors/Rects.js +5 -6
  88. package/lib/module/renderer/processors/Rects.js.map +1 -1
  89. package/lib/module/skia/Color.js +2 -21
  90. package/lib/module/skia/Color.js.map +1 -1
  91. package/lib/module/skia/Image/Image.js.map +1 -1
  92. package/lib/module/skia/ImageFilter/ImageFilterFactory.js.map +1 -1
  93. package/lib/module/skia/Paint/Paint.js +6 -0
  94. package/lib/module/skia/Paint/Paint.js.map +1 -1
  95. package/lib/module/skia/Paint/usePaint.js +2 -3
  96. package/lib/module/skia/Paint/usePaint.js.map +1 -1
  97. package/lib/module/skia/Path/Path.js +11 -0
  98. package/lib/module/skia/Path/Path.js.map +1 -1
  99. package/lib/module/skia/Shader/Shader.js.map +1 -1
  100. package/lib/module/skia/Skia.js +45 -2
  101. package/lib/module/skia/Skia.js.map +1 -1
  102. package/lib/module/values/animation/timing/functions/getResolvedParams.js +3 -3
  103. package/lib/module/values/animation/timing/functions/getResolvedParams.js.map +1 -1
  104. package/lib/typescript/src/renderer/Canvas.d.ts +6 -0
  105. package/lib/typescript/src/renderer/components/shapes/Path.d.ts +3 -1
  106. package/lib/typescript/src/renderer/processors/Paint.d.ts +2 -1
  107. package/lib/typescript/src/skia/Color.d.ts +0 -1
  108. package/lib/typescript/src/skia/Image/Image.d.ts +3 -3
  109. package/lib/typescript/src/skia/ImageFilter/ImageFilterFactory.d.ts +2 -2
  110. package/lib/typescript/src/skia/Paint/Paint.d.ts +3 -2
  111. package/lib/typescript/src/skia/Path/Path.d.ts +13 -0
  112. package/lib/typescript/src/skia/Path/PathFactory.d.ts +7 -1
  113. package/lib/typescript/src/skia/Picture/Picture.d.ts +2 -2
  114. package/lib/typescript/src/skia/RuntimeEffect/RuntimeEffect.d.ts +3 -3
  115. package/lib/typescript/src/skia/Shader/Shader.d.ts +2 -2
  116. package/lib/typescript/src/skia/Shader/ShaderFactory.d.ts +9 -9
  117. package/lib/typescript/src/skia/Skia.d.ts +5 -3
  118. package/lib/typescript/src/values/animation/types.d.ts +5 -5
  119. package/package.json +1 -1
  120. package/scripts/install-npm.js +1 -1
  121. package/src/renderer/Canvas.tsx +13 -6
  122. package/src/renderer/components/Paint.tsx +2 -2
  123. package/src/renderer/components/colorFilters/Lerp.tsx +1 -1
  124. package/src/renderer/components/shaders/Shader.tsx +1 -1
  125. package/src/renderer/components/shapes/Path.tsx +12 -4
  126. package/src/renderer/nodes/Node.ts +3 -3
  127. package/src/renderer/processors/Circles.ts +2 -1
  128. package/src/renderer/processors/Font.ts +1 -1
  129. package/src/renderer/processors/Paint.ts +5 -0
  130. package/src/renderer/processors/Rects.ts +3 -2
  131. package/src/skia/Color.ts +3 -20
  132. package/src/skia/Image/Image.ts +3 -3
  133. package/src/skia/ImageFilter/ImageFilterFactory.ts +2 -2
  134. package/src/skia/Paint/Paint.ts +9 -2
  135. package/src/skia/Paint/usePaint.ts +2 -4
  136. package/src/skia/Path/Path.ts +16 -0
  137. package/src/skia/Path/PathFactory.ts +8 -1
  138. package/src/skia/Picture/Picture.ts +2 -2
  139. package/src/skia/RuntimeEffect/RuntimeEffect.ts +4 -4
  140. package/src/skia/Shader/Shader.ts +2 -2
  141. package/src/skia/Shader/ShaderFactory.ts +9 -9
  142. package/src/skia/Skia.ts +47 -3
  143. package/src/values/animation/timing/functions/getResolvedParams.ts +2 -2
  144. package/src/values/animation/types.ts +5 -5
package/src/skia/Skia.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { Platform, processColor } from "react-native";
2
+
1
3
  /*global SkiaApi*/
2
4
  import type { ImageFilterFactory } from "./ImageFilter";
3
5
  import type { PathFactory } from "./Path";
@@ -11,8 +13,6 @@ import type { SkRect } from "./Rect";
11
13
  import type { SkRRect } from "./RRect";
12
14
  import type { RuntimeEffectFactory } from "./RuntimeEffect";
13
15
  import type { ShaderFactory } from "./Shader";
14
- import type { SkColor } from "./Color";
15
- import { processColor } from "./Color";
16
16
  import type { SkMatrix } from "./Matrix";
17
17
  import type { PathEffectFactory } from "./PathEffect";
18
18
  import type { SkPoint } from "./Point";
@@ -27,6 +27,45 @@ import type { SkRSXform } from "./RSXform";
27
27
  import type { SkPath } from "./Path/Path";
28
28
  import type { SkContourMeasureIter } from "./ContourMeasure";
29
29
  import type { PictureFactory, SkPictureRecorder } from "./Picture";
30
+ import type { Color, SkColor } from "./Color";
31
+
32
+ /*
33
+ * Parse CSS colors
34
+ */
35
+ const SkiaColor = (cl: Color) => {
36
+ if (typeof cl === "number") {
37
+ return cl;
38
+ }
39
+ const color = Skia.parseColorString(cl);
40
+ if (color !== undefined) {
41
+ return color;
42
+ } else {
43
+ // If the color is not recognized, we fallback to React Native
44
+ let rnColor = processColor(cl);
45
+ // 1. Neither Skia or RN could parse the color
46
+ if (typeof rnColor !== "number") {
47
+ console.warn("Skia couldn't parse the following color " + cl);
48
+ return BLACK;
49
+ // 2. The color is recognized by RN but not by Skia
50
+ } else {
51
+ console.warn(
52
+ "Skia couldn't parse the following color " +
53
+ cl +
54
+ ". The color parsing was delegated to React Native. Please file on issue with that color."
55
+ );
56
+ // On android we need to move the alpha byte to the start of the structure
57
+ if (Platform.OS === "android") {
58
+ rnColor = rnColor >>> 0;
59
+ const a = (rnColor >> 24) & 0xff;
60
+ const r = (rnColor >> 16) & 0xff;
61
+ const g = (rnColor >> 8) & 0xff;
62
+ const b = rnColor & 0xff;
63
+ rnColor = ((a << 24) | (r << 16) | (g << 8) | b) >>> 0;
64
+ }
65
+ return rnColor;
66
+ }
67
+ }
68
+ };
30
69
 
31
70
  /**
32
71
  * Declares the interface for the native Skia API
@@ -36,6 +75,8 @@ export interface Skia {
36
75
  XYWHRect: (x: number, y: number, width: number, height: number) => SkRect;
37
76
  RRectXY: (rect: SkRect, rx: number, ry: number) => SkRRect;
38
77
  RSXform: (scos: number, ssin: number, tx: number, ty: number) => SkRSXform;
78
+ Color: (color: Color) => SkColor;
79
+ parseColorString: (color: string) => SkColor | undefined;
39
80
  ContourMeasureIter: (
40
81
  path: SkPath,
41
82
  forceClosed: boolean,
@@ -115,7 +156,8 @@ export const Skia = {
115
156
  ColorFilter: SkiaApi.ColorFilter,
116
157
  ContourMeasureIter: SkiaApi.ContourMeasureIter,
117
158
  // Here are constructors for data types which are represented as typed arrays in CanvasKit
118
- Color: (color: Parameters<typeof processColor>[0]) => processColor(color, 1),
159
+ Color: SkiaColor,
160
+ parseColorString: SkiaApi.parseColorString,
119
161
  RSXform: SkiaApi.RSXform,
120
162
  // For the following methods the factory symmetry is broken to be comptatible with CanvasKit
121
163
  MakeSurface: SkiaApi.Surface.Make,
@@ -123,3 +165,5 @@ export const Skia = {
123
165
  MakeImage: SkiaApi.Image.MakeImage,
124
166
  MakeVertices: SkiaApi.MakeVertices,
125
167
  };
168
+
169
+ const BLACK = Skia.parseColorString("black")!;
@@ -42,8 +42,8 @@ export const getResolvedParams = (
42
42
 
43
43
  const resolvedConfig: Required<TimingConfig> = { ...DefaultTimingConfig };
44
44
  if (config) {
45
- resolvedConfig.duration = config.duration;
46
- resolvedConfig.easing = config.easing ?? ((t) => t);
45
+ resolvedConfig.duration = config.duration ?? DefaultTimingConfig.duration;
46
+ resolvedConfig.easing = config.easing ?? DefaultTimingConfig.easing;
47
47
  }
48
48
 
49
49
  return { ...resolvedParameters, ...resolvedConfig };
@@ -1,12 +1,12 @@
1
1
  export interface SpringConfig {
2
- mass: number;
3
- stiffness: number;
4
- damping: number;
5
- velocity: number;
2
+ mass?: number;
3
+ stiffness?: number;
4
+ damping?: number;
5
+ velocity?: number;
6
6
  }
7
7
 
8
8
  export interface TimingConfig {
9
- duration: number;
9
+ duration?: number;
10
10
  easing?: (t: number) => number;
11
11
  }
12
12