@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
@@ -4,32 +4,32 @@
4
4
  #include <memory>
5
5
  #include <mutex>
6
6
  #include <string>
7
+ #include <unordered_map>
7
8
  #include <vector>
8
9
 
9
10
  #include <JsiHostObject.h>
10
11
  #include <JsiValueWrapper.h>
11
- #include <RNSkView.h>
12
12
  #include <RNSkPlatformContext.h>
13
13
  #include <RNSkValue.h>
14
+ #include <RNSkView.h>
14
15
  #include <jsi/jsi.h>
15
16
 
16
17
  namespace RNSkia {
17
- using namespace facebook;
18
+ namespace jsi = facebook::jsi;
18
19
 
19
20
  using RNSkViewInfo = struct RNSkViewInfo {
20
- RNSkViewInfo() {
21
- view = nullptr;
22
- }
21
+ RNSkViewInfo() { view = nullptr; }
23
22
  std::shared_ptr<RNSkView> view;
24
- std::unordered_map<std::string, JsiValueWrapper> props;
23
+ std::unordered_map<std::string, RNJsi::JsiValueWrapper> props;
25
24
  };
26
25
 
27
- class RNSkJsiViewApi : public JsiHostObject, public std::enable_shared_from_this<RNSkJsiViewApi> {
26
+ class RNSkJsiViewApi : public RNJsi::JsiHostObject,
27
+ public std::enable_shared_from_this<RNSkJsiViewApi> {
28
28
  public:
29
29
  /**
30
- Sets a custom property on a view given a view id. The property name/value will
31
- be stored in a map alongside the id of the view and propagated to the view when
32
- needed.
30
+ Sets a custom property on a view given a view id. The property name/value
31
+ will be stored in a map alongside the id of the view and propagated to the
32
+ view when needed.
33
33
  */
34
34
  JSI_HOST_FUNCTION(setJsiProperty) {
35
35
  if (count != 3) {
@@ -46,8 +46,8 @@ public:
46
46
  }
47
47
 
48
48
  if (!arguments[1].isString()) {
49
- _platformContext->raiseError(
50
- "setJsiProperty: Second argument must be the name of the property to set.");
49
+ _platformContext->raiseError("setJsiProperty: Second argument must be "
50
+ "the name of the property to set.");
51
51
 
52
52
  return jsi::Value::undefined();
53
53
  }
@@ -55,10 +55,11 @@ public:
55
55
  auto info = getEnsuredViewInfo(nativeId);
56
56
 
57
57
  std::lock_guard<std::mutex> lock(_mutex);
58
- info->props.emplace(arguments[1].asString(runtime).utf8(runtime), JsiValueWrapper(runtime, arguments[2]));
58
+ info->props.emplace(arguments[1].asString(runtime).utf8(runtime),
59
+ RNJsi::JsiValueWrapper(runtime, arguments[2]));
59
60
 
60
61
  // Now let's see if we have a view that we can update
61
- if(info->view != nullptr) {
62
+ if (info->view != nullptr) {
62
63
  // Update view!
63
64
  info->view->setNativeId(nativeId);
64
65
  info->view->setJsiProperties(info->props);
@@ -88,8 +89,8 @@ public:
88
89
  }
89
90
 
90
91
  if (!arguments[1].isString()) {
91
- _platformContext->raiseError(
92
- "callCustomCommand: Second argument must be the name of the action to call.");
92
+ _platformContext->raiseError("callCustomCommand: Second argument must be "
93
+ "the name of the action to call.");
93
94
 
94
95
  return jsi::Value::undefined();
95
96
  }
@@ -99,53 +100,58 @@ public:
99
100
 
100
101
  auto info = getEnsuredViewInfo(nativeId);
101
102
 
102
- if(info->view == nullptr) {
103
- throw jsi::JSError(runtime,
104
- std::string("callCustomCommand: Could not call action " + action +
105
- " on view - view not ready.").c_str());
103
+ if (info->view == nullptr) {
104
+ throw jsi::JSError(
105
+ runtime, std::string("callCustomCommand: Could not call action " +
106
+ action + " on view - view not ready.")
107
+ .c_str());
106
108
 
107
109
  return jsi::Value::undefined();
108
110
  }
109
111
 
110
112
  // Get arguments
111
113
  size_t paramsCount = count - 2;
112
- const jsi::Value* params = paramsCount > 0 ? &arguments[2] : nullptr;
114
+ const jsi::Value *params = paramsCount > 0 ? &arguments[2] : nullptr;
113
115
  return info->view->callJsiMethod(runtime, action, params, paramsCount);
114
116
  }
115
117
 
116
118
  JSI_HOST_FUNCTION(requestRedraw) {
117
119
  if (count != 1) {
118
- _platformContext->raiseError(
119
- std::string("requestRedraw: Expected 1 arguments, got " + std::to_string(count) + "."));
120
+ _platformContext->raiseError(
121
+ std::string("requestRedraw: Expected 1 arguments, got " +
122
+ std::to_string(count) + "."));
120
123
 
121
- return jsi::Value::undefined();
122
- }
124
+ return jsi::Value::undefined();
125
+ }
123
126
 
124
- if (!arguments[0].isNumber()) {
125
- _platformContext->raiseError(
126
- "requestRedraw: First argument must be a number");
127
+ if (!arguments[0].isNumber()) {
128
+ _platformContext->raiseError(
129
+ "requestRedraw: First argument must be a number");
127
130
 
128
- return jsi::Value::undefined();
129
- }
131
+ return jsi::Value::undefined();
132
+ }
130
133
 
131
- // find Skia View
132
- int nativeId = arguments[0].asNumber();
134
+ // find Skia View
135
+ int nativeId = arguments[0].asNumber();
133
136
 
134
- auto info = getEnsuredViewInfo(nativeId);
135
- if (info->view != nullptr) {
136
- info->view->requestRedraw();
137
- }
138
- return jsi::Value::undefined();
137
+ auto info = getEnsuredViewInfo(nativeId);
138
+ if (info->view != nullptr) {
139
+ info->view->requestRedraw();
140
+ }
141
+ return jsi::Value::undefined();
139
142
  }
140
143
 
141
144
  JSI_HOST_FUNCTION(makeImageSnapshot) {
142
145
  if (count < 1) {
143
- _platformContext->raiseError(std::string("makeImageSnapshot: Expected at least 1 argument, got " + std::to_string(count) + "."));
146
+ _platformContext->raiseError(
147
+ std::string("makeImageSnapshot: Expected at least 1 argument, got " +
148
+ std::to_string(count) + "."));
144
149
  return jsi::Value::undefined();
145
150
  }
146
151
 
147
152
  if (!arguments[0].isNumber()) {
148
- _platformContext->raiseError("makeImageSnapshot: First argument must be a number");
153
+ _platformContext->raiseError(
154
+ "makeImageSnapshot: First argument must be a number");
149
155
  return jsi::Value::undefined();
150
156
  }
151
157
 
@@ -154,68 +160,74 @@ public:
154
160
  sk_sp<SkImage> image;
155
161
  auto info = getEnsuredViewInfo(nativeId);
156
162
  if (info->view != nullptr) {
157
- if(count > 1 && !arguments[1].isUndefined() && !arguments[1].isNull()) {
163
+ if (count > 1 && !arguments[1].isUndefined() && !arguments[1].isNull()) {
158
164
  auto rect = JsiSkRect::fromValue(runtime, arguments[1]);
159
165
  image = info->view->makeImageSnapshot(rect);
160
166
  } else {
161
167
  image = info->view->makeImageSnapshot(nullptr);
162
168
  }
163
- if(image == nullptr) {
164
- throw jsi::JSError(runtime, "Could not create image from current surface.");
169
+ if (image == nullptr) {
170
+ throw jsi::JSError(runtime,
171
+ "Could not create image from current surface.");
165
172
  return jsi::Value::undefined();
166
173
  }
167
- return jsi::Object::createFromHostObject(runtime, std::make_shared<JsiSkImage>(_platformContext, image));
174
+ return jsi::Object::createFromHostObject(
175
+ runtime, std::make_shared<JsiSkImage>(_platformContext, image));
168
176
  }
169
177
  throw jsi::JSError(runtime, "No Skia View currently available.");
170
178
  return jsi::Value::undefined();
171
179
  }
172
180
 
173
181
  JSI_HOST_FUNCTION(registerValuesInView) {
174
- // Check params
175
- if(!arguments[1].isObject() || !arguments[1].asObject(runtime).isArray(runtime)) {
176
- throw jsi::JSError(runtime, "Expected array of Values as second parameter");
177
- return jsi::Value::undefined();
178
- }
182
+ // Check params
183
+ if (!arguments[1].isObject() ||
184
+ !arguments[1].asObject(runtime).isArray(runtime)) {
185
+ throw jsi::JSError(runtime,
186
+ "Expected array of Values as second parameter");
187
+ return jsi::Value::undefined();
188
+ }
189
+
190
+ // Get identifier of native SkiaView
191
+ int nativeId = arguments[0].asNumber();
179
192
 
180
- // Get identifier of native SkiaView
181
- int nativeId = arguments[0].asNumber();
182
-
183
- // Get values that should be added as dependencies
184
- auto values = arguments[1].asObject(runtime).asArray(runtime);
185
- std::vector<std::function<void()>> unsubscribers;
186
- const std::size_t size = values.size(runtime);
187
- unsubscribers.reserve(size);
188
- for(size_t i=0; i<size; ++i) {
189
- auto value = values.getValueAtIndex(runtime, i).asObject(runtime).asHostObject<RNSkReadonlyValue>(runtime);
190
-
191
- if(value != nullptr) {
192
- // Add change listener
193
- unsubscribers.push_back(value->addListener([weakSelf = weak_from_this(), nativeId](jsi::Runtime&){
194
- auto self = weakSelf.lock();
195
- if(self) {
196
- auto info = self->getEnsuredViewInfo(nativeId);
197
- if(info->view != nullptr) {
198
- info->view->requestRedraw();
193
+ // Get values that should be added as dependencies
194
+ auto values = arguments[1].asObject(runtime).asArray(runtime);
195
+ std::vector<std::function<void()>> unsubscribers;
196
+ const std::size_t size = values.size(runtime);
197
+ unsubscribers.reserve(size);
198
+ for (size_t i = 0; i < size; ++i) {
199
+ auto value = values.getValueAtIndex(runtime, i)
200
+ .asObject(runtime)
201
+ .asHostObject<RNSkReadonlyValue>(runtime);
202
+
203
+ if (value != nullptr) {
204
+ // Add change listener
205
+ unsubscribers.push_back(value->addListener(
206
+ [weakSelf = weak_from_this(), nativeId](jsi::Runtime &) {
207
+ auto self = weakSelf.lock();
208
+ if (self) {
209
+ auto info = self->getEnsuredViewInfo(nativeId);
210
+ if (info->view != nullptr) {
211
+ info->view->requestRedraw();
212
+ }
199
213
  }
200
- }
201
- }));
202
- }
214
+ }));
203
215
  }
204
-
205
- // Return unsubscribe method that unsubscribes to all values
206
- // that we subscribed to.
207
- return jsi::Function::createFromHostFunction(runtime,
208
- jsi::PropNameID::forUtf8(runtime, "unsubscribe"),
209
- 0,
210
- JSI_HOST_FUNCTION_LAMBDA {
211
- // decrease dependency count on the Skia View
212
- for(auto &unsub : unsubscribers) {
213
- unsub();
214
- }
215
- return jsi::Value::undefined();
216
- });
217
216
  }
218
217
 
218
+ // Return unsubscribe method that unsubscribes to all values
219
+ // that we subscribed to.
220
+ return jsi::Function::createFromHostFunction(
221
+ runtime, jsi::PropNameID::forUtf8(runtime, "unsubscribe"), 0,
222
+ JSI_HOST_FUNCTION_LAMBDA {
223
+ // decrease dependency count on the Skia View
224
+ for (auto &unsub : unsubscribers) {
225
+ unsub();
226
+ }
227
+ return jsi::Value::undefined();
228
+ });
229
+ }
230
+
219
231
  JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(RNSkJsiViewApi, setJsiProperty),
220
232
  JSI_EXPORT_FUNC(RNSkJsiViewApi, callJsiMethod),
221
233
  JSI_EXPORT_FUNC(RNSkJsiViewApi, registerValuesInView),
@@ -226,15 +238,13 @@ public:
226
238
  * Constructor
227
239
  * @param platformContext Platform context
228
240
  */
229
- RNSkJsiViewApi(std::shared_ptr<RNSkPlatformContext> platformContext)
241
+ explicit RNSkJsiViewApi(std::shared_ptr<RNSkPlatformContext> platformContext)
230
242
  : JsiHostObject(), _platformContext(platformContext) {}
231
243
 
232
244
  /**
233
245
  * Invalidates the Skia View Api object
234
246
  */
235
- void invalidate() {
236
- unregisterAll();
237
- }
247
+ void invalidate() { unregisterAll(); }
238
248
 
239
249
  /**
240
250
  Call to remove all draw view infos
@@ -242,7 +252,7 @@ public:
242
252
  void unregisterAll() {
243
253
  // Unregister all views
244
254
  auto tempList = _viewInfos;
245
- for (const auto& info : tempList) {
255
+ for (const auto &info : tempList) {
246
256
  unregisterSkiaView(info.first);
247
257
  }
248
258
  std::lock_guard<std::mutex> lock(_mutex);
@@ -295,7 +305,7 @@ public:
295
305
  info->view->setNativeId(nativeId);
296
306
  info->view->setJsiProperties(info->props);
297
307
  info->props.clear();
298
- } else if(view == nullptr) {
308
+ } else if (view == nullptr) {
299
309
  info->view = view;
300
310
  }
301
311
  }
@@ -7,11 +7,11 @@
7
7
 
8
8
  #include <JsiSkApi.h>
9
9
  #include <RNSkJsiViewApi.h>
10
- #include <RNSkView.h>
11
10
  #include <RNSkValueApi.h>
11
+ #include <RNSkView.h>
12
12
 
13
13
  namespace RNSkia {
14
- using namespace facebook;
14
+ namespace jsi = facebook::jsi;
15
15
 
16
16
  RNSkManager::RNSkManager(
17
17
  jsi::Runtime *jsRuntime,
@@ -35,17 +35,18 @@ RNSkManager::~RNSkManager() {
35
35
  }
36
36
 
37
37
  void RNSkManager::invalidate() {
38
- if(_isInvalidated) {
38
+ if (_isInvalidated) {
39
39
  return;
40
40
  }
41
41
  _isInvalidated = true;
42
-
42
+
43
43
  // Invalidate members
44
44
  _viewApi->invalidate();
45
45
  _platformContext->invalidate();
46
46
  }
47
47
 
48
- void RNSkManager::registerSkiaView(size_t nativeId, std::shared_ptr<RNSkView> view) {
48
+ void RNSkManager::registerSkiaView(size_t nativeId,
49
+ std::shared_ptr<RNSkView> view) {
49
50
  if (!_isInvalidated && _viewApi != nullptr)
50
51
  _viewApi->registerSkiaView(nativeId, view);
51
52
  }
@@ -75,7 +76,7 @@ void RNSkManager::installBindings() {
75
76
 
76
77
  auto skiaValueApi = std::make_shared<RNSkValueApi>(_platformContext);
77
78
  _jsRuntime->global().setProperty(
78
- *_jsRuntime, "SkiaValueApi",
79
- jsi::Object::createFromHostObject(*_jsRuntime, std::move(skiaValueApi)));
79
+ *_jsRuntime, "SkiaValueApi",
80
+ jsi::Object::createFromHostObject(*_jsRuntime, std::move(skiaValueApi)));
80
81
  }
81
82
  } // namespace RNSkia
@@ -6,15 +6,17 @@
6
6
  #include "RNSkPlatformContext.h"
7
7
 
8
8
  namespace facebook {
9
- namespace react {
10
- class CallInvoker;
11
- }
9
+ namespace react {
10
+ class CallInvoker;
12
11
  }
12
+ } // namespace facebook
13
13
 
14
14
  namespace RNSkia {
15
15
  class RNSkView;
16
16
  class RNSkJsiViewApi;
17
- using namespace facebook;
17
+
18
+ namespace jsi = facebook::jsi;
19
+ namespace react = facebook::react;
18
20
 
19
21
  class RNSkManager {
20
22
  public:
@@ -30,7 +32,7 @@ public:
30
32
  std::shared_ptr<RNSkPlatformContext> platformContext);
31
33
 
32
34
  ~RNSkManager();
33
-
35
+
34
36
  /**
35
37
  Invalidates the Skia Manager
36
38
  */
@@ -48,7 +50,7 @@ public:
48
50
  * @param nativeId Native view Id
49
51
  */
50
52
  void unregisterSkiaView(size_t nativeId);
51
-
53
+
52
54
  /**
53
55
  Sets the view pointed to by nativeId to the provided value.
54
56
  Used when we want to remove a view without unregistering it
@@ -3,25 +3,26 @@
3
3
  #include <functional>
4
4
  #include <memory>
5
5
  #include <mutex>
6
- #include <vector>
7
6
  #include <string>
7
+ #include <unordered_map>
8
+ #include <vector>
8
9
 
9
10
  #include <jsi/jsi.h>
10
11
 
11
12
  #include <JsiValueWrapper.h>
12
13
  #include <RNSkView.h>
13
14
 
15
+ #include <JsiSkPicture.h>
14
16
  #include <RNSkInfoParameter.h>
17
+ #include <RNSkLog.h>
15
18
  #include <RNSkPlatformContext.h>
16
19
  #include <RNSkTimingInfo.h>
17
- #include <RNSkLog.h>
18
- #include <JsiSkPicture.h>
19
20
 
20
21
  #pragma clang diagnostic push
21
22
  #pragma clang diagnostic ignored "-Wdocumentation"
22
23
 
23
- #include <SkCanvas.h>
24
24
  #include <SkBBHFactory.h>
25
+ #include <SkCanvas.h>
25
26
  #include <SkPictureRecorder.h>
26
27
 
27
28
  #pragma clang diagnostic pop
@@ -32,85 +33,91 @@ class SkImage;
32
33
 
33
34
  namespace RNSkia {
34
35
 
35
- using namespace facebook;
36
+ namespace jsi = facebook::jsi;
36
37
 
37
- class RNSkPictureRenderer:
38
- public RNSkRenderer,
39
- public std::enable_shared_from_this<RNSkPictureRenderer> {
38
+ class RNSkPictureRenderer
39
+ : public RNSkRenderer,
40
+ public std::enable_shared_from_this<RNSkPictureRenderer> {
40
41
  public:
41
- RNSkPictureRenderer(std::function<void()> requestRedraw,
42
- std::shared_ptr<RNSkPlatformContext> context):
43
- RNSkRenderer(requestRedraw),
44
- _platformContext(context) {}
42
+ RNSkPictureRenderer(std::function<void()> requestRedraw,
43
+ std::shared_ptr<RNSkPlatformContext> context)
44
+ : RNSkRenderer(requestRedraw), _platformContext(context) {}
45
45
 
46
46
  bool tryRender(std::shared_ptr<RNSkCanvasProvider> canvasProvider) override {
47
47
  performDraw(canvasProvider);
48
48
  return true;
49
49
  }
50
-
51
- void renderImmediate(std::shared_ptr<RNSkCanvasProvider> canvasProvider) override {
50
+
51
+ void
52
+ renderImmediate(std::shared_ptr<RNSkCanvasProvider> canvasProvider) override {
52
53
  performDraw(canvasProvider);
53
54
  }
54
55
 
55
56
  void setPicture(std::shared_ptr<jsi::HostObject> picture) {
56
- if(picture == nullptr) {
57
+ if (picture == nullptr) {
57
58
  _picture = nullptr;
58
59
  return;
59
60
  }
60
-
61
+
61
62
  _picture = std::dynamic_pointer_cast<JsiSkPicture>(picture);
62
63
  _requestRedraw();
63
64
  }
64
-
65
+
65
66
  private:
66
67
  void performDraw(std::shared_ptr<RNSkCanvasProvider> canvasProvider) {
67
- if(_picture == nullptr) {
68
+ if (_picture == nullptr) {
68
69
  return;
69
70
  }
70
-
71
- canvasProvider->renderToCanvas([=](SkCanvas* canvas){
71
+
72
+ canvasProvider->renderToCanvas([=](SkCanvas *canvas) {
72
73
  // Make sure to scale correctly
73
74
  auto pd = _platformContext->getPixelDensity();
74
75
  canvas->save();
75
76
  canvas->scale(pd, pd);
76
-
77
+
77
78
  canvas->drawPicture(_picture->getObject());
78
-
79
+
79
80
  // Restore and flush canvas
80
81
  canvas->restore();
81
82
  canvas->flush();
82
83
  });
83
84
  }
84
-
85
+
85
86
  std::shared_ptr<RNSkPlatformContext> _platformContext;
86
87
  std::shared_ptr<JsiSkPicture> _picture;
87
88
  };
88
89
 
89
- class RNSkPictureView: public RNSkView {
90
+ class RNSkPictureView : public RNSkView {
90
91
  public:
91
92
  /**
92
93
  * Constructor
93
94
  */
94
95
  RNSkPictureView(std::shared_ptr<RNSkPlatformContext> context,
95
- std::shared_ptr<RNSkCanvasProvider> canvasProvider):
96
- RNSkView(context,
97
- canvasProvider,
98
- std::make_shared<RNSkPictureRenderer>(std::bind(&RNSkPictureView::requestRedraw, this), context)) {}
99
-
100
- void setJsiProperties(std::unordered_map<std::string, JsiValueWrapper> &props) override {
101
- for(auto& prop: props) {
102
- if(prop.first == "picture") {
103
- if(prop.second.isUndefinedOrNull()) {
96
+ std::shared_ptr<RNSkCanvasProvider> canvasProvider)
97
+ : RNSkView(
98
+ context, canvasProvider,
99
+ std::make_shared<RNSkPictureRenderer>(
100
+ std::bind(&RNSkPictureView::requestRedraw, this), context)) {}
101
+
102
+ void setJsiProperties(
103
+ std::unordered_map<std::string, RNJsi::JsiValueWrapper> &props) override {
104
+ for (auto &prop : props) {
105
+ if (prop.first == "picture") {
106
+ if (prop.second.isUndefinedOrNull()) {
104
107
  // Clear picture
105
- std::static_pointer_cast<RNSkPictureRenderer>(getRenderer())->setPicture(nullptr);
108
+ std::static_pointer_cast<RNSkPictureRenderer>(getRenderer())
109
+ ->setPicture(nullptr);
106
110
  return;
107
- } else if (prop.second.getType() != JsiWrapperValueType::HostObject) {
111
+ } else if (prop.second.getType() !=
112
+ RNJsi::JsiWrapperValueType::HostObject) {
108
113
  // We expect a function for the picture custom property
109
- throw std::runtime_error("Expected an object for the picture custom property.");
114
+ throw std::runtime_error(
115
+ "Expected an object for the picture custom property.");
110
116
  }
111
117
 
112
118
  // Save picture
113
- std::static_pointer_cast<RNSkPictureRenderer>(getRenderer())->setPicture(prop.second.getAsHostObject());
119
+ std::static_pointer_cast<RNSkPictureRenderer>(getRenderer())
120
+ ->setPicture(prop.second.getAsHostObject());
114
121
 
115
122
  // Request redraw
116
123
  requestRedraw();