@shopify/react-native-skia 0.1.131 → 0.1.134

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. package/android/CMakeLists.txt +1 -1
  2. package/android/build.gradle +17 -2
  3. package/android/cpp/rnskia-android/RNSkDrawViewImpl.cpp +5 -0
  4. package/cpp/api/JsiSkFont.h +6 -2
  5. package/cpp/api/JsiSkImage.h +2 -19
  6. package/cpp/api/JsiSkPaint.h +5 -32
  7. package/cpp/api/JsiSkPath.h +4 -4
  8. package/cpp/rnskia/RNSkValueApi.h +6 -6
  9. package/cpp/rnskia/values/{RNSkDerivedValue.h → RNSkComputedValue.h} +7 -7
  10. package/cpp/utils/RNSkLog.h +5 -0
  11. package/ios/RNSkia-iOS/SkiaManager.mm +1 -1
  12. package/lib/commonjs/mock/index.js +190 -0
  13. package/lib/commonjs/mock/index.js.map +1 -0
  14. package/lib/commonjs/skia/core/Data.js +33 -43
  15. package/lib/commonjs/skia/core/Data.js.map +1 -1
  16. package/lib/commonjs/skia/core/Typeface.js +1 -1
  17. package/lib/commonjs/skia/core/Typeface.js.map +1 -1
  18. package/lib/commonjs/skia/types/Font/Font.js.map +1 -1
  19. package/lib/commonjs/skia/types/Image/Image.js +5 -5
  20. package/lib/commonjs/skia/types/Image/Image.js.map +1 -1
  21. package/lib/commonjs/skia/types/Paint/Paint.js +3 -3
  22. package/lib/commonjs/skia/types/Paint/Paint.js.map +1 -1
  23. package/lib/commonjs/skia/types/Path/Path.js +0 -1
  24. package/lib/commonjs/skia/types/Path/Path.js.map +1 -1
  25. package/lib/commonjs/skia/types/Shader/Shader.js +1 -7
  26. package/lib/commonjs/skia/types/Shader/Shader.js.map +1 -1
  27. package/lib/commonjs/skia/web/JsiSkCanvas.js +1 -1
  28. package/lib/commonjs/skia/web/JsiSkCanvas.js.map +1 -1
  29. package/lib/commonjs/skia/web/JsiSkFont.js +4 -2
  30. package/lib/commonjs/skia/web/JsiSkFont.js.map +1 -1
  31. package/lib/commonjs/skia/web/JsiSkFontMgr.js +0 -2
  32. package/lib/commonjs/skia/web/JsiSkFontMgr.js.map +1 -1
  33. package/lib/commonjs/skia/web/JsiSkImage.js +10 -6
  34. package/lib/commonjs/skia/web/JsiSkImage.js.map +1 -1
  35. package/lib/commonjs/skia/web/{JsiImageFilterFactory.js → JsiSkImageFilterFactory.js} +1 -1
  36. package/lib/commonjs/skia/web/JsiSkImageFilterFactory.js.map +1 -0
  37. package/lib/commonjs/skia/web/JsiSkPaint.js.map +1 -1
  38. package/lib/commonjs/skia/web/JsiSkPath.js +65 -52
  39. package/lib/commonjs/skia/web/JsiSkPath.js.map +1 -1
  40. package/lib/commonjs/skia/web/JsiSkShaderFactory.js +1 -1
  41. package/lib/commonjs/skia/web/JsiSkShaderFactory.js.map +1 -1
  42. package/lib/commonjs/skia/web/JsiSkVerticesFactory.js +23 -1
  43. package/lib/commonjs/skia/web/JsiSkVerticesFactory.js.map +1 -1
  44. package/lib/commonjs/skia/web/JsiSkia.js +2 -2
  45. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  46. package/lib/commonjs/values/api.js +3 -3
  47. package/lib/commonjs/values/api.js.map +1 -1
  48. package/lib/commonjs/values/api.web.js +3 -3
  49. package/lib/commonjs/values/api.web.js.map +1 -1
  50. package/lib/commonjs/values/hooks/index.js +4 -4
  51. package/lib/commonjs/values/hooks/index.js.map +1 -1
  52. package/lib/commonjs/values/hooks/useComputedValue.js +32 -0
  53. package/lib/commonjs/values/hooks/useComputedValue.js.map +1 -0
  54. package/lib/commonjs/values/web/{RNSkDerivedValue.js → RNSkComputedValue.js} +4 -4
  55. package/lib/commonjs/values/web/RNSkComputedValue.js.map +1 -0
  56. package/lib/commonjs/values/web/api.js +3 -3
  57. package/lib/commonjs/values/web/api.js.map +1 -1
  58. package/lib/commonjs/views/SkiaView.web.js +4 -4
  59. package/lib/commonjs/views/SkiaView.web.js.map +1 -1
  60. package/lib/commonjs/web/index.js +4 -2
  61. package/lib/commonjs/web/index.js.map +1 -1
  62. package/lib/module/mock/index.js +152 -0
  63. package/lib/module/mock/index.js.map +1 -0
  64. package/lib/module/skia/core/Data.js +32 -41
  65. package/lib/module/skia/core/Data.js.map +1 -1
  66. package/lib/module/skia/core/Typeface.js +1 -1
  67. package/lib/module/skia/core/Typeface.js.map +1 -1
  68. package/lib/module/skia/types/Font/Font.js.map +1 -1
  69. package/lib/module/skia/types/Image/Image.js +5 -5
  70. package/lib/module/skia/types/Image/Image.js.map +1 -1
  71. package/lib/module/skia/types/Paint/Paint.js +3 -3
  72. package/lib/module/skia/types/Paint/Paint.js.map +1 -1
  73. package/lib/module/skia/types/Path/Path.js +0 -1
  74. package/lib/module/skia/types/Path/Path.js.map +1 -1
  75. package/lib/module/skia/types/Shader/Shader.js +1 -7
  76. package/lib/module/skia/types/Shader/Shader.js.map +1 -1
  77. package/lib/module/skia/web/JsiSkCanvas.js +1 -1
  78. package/lib/module/skia/web/JsiSkCanvas.js.map +1 -1
  79. package/lib/module/skia/web/JsiSkFont.js +5 -3
  80. package/lib/module/skia/web/JsiSkFont.js.map +1 -1
  81. package/lib/module/skia/web/JsiSkFontMgr.js +0 -2
  82. package/lib/module/skia/web/JsiSkFontMgr.js.map +1 -1
  83. package/lib/module/skia/web/JsiSkImage.js +10 -7
  84. package/lib/module/skia/web/JsiSkImage.js.map +1 -1
  85. package/lib/module/skia/web/{JsiImageFilterFactory.js → JsiSkImageFilterFactory.js} +1 -1
  86. package/lib/module/skia/web/JsiSkImageFilterFactory.js.map +1 -0
  87. package/lib/module/skia/web/JsiSkPaint.js.map +1 -1
  88. package/lib/module/skia/web/JsiSkPath.js +65 -52
  89. package/lib/module/skia/web/JsiSkPath.js.map +1 -1
  90. package/lib/module/skia/web/JsiSkShaderFactory.js +1 -1
  91. package/lib/module/skia/web/JsiSkShaderFactory.js.map +1 -1
  92. package/lib/module/skia/web/JsiSkVerticesFactory.js +24 -1
  93. package/lib/module/skia/web/JsiSkVerticesFactory.js.map +1 -1
  94. package/lib/module/skia/web/JsiSkia.js +1 -1
  95. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  96. package/lib/module/values/api.js +1 -1
  97. package/lib/module/values/api.js.map +1 -1
  98. package/lib/module/values/api.web.js +1 -1
  99. package/lib/module/values/api.web.js.map +1 -1
  100. package/lib/module/values/hooks/index.js +1 -1
  101. package/lib/module/values/hooks/index.js.map +1 -1
  102. package/lib/module/values/hooks/useComputedValue.js +18 -0
  103. package/lib/module/values/hooks/useComputedValue.js.map +1 -0
  104. package/lib/module/values/web/{RNSkDerivedValue.js → RNSkComputedValue.js} +2 -2
  105. package/lib/module/values/web/RNSkComputedValue.js.map +1 -0
  106. package/lib/module/values/web/api.js +3 -3
  107. package/lib/module/values/web/api.js.map +1 -1
  108. package/lib/module/views/SkiaView.web.js +4 -4
  109. package/lib/module/views/SkiaView.web.js.map +1 -1
  110. package/lib/module/web/index.js +3 -1
  111. package/lib/module/web/index.js.map +1 -1
  112. package/lib/typescript/src/mock/index.d.ts +47 -0
  113. package/lib/typescript/src/skia/core/Data.d.ts +3 -3
  114. package/lib/typescript/src/skia/types/Font/Font.d.ts +8 -9
  115. package/lib/typescript/src/skia/types/Image/Image.d.ts +5 -5
  116. package/lib/typescript/src/skia/types/Paint/Paint.d.ts +3 -3
  117. package/lib/typescript/src/skia/types/Path/Path.d.ts +1 -2
  118. package/lib/typescript/src/skia/types/RuntimeEffect/RuntimeEffect.d.ts +1 -0
  119. package/lib/typescript/src/skia/types/Skia.d.ts +1 -1
  120. package/lib/typescript/src/skia/web/JsiSkFont.d.ts +1 -1
  121. package/lib/typescript/src/skia/web/JsiSkImage.d.ts +3 -3
  122. package/lib/typescript/src/skia/web/{JsiImageFilterFactory.d.ts → JsiSkImageFilterFactory.d.ts} +0 -0
  123. package/lib/typescript/src/skia/web/JsiSkPaint.d.ts +1 -1
  124. package/lib/typescript/src/values/api.d.ts +1 -1
  125. package/lib/typescript/src/values/api.web.d.ts +1 -1
  126. package/lib/typescript/src/values/hooks/index.d.ts +1 -1
  127. package/lib/typescript/src/values/hooks/{useDerivedValue.d.ts → useComputedValue.d.ts} +2 -1
  128. package/lib/typescript/src/values/types.d.ts +2 -2
  129. package/lib/typescript/src/values/web/{RNSkDerivedValue.d.ts → RNSkComputedValue.d.ts} +1 -1
  130. package/package.json +2 -1
  131. package/src/mock/index.ts +156 -0
  132. package/src/skia/core/Data.ts +67 -50
  133. package/src/skia/core/Typeface.ts +6 -1
  134. package/src/skia/types/Font/Font.ts +9 -14
  135. package/src/skia/types/Image/Image.ts +4 -4
  136. package/src/skia/types/Paint/Paint.ts +1 -1
  137. package/src/skia/types/Path/Path.ts +0 -1
  138. package/src/skia/types/RuntimeEffect/RuntimeEffect.ts +1 -0
  139. package/src/skia/types/Shader/Shader.ts +3 -5
  140. package/src/skia/types/Skia.ts +1 -1
  141. package/src/skia/web/JsiSkCanvas.ts +2 -2
  142. package/src/skia/web/JsiSkFont.ts +7 -3
  143. package/src/skia/web/JsiSkFontMgr.ts +0 -4
  144. package/src/skia/web/JsiSkImage.ts +37 -16
  145. package/src/skia/web/{JsiImageFilterFactory.ts → JsiSkImageFilterFactory.ts} +0 -0
  146. package/src/skia/web/JsiSkPaint.ts +1 -1
  147. package/src/skia/web/JsiSkPath.ts +64 -47
  148. package/src/skia/web/JsiSkShaderFactory.ts +4 -1
  149. package/src/skia/web/JsiSkVerticesFactory.ts +15 -1
  150. package/src/skia/web/JsiSkia.ts +2 -2
  151. package/src/values/api.ts +1 -1
  152. package/src/values/api.web.ts +1 -1
  153. package/src/values/hooks/index.ts +1 -1
  154. package/src/values/hooks/{useDerivedValue.ts → useComputedValue.ts} +8 -3
  155. package/src/values/types.ts +2 -2
  156. package/src/values/web/{RNSkDerivedValue.ts → RNSkComputedValue.ts} +1 -1
  157. package/src/values/web/api.ts +3 -3
  158. package/src/views/SkiaView.web.tsx +9 -11
  159. package/src/web/index.ts +3 -1
  160. package/lib/commonjs/skia/web/JsiImageFilterFactory.js.map +0 -1
  161. package/lib/commonjs/values/hooks/useDerivedValue.js +0 -25
  162. package/lib/commonjs/values/hooks/useDerivedValue.js.map +0 -1
  163. package/lib/commonjs/values/web/RNSkDerivedValue.js.map +0 -1
  164. package/lib/module/skia/web/JsiImageFilterFactory.js.map +0 -1
  165. package/lib/module/values/hooks/useDerivedValue.js +0 -14
  166. package/lib/module/values/hooks/useDerivedValue.js.map +0 -1
  167. package/lib/module/values/web/RNSkDerivedValue.js.map +0 -1
@@ -50,9 +50,9 @@ target_include_directories(
50
50
  ${PACKAGE_NAME}
51
51
  PRIVATE
52
52
 
53
- # When installed in the development environment
54
53
  "${NODE_MODULES_DIR}/react-native/ReactCommon/callinvoker"
55
54
  "${NODE_MODULES_DIR}/react-native/ReactCommon/jsi"
55
+ "${NODE_MODULES_DIR}/react-native/ReactCommon"
56
56
  "${NODE_MODULES_DIR}/react-native/ReactCommon/react/nativemodule/core"
57
57
  "${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni"
58
58
 
@@ -51,6 +51,13 @@ def defaultDir = null
51
51
  def androidSourcesDir = null
52
52
  def androidSourcesName = 'React Native sources'
53
53
 
54
+ def buildType = "debug"
55
+ tasks.all({ task ->
56
+ if (task.name == "buildCMakeRelease") {
57
+ buildType = "release"
58
+ }
59
+ })
60
+
54
61
  if (rootProject.ext.has('reactNativeAndroidRoot')) {
55
62
  defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
56
63
  androidSourcesDir = defaultDir.parentFile.toString()
@@ -81,6 +88,7 @@ def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME").split("\\
81
88
  logger.warn("react-native-skia: React Native version: ${REACT_NATIVE_VERSION}")
82
89
  logger.warn("react-native-skia: Is Source build: ${sourceBuild}")
83
90
  logger.warn("react-native-skia: Prebuilt dir: ${prebuiltDir}")
91
+ logger.warn("react-native-skia: Build type: ${buildType}")
84
92
 
85
93
  buildscript {
86
94
  // The Android Gradle plugin is only required when opening the android folder stand-alone.
@@ -175,8 +183,15 @@ dependencies {
175
183
  //noinspection GradleDynamicVersion
176
184
  extractJNI("com.facebook.fbjni:fbjni:0.2.2")
177
185
 
178
- def rnAAR = fileTree("${nodeModules}/react-native/android").matching({ it.include "**/**/*.aar" }).singleFile
179
- extractJNI(files(rnAAR))
186
+ if(REACT_NATIVE_VERSION < 69) {
187
+ def rnAAR = fileTree("${nodeModules}/react-native/android").matching({ it.include "**/**/*.aar" }).singleFile
188
+ extractJNI(files(rnAAR))
189
+ } else {
190
+ // React Native >= 0.69
191
+ def rnAarMatcher = "**/react-native/**/*${buildType}.aar"
192
+ def rnAAR = fileTree("${nodeModules}/react-native/android").matching({ it.include rnAarMatcher }).singleFile
193
+ extractJNI(files(rnAAR))
194
+ }
180
195
  }
181
196
 
182
197
  afterEvaluate { project ->
@@ -53,6 +53,11 @@ namespace RNSkia {
53
53
  }
54
54
 
55
55
  void RNSkDrawViewImpl::surfaceSizeChanged(int width, int height) {
56
+ if(width == 0 && height == 0) {
57
+ // Setting width/height to zero is nothing we need to care about when
58
+ // it comes to invalidating the surface.
59
+ return;
60
+ }
56
61
  _scaledWidth = width;
57
62
  _scaledHeight = height;
58
63
 
@@ -5,13 +5,15 @@
5
5
  #include <vector>
6
6
 
7
7
  #include <jsi/jsi.h>
8
-
9
8
  #include "JsiSkHostObjects.h"
9
+ #include <RNSkLog.h>
10
+
10
11
  #include "JsiSkPaint.h"
11
12
  #include "JsiSkRect.h"
12
13
  #include "JsiSkTypeface.h"
13
14
  #include "JsiSkPoint.h"
14
15
 
16
+
15
17
  #pragma clang diagnostic push
16
18
  #pragma clang diagnostic ignored "-Wdocumentation"
17
19
 
@@ -37,6 +39,7 @@ namespace RNSkia
37
39
 
38
40
  JSI_HOST_FUNCTION(measureText)
39
41
  {
42
+ RNSkLogger::warnToJavascriptConsole(runtime, "measureText() is deprecated. Clients should use 'Font.getGlyphWidths' instead (the latter does no shaping)");
40
43
  auto textVal = arguments[0].asString(runtime).utf8(runtime);
41
44
  auto text = textVal.c_str();
42
45
  SkRect rect;
@@ -252,6 +255,7 @@ namespace RNSkia
252
255
  }
253
256
 
254
257
  JSI_EXPORT_FUNCTIONS(
258
+ JSI_EXPORT_FUNC(JsiSkFont, getSize),
255
259
  JSI_EXPORT_FUNC(JsiSkFont, measureText),
256
260
  JSI_EXPORT_FUNC(JsiSkFont, getMetrics),
257
261
  JSI_EXPORT_FUNC(JsiSkFont, getGlyphIDs),
@@ -323,4 +327,4 @@ namespace RNSkia
323
327
  }
324
328
  };
325
329
 
326
- } // namespace RNSkia
330
+ } // namespace RNSkia
@@ -65,9 +65,7 @@ namespace RNSkia
65
65
  JSI_HOST_FUNCTION(encodeToBytes)
66
66
  {
67
67
  // Get optional parameters
68
- auto format = count >= 1 ? getFormatFromNumber(
69
- static_cast<int>(arguments[0].asNumber())) : SkEncodedImageFormat::kPNG;
70
-
68
+ auto format = count >= 1 ? static_cast<SkEncodedImageFormat>(arguments[0].asNumber()) : SkEncodedImageFormat::kPNG;
71
69
  auto quality = count == 2 ? arguments[1].asNumber() : 100.0;
72
70
 
73
71
  // Get data
@@ -89,8 +87,7 @@ namespace RNSkia
89
87
  JSI_HOST_FUNCTION(encodeToBase64)
90
88
  {
91
89
  // Get optional parameters
92
- auto format = count >= 1 ? getFormatFromNumber(
93
- static_cast<int>(arguments[0].asNumber())) : SkEncodedImageFormat::kPNG;
90
+ auto format = count >= 1 ? static_cast<SkEncodedImageFormat>(arguments[0].asNumber()) : SkEncodedImageFormat::kPNG;
94
91
 
95
92
  auto quality = count == 2 ? arguments[1].asNumber() : 100.0;
96
93
 
@@ -122,20 +119,6 @@ namespace RNSkia
122
119
  .asHostObject<JsiSkImage>(runtime)
123
120
  ->getObject();
124
121
  }
125
- private:
126
-
127
- SkEncodedImageFormat getFormatFromNumber(int value) {
128
- switch(value) {
129
- case 0: // PNG
130
- return SkEncodedImageFormat::kPNG;
131
- case 1: // JPEG
132
- return SkEncodedImageFormat::kJPEG;
133
- case 2: // WEBP
134
- return SkEncodedImageFormat::kWEBP;
135
- default:
136
- return SkEncodedImageFormat::kPNG;
137
- }
138
- }
139
122
  };
140
123
 
141
124
  } // namespace RNSkia
@@ -84,47 +84,20 @@ public:
84
84
  }
85
85
 
86
86
  JSI_HOST_FUNCTION(setStyle) {
87
- int styleInt = arguments[0].asNumber();
88
- switch (styleInt) {
89
- case 0:
90
- getObject()->setStyle(SkPaint::kFill_Style);
91
- break;
92
- case 1:
93
- getObject()->setStyle(SkPaint::kStroke_Style);
94
- break;
95
- }
87
+ auto style = arguments[0].asNumber();
88
+ getObject()->setStyle(static_cast<SkPaint::Style>(style));
96
89
  return jsi::Value::undefined();
97
90
  }
98
91
 
99
92
  JSI_HOST_FUNCTION(setStrokeCap) {
100
- int cap = arguments[0].asNumber();
101
- switch (cap) {
102
- case 0:
103
- getObject()->setStrokeCap(SkPaint::kButt_Cap);
104
- break;
105
- case 1:
106
- getObject()->setStrokeCap(SkPaint::kRound_Cap);
107
- break;
108
- case 2:
109
- getObject()->setStrokeCap(SkPaint::kSquare_Cap);
110
- break;
111
- }
93
+ auto cap = arguments[0].asNumber();
94
+ getObject()->setStrokeCap(static_cast<SkPaint::Cap>(cap));
112
95
  return jsi::Value::undefined();
113
96
  }
114
97
 
115
98
  JSI_HOST_FUNCTION(setStrokeJoin) {
116
99
  int join = arguments[0].asNumber();
117
- switch (join) {
118
- case 0:
119
- getObject()->setStrokeJoin(SkPaint::kBevel_Join);
120
- break;
121
- case 1:
122
- getObject()->setStrokeJoin(SkPaint::kMiter_Join);
123
- break;
124
- case 2:
125
- getObject()->setStrokeJoin(SkPaint::kRound_Join);
126
- break;
127
- }
100
+ getObject()->setStrokeJoin(static_cast<SkPaint::Join>(join));
128
101
  return jsi::Value::undefined();
129
102
  }
130
103
 
@@ -480,8 +480,8 @@ public:
480
480
  auto cmds = jsi::Array(runtime, path.countVerbs());
481
481
  auto it = SkPath::Iter(path, false);
482
482
  // { "Move", "Line", "Quad", "Conic", "Cubic", "Close", "Done" };
483
- const int pointCount[] = { 1 , 2 , 3 , 3 , 4 , 1 , 0 };
484
- const int cmdCount[] = { 3 , 5 , 7 , 8 , 9 , 3 , 0 };
483
+ const int pointCount[] = { 1 , 1 , 2 , 2 , 3 , 0 , 0 };
484
+ const int cmdCount[] = { 3 , 3 , 5 , 6 , 7 , 1 , 0 };
485
485
  SkPoint points[4];
486
486
  SkPath::Verb verb;
487
487
  auto k = 0;
@@ -491,8 +491,8 @@ public:
491
491
  auto j = 0;
492
492
  cmd.setValueAtIndex(runtime, j++, jsi::Value(verbVal));
493
493
  for (int i = 0; i < pointCount[verbVal]; ++i) {
494
- cmd.setValueAtIndex(runtime, j++, jsi::Value(static_cast<double>(points[i].fX)));
495
- cmd.setValueAtIndex(runtime, j++, jsi::Value(static_cast<double>(points[i].fY)));
494
+ cmd.setValueAtIndex(runtime, j++, jsi::Value(static_cast<double>(points[1 + i].fX)));
495
+ cmd.setValueAtIndex(runtime, j++, jsi::Value(static_cast<double>(points[1 + i].fY)));
496
496
  }
497
497
  if (SkPath::kConic_Verb == verb) {
498
498
  cmd.setValueAtIndex(runtime, j, jsi::Value(static_cast<double>(it.conicWeight())));
@@ -4,7 +4,7 @@
4
4
  #include <JsiHostObject.h>
5
5
  #include <RNSkPlatformContext.h>
6
6
  #include <RNSkValue.h>
7
- #include <RNSkDerivedValue.h>
7
+ #include <RNSkComputedValue.h>
8
8
  #include <RNSkAnimation.h>
9
9
  #include <jsi/jsi.h>
10
10
 
@@ -33,13 +33,13 @@ public:
33
33
  std::make_shared<RNSkValue>(_platformContext, runtime, arguments, count));
34
34
  }
35
35
 
36
- JSI_HOST_FUNCTION(createDerivedValue) {
36
+ JSI_HOST_FUNCTION(createComputedValue) {
37
37
  // Creation and initialization is done in two steps to be able to use weak references when setting
38
38
  // up dependencies - since weak_from_this needs our instance to be a shared_ptr before calling
39
39
  // weak_from_this().
40
- auto derivedValue = std::make_shared<RNSkDerivedValue>(_platformContext, runtime, arguments, count);
41
- derivedValue->initializeDependencies(runtime, arguments, count);
42
- return jsi::Object::createFromHostObject(runtime, derivedValue);
40
+ auto computedValue = std::make_shared<RNSkComputedValue>(_platformContext, runtime, arguments, count);
41
+ computedValue->initializeDependencies(runtime, arguments, count);
42
+ return jsi::Object::createFromHostObject(runtime, computedValue);
43
43
  }
44
44
 
45
45
  JSI_HOST_FUNCTION(createAnimation) {
@@ -61,7 +61,7 @@ public:
61
61
  }
62
62
 
63
63
  JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(RNSkValueApi, createValue),
64
- JSI_EXPORT_FUNC(RNSkValueApi, createDerivedValue),
64
+ JSI_EXPORT_FUNC(RNSkValueApi, createComputedValue),
65
65
  JSI_EXPORT_FUNC(RNSkValueApi, createClockValue),
66
66
  JSI_EXPORT_FUNC(RNSkValueApi, createAnimation))
67
67
 
@@ -19,13 +19,13 @@ using namespace facebook;
19
19
  Creates a readonly value that depends on one or more other values. The derived value has a callback
20
20
  function that is used to calculate the new value when any of the dependencies change.
21
21
  */
22
- class RNSkDerivedValue : public RNSkReadonlyValue
22
+ class RNSkComputedValue : public RNSkReadonlyValue
23
23
  {
24
24
  public:
25
- RNSkDerivedValue(std::shared_ptr<RNSkPlatformContext> platformContext,
26
- jsi::Runtime &runtime,
27
- const jsi::Value *arguments,
28
- size_t count
25
+ RNSkComputedValue(std::shared_ptr<RNSkPlatformContext> platformContext,
26
+ jsi::Runtime &runtime,
27
+ const jsi::Value *arguments,
28
+ size_t count
29
29
  )
30
30
  : RNSkReadonlyValue(platformContext) {
31
31
  // Verify input
@@ -70,7 +70,7 @@ public:
70
70
  _unsubscribers.push_back(dep->addListener([weakSelf = weak_from_this()](jsi::Runtime& runtime) {
71
71
  auto self = weakSelf.lock();
72
72
  if(self) {
73
- auto selfAsThis = std::dynamic_pointer_cast<RNSkDerivedValue>(self);
73
+ auto selfAsThis = std::dynamic_pointer_cast<RNSkComputedValue>(self);
74
74
  selfAsThis->dependencyUpdated(runtime);
75
75
  }
76
76
  }));
@@ -80,7 +80,7 @@ public:
80
80
  dependencyUpdated(runtime);
81
81
  }
82
82
 
83
- virtual ~RNSkDerivedValue() {
83
+ virtual ~RNSkComputedValue() {
84
84
  // Unregister listeners
85
85
  for(const auto &unsubscribe: _unsubscribers) {
86
86
  unsubscribe();
@@ -5,6 +5,8 @@
5
5
  #pragma once
6
6
 
7
7
  #include <string>
8
+ #include <jsi/jsi.h>
9
+
8
10
  #ifdef ANDROID
9
11
  #include <android/log.h>
10
12
  #endif
@@ -14,6 +16,9 @@
14
16
  #endif
15
17
 
16
18
  namespace RNSkia {
19
+
20
+ using namespace facebook;
21
+
17
22
  class RNSkLogger {
18
23
  public:
19
24
  /**
@@ -34,7 +34,7 @@
34
34
  if (cxxBridge.runtime) {
35
35
 
36
36
  auto callInvoker = bridge.jsCallInvoker;
37
- jsi::Runtime* jsRuntime = (jsi::Runtime*)cxxBridge.runtime;
37
+ facebook::jsi::Runtime* jsRuntime = (facebook::jsi::Runtime*)cxxBridge.runtime;
38
38
 
39
39
  // Create platform context
40
40
  _platformContext = std::make_shared<RNSkia::PlatformContext>(jsRuntime, callInvoker);
@@ -0,0 +1,190 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.vec = exports.useValueEffect = exports.useValue = exports.useTypeface = exports.useTouchHandler = exports.useTiming = exports.useSpring = exports.useSharedValueEffect = exports.useSVG = exports.usePicture = exports.useImage = exports.useFont = exports.useDataCollection = exports.useData = exports.useComputedValue = exports.useClockValue = exports.timing = exports.spring = exports.runTiming = exports.runSpring = exports.runDecay = exports.rrect = exports.rect = exports.decay = exports.Skia = void 0;
7
+
8
+ /**
9
+ * Mock implementation for test runners.
10
+ *
11
+ * Example:
12
+ *
13
+ * ```js
14
+ * jest.mock('@shopify/react-native-skia', () => require('@shopify/react-native-skia/lib/commonjs/mock'));
15
+ * ```
16
+ */
17
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
+ const MockJSIInstance = {};
19
+
20
+ const Noop = () => MockJSIInstance;
21
+
22
+ const Skia = {
23
+ Point: Noop,
24
+ XYWHRect: Noop,
25
+ RuntimeShaderBuilder: Noop,
26
+ RRectXY: Noop,
27
+ RSXform: Noop,
28
+ Color: Noop,
29
+ ContourMeasureIter: Noop,
30
+ Paint: Noop,
31
+ PictureRecorder: Noop,
32
+ Picture: {
33
+ MakePicture: Noop
34
+ },
35
+ Path: {
36
+ Make: Noop,
37
+ MakeFromSVGString: Noop,
38
+ MakeFromOp: Noop,
39
+ MakeFromCmds: Noop,
40
+ MakeFromText: Noop
41
+ },
42
+ Matrix: Noop,
43
+ ColorFilter: {
44
+ MakeMatrix: Noop,
45
+ MakeBlend: Noop,
46
+ MakeCompose: Noop,
47
+ MakeLerp: Noop,
48
+ MakeLinearToSRGBGamma: Noop,
49
+ MakeSRGBToLinearGamma: Noop,
50
+ MakeLumaColorFilter: Noop
51
+ },
52
+ Font: Noop,
53
+ Typeface: {
54
+ MakeFreeTypeFaceFromData: Noop
55
+ },
56
+ MaskFilter: {
57
+ MakeBlur: Noop
58
+ },
59
+ RuntimeEffect: {
60
+ Make: Noop
61
+ },
62
+ ImageFilter: {
63
+ MakeOffset: Noop,
64
+ MakeDisplacementMap: Noop,
65
+ MakeShader: Noop,
66
+ MakeBlur: Noop,
67
+ MakeColorFilter: Noop,
68
+ MakeCompose: Noop,
69
+ MakeDropShadow: Noop,
70
+ MakeDropShadowOnly: Noop,
71
+ MakeErode: Noop,
72
+ MakeDilate: Noop,
73
+ MakeBlend: Noop,
74
+ MakeRuntimeShader: Noop
75
+ },
76
+ Shader: {
77
+ MakeLinearGradient: Noop,
78
+ MakeRadialGradient: Noop,
79
+ MakeTwoPointConicalGradient: Noop,
80
+ MakeSweepGradient: Noop,
81
+ MakeTurbulence: Noop,
82
+ MakeFractalNoise: Noop,
83
+ MakeBlend: Noop,
84
+ MakeColor: Noop
85
+ },
86
+ PathEffect: {
87
+ MakeCorner: Noop,
88
+ MakeDash: Noop,
89
+ MakeDiscrete: Noop,
90
+ MakeCompose: Noop,
91
+ MakeSum: Noop,
92
+ MakeLine2D: Noop,
93
+ MakePath1D: Noop,
94
+ MakePath2D: Noop
95
+ },
96
+ MakeVertices: Noop,
97
+ Data: {
98
+ fromURI: Noop,
99
+ fromBytes: Noop,
100
+ fromBase64: Noop
101
+ },
102
+ Image: {
103
+ MakeImageFromEncoded: Noop,
104
+ MakeImage: Noop
105
+ },
106
+ SVG: {
107
+ MakeFromData: Noop,
108
+ MakeFromString: Noop
109
+ },
110
+ FontMgr: {
111
+ RefDefault: Noop
112
+ },
113
+ TextBlob: {
114
+ MakeFromText: Noop,
115
+ MakeFromGlyphs: Noop,
116
+ MakeFromRSXform: Noop,
117
+ MakeFromRSXformGlyphs: Noop
118
+ },
119
+ Surface: {
120
+ Make: Noop
121
+ }
122
+ };
123
+ exports.Skia = Skia;
124
+
125
+ const vec = (x, y) => ({
126
+ x,
127
+ y
128
+ });
129
+
130
+ exports.vec = vec;
131
+
132
+ const rect = (x, y, width, height) => ({
133
+ x,
134
+ y,
135
+ width,
136
+ height
137
+ });
138
+
139
+ exports.rect = rect;
140
+
141
+ const rrect = (r, rx, ry) => ({
142
+ rect: r,
143
+ rx,
144
+ ry
145
+ });
146
+
147
+ exports.rrect = rrect;
148
+ const useTouchHandler = Noop;
149
+ exports.useTouchHandler = useTouchHandler;
150
+ const useComputedValue = Noop;
151
+ exports.useComputedValue = useComputedValue;
152
+ const useValue = Noop;
153
+ exports.useValue = useValue;
154
+ const useClockValue = Noop;
155
+ exports.useClockValue = useClockValue;
156
+ const useValueEffect = Noop;
157
+ exports.useValueEffect = useValueEffect;
158
+ const useTiming = Noop;
159
+ exports.useTiming = useTiming;
160
+ const runTiming = Noop;
161
+ exports.runTiming = runTiming;
162
+ const timing = Noop;
163
+ exports.timing = timing;
164
+ const useSpring = Noop;
165
+ exports.useSpring = useSpring;
166
+ const runSpring = Noop;
167
+ exports.runSpring = runSpring;
168
+ const spring = Noop;
169
+ exports.spring = spring;
170
+ const runDecay = Noop;
171
+ exports.runDecay = runDecay;
172
+ const decay = Noop;
173
+ exports.decay = decay;
174
+ const useSharedValueEffect = Noop;
175
+ exports.useSharedValueEffect = useSharedValueEffect;
176
+ const useData = Noop;
177
+ exports.useData = useData;
178
+ const useDataCollection = Noop;
179
+ exports.useDataCollection = useDataCollection;
180
+ const useFont = Noop;
181
+ exports.useFont = useFont;
182
+ const useImage = Noop;
183
+ exports.useImage = useImage;
184
+ const usePicture = Noop;
185
+ exports.usePicture = usePicture;
186
+ const useSVG = Noop;
187
+ exports.useSVG = useSVG;
188
+ const useTypeface = Noop;
189
+ exports.useTypeface = useTypeface;
190
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.ts"],"names":["MockJSIInstance","Noop","Skia","Point","XYWHRect","RuntimeShaderBuilder","RRectXY","RSXform","Color","ContourMeasureIter","Paint","PictureRecorder","Picture","MakePicture","Path","Make","MakeFromSVGString","MakeFromOp","MakeFromCmds","MakeFromText","Matrix","ColorFilter","MakeMatrix","MakeBlend","MakeCompose","MakeLerp","MakeLinearToSRGBGamma","MakeSRGBToLinearGamma","MakeLumaColorFilter","Font","Typeface","MakeFreeTypeFaceFromData","MaskFilter","MakeBlur","RuntimeEffect","ImageFilter","MakeOffset","MakeDisplacementMap","MakeShader","MakeColorFilter","MakeDropShadow","MakeDropShadowOnly","MakeErode","MakeDilate","MakeRuntimeShader","Shader","MakeLinearGradient","MakeRadialGradient","MakeTwoPointConicalGradient","MakeSweepGradient","MakeTurbulence","MakeFractalNoise","MakeColor","PathEffect","MakeCorner","MakeDash","MakeDiscrete","MakeSum","MakeLine2D","MakePath1D","MakePath2D","MakeVertices","Data","fromURI","fromBytes","fromBase64","Image","MakeImageFromEncoded","MakeImage","SVG","MakeFromData","MakeFromString","FontMgr","RefDefault","TextBlob","MakeFromGlyphs","MakeFromRSXform","MakeFromRSXformGlyphs","Surface","vec","x","y","rect","width","height","rrect","r","rx","ry","useTouchHandler","useComputedValue","useValue","useClockValue","useValueEffect","useTiming","runTiming","timing","useSpring","runSpring","spring","runDecay","decay","useSharedValueEffect","useData","useDataCollection","useFont","useImage","usePicture","useSVG","useTypeface"],"mappings":"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","sourcesContent":["/**\n * Mock implementation for test runners.\n *\n * Example:\n *\n * ```js\n * jest.mock('@shopify/react-native-skia', () => require('@shopify/react-native-skia/lib/commonjs/mock'));\n * ```\n */\n\nimport type { Skia as SkiaApi, SkRect } from \"../skia/types\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst MockJSIInstance: any = {};\nconst Noop = () => MockJSIInstance;\n\nexport const Skia: SkiaApi = {\n Point: Noop,\n XYWHRect: Noop,\n RuntimeShaderBuilder: Noop,\n RRectXY: Noop,\n RSXform: Noop,\n Color: Noop,\n ContourMeasureIter: Noop,\n Paint: Noop,\n PictureRecorder: Noop,\n Picture: {\n MakePicture: Noop,\n },\n Path: {\n Make: Noop,\n MakeFromSVGString: Noop,\n MakeFromOp: Noop,\n MakeFromCmds: Noop,\n MakeFromText: Noop,\n },\n Matrix: Noop,\n ColorFilter: {\n MakeMatrix: Noop,\n MakeBlend: Noop,\n MakeCompose: Noop,\n MakeLerp: Noop,\n MakeLinearToSRGBGamma: Noop,\n MakeSRGBToLinearGamma: Noop,\n MakeLumaColorFilter: Noop,\n },\n Font: Noop,\n Typeface: {\n MakeFreeTypeFaceFromData: Noop,\n },\n MaskFilter: {\n MakeBlur: Noop,\n },\n RuntimeEffect: {\n Make: Noop,\n },\n ImageFilter: {\n MakeOffset: Noop,\n MakeDisplacementMap: Noop,\n MakeShader: Noop,\n MakeBlur: Noop,\n MakeColorFilter: Noop,\n MakeCompose: Noop,\n MakeDropShadow: Noop,\n MakeDropShadowOnly: Noop,\n MakeErode: Noop,\n MakeDilate: Noop,\n MakeBlend: Noop,\n MakeRuntimeShader: Noop,\n },\n Shader: {\n MakeLinearGradient: Noop,\n MakeRadialGradient: Noop,\n MakeTwoPointConicalGradient: Noop,\n MakeSweepGradient: Noop,\n MakeTurbulence: Noop,\n MakeFractalNoise: Noop,\n MakeBlend: Noop,\n MakeColor: Noop,\n },\n PathEffect: {\n MakeCorner: Noop,\n MakeDash: Noop,\n MakeDiscrete: Noop,\n MakeCompose: Noop,\n MakeSum: Noop,\n MakeLine2D: Noop,\n MakePath1D: Noop,\n MakePath2D: Noop,\n },\n MakeVertices: Noop,\n Data: {\n fromURI: Noop,\n fromBytes: Noop,\n fromBase64: Noop,\n },\n Image: {\n MakeImageFromEncoded: Noop,\n MakeImage: Noop,\n },\n SVG: {\n MakeFromData: Noop,\n MakeFromString: Noop,\n },\n FontMgr: {\n RefDefault: Noop,\n },\n TextBlob: {\n MakeFromText: Noop,\n MakeFromGlyphs: Noop,\n MakeFromRSXform: Noop,\n MakeFromRSXformGlyphs: Noop,\n },\n Surface: {\n Make: Noop,\n },\n};\n\nexport const vec = (x: number, y: number) => ({ x, y });\n\nexport const rect = (x: number, y: number, width: number, height: number) => ({\n x,\n y,\n width,\n height,\n});\n\nexport const rrect = (r: SkRect, rx: number, ry: number) => ({\n rect: r,\n rx,\n ry,\n});\n\nexport const useTouchHandler = Noop;\nexport const useComputedValue = Noop;\nexport const useValue = Noop;\nexport const useClockValue = Noop;\nexport const useValueEffect = Noop;\nexport const useTiming = Noop;\nexport const runTiming = Noop;\nexport const timing = Noop;\nexport const useSpring = Noop;\nexport const runSpring = Noop;\nexport const spring = Noop;\nexport const runDecay = Noop;\nexport const decay = Noop;\n\nexport const useSharedValueEffect = Noop;\n\nexport const useData = Noop;\nexport const useDataCollection = Noop;\nexport const useFont = Noop;\nexport const useImage = Noop;\nexport const usePicture = Noop;\nexport const useSVG = Noop;\nexport const useTypeface = Noop;\n"]}
@@ -15,65 +15,55 @@ const resolveAsset = source => {
15
15
  return _reactNative.Platform.OS === "web" ? source.default : _reactNative.Image.resolveAssetSource(source).uri;
16
16
  };
17
17
 
18
- const useDataCollection = function (sources, factory) {
19
- let deps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
20
- const [data, setData] = (0, _react.useState)(null);
21
- (0, _react.useEffect)(() => {
22
- const bytesOrURIs = sources.map(source => {
23
- if (source instanceof Uint8Array) {
24
- return source;
25
- }
26
-
27
- return typeof source === "string" ? source : resolveAsset(source);
28
- });
29
- Promise.all(bytesOrURIs.map(bytesOrURI => bytesOrURI instanceof Uint8Array ? _Skia.Skia.Data.fromBytes(bytesOrURI) : _Skia.Skia.Data.fromURI(bytesOrURI))).then(d => setData(factory(d))); // eslint-disable-next-line react-hooks/exhaustive-deps
30
- }, deps);
31
- return data;
18
+ const factoryWrapper = (data2, factory, onError) => {
19
+ const factoryResult = factory(data2);
20
+
21
+ if (factoryResult === null) {
22
+ onError && onError(new Error("Could not load data"));
23
+ return null;
24
+ } else {
25
+ return factoryResult;
26
+ }
32
27
  };
33
28
 
34
- exports.useDataCollection = useDataCollection;
29
+ const loadDataCollection = (sources, factory, onError) => Promise.all(sources.map(source => loadData(source, factory, onError)));
30
+
31
+ const loadData = (source, factory, onError) => {
32
+ if (source instanceof Uint8Array) {
33
+ return new Promise(resolve => resolve(factoryWrapper(_Skia.Skia.Data.fromBytes(source), factory, onError)));
34
+ } else {
35
+ const uri = typeof source === "string" ? source : resolveAsset(source);
36
+ return _Skia.Skia.Data.fromURI(uri).then(d => factoryWrapper(d, factory, onError));
37
+ }
38
+ };
35
39
 
36
- const useRawData = (source, factory, onError) => {
40
+ const useLoading = function (source, loader) {
41
+ let deps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
37
42
  const [data, setData] = (0, _react.useState)(null);
38
43
  const prevSourceRef = (0, _react.useRef)();
39
44
  (0, _react.useEffect)(() => {
40
- // Track to avoid re-fetching the same data
41
45
  if (prevSourceRef.current !== source) {
42
46
  prevSourceRef.current = source;
47
+ loader().then(setData);
48
+ } else {
49
+ setData(null);
50
+ } // eslint-disable-next-line react-hooks/exhaustive-deps
43
51
 
44
- if (source !== null && source !== undefined) {
45
- const factoryWrapper = data2 => {
46
- const factoryResult = factory(data2);
47
-
48
- if (factoryResult === null) {
49
- onError && onError(new Error("Could not load data"));
50
- setData(null);
51
- } else {
52
- setData(factoryResult);
53
- }
54
- };
55
-
56
- if (source instanceof Uint8Array) {
57
- factoryWrapper(_Skia.Skia.Data.fromBytes(source));
58
- } else {
59
- const uri = typeof source === "string" ? source : resolveAsset(source);
60
-
61
- _Skia.Skia.Data.fromURI(uri).then(d => factoryWrapper(d));
62
- }
63
- } else {
64
- // new source is null or undefined -> remove cached data
65
- setData(null);
66
- }
67
- }
68
- }, [factory, onError, source]);
52
+ }, deps);
69
53
  return data;
70
54
  };
71
55
 
56
+ const useDataCollection = (sources, factory, onError, deps) => useLoading(sources, () => loadDataCollection(sources, factory, onError), deps);
57
+
58
+ exports.useDataCollection = useDataCollection;
59
+
60
+ const useRawData = (source, factory, onError, deps) => useLoading(source, () => loadData(source, factory, onError), deps);
61
+
72
62
  exports.useRawData = useRawData;
73
63
 
74
64
  const identity = data => data;
75
65
 
76
- const useData = (source, onError) => useRawData(source, identity, onError);
66
+ const useData = (source, onError, deps) => useRawData(source, identity, onError, deps);
77
67
 
78
68
  exports.useData = useData;
79
69
  //# sourceMappingURL=Data.js.map