@shopify/react-native-skia 0.1.195 → 0.1.196

Sign up to get free protection for your applications and to get access to all the features.
@@ -51,6 +51,7 @@ add_library(
51
51
  "${PROJECT_SOURCE_DIR}/cpp/jsi/JsiValue.cpp"
52
52
  "${PROJECT_SOURCE_DIR}/cpp/jsi/RuntimeLifecycleMonitor.cpp"
53
53
  "${PROJECT_SOURCE_DIR}/cpp/jsi/RuntimeAwareCache.cpp"
54
+ "${PROJECT_SOURCE_DIR}/cpp/jsi/JsiPromises.cpp"
54
55
 
55
56
  "${PROJECT_SOURCE_DIR}/cpp/rnskia/RNSkManager.cpp"
56
57
  "${PROJECT_SOURCE_DIR}/cpp/rnskia/RNSkJsView.cpp"
@@ -137,6 +137,12 @@ android {
137
137
  abortOnError false
138
138
  }
139
139
 
140
+ publishing {
141
+ singleVariant("release") {
142
+ withSourcesJar()
143
+ }
144
+ }
145
+
140
146
  externalNativeBuild {
141
147
  cmake {
142
148
  path file('CMakeLists.txt')
@@ -223,12 +229,6 @@ dependencies {
223
229
  }
224
230
 
225
231
  afterEvaluate { project ->
226
- task androidSourcesJar(type: Jar) {
227
- classifier = 'sources'
228
- from android.sourceSets.main.java.srcDirs
229
- include '**/*.java'
230
- }
231
-
232
232
  android.libraryVariants.all { variant ->
233
233
  def name = variant.name.capitalize()
234
234
  def javaCompileTask = variant.javaCompileProvider.get()
@@ -237,10 +237,6 @@ afterEvaluate { project ->
237
237
  from javaCompileTask.destinationDir
238
238
  }
239
239
  }
240
-
241
- artifacts {
242
- archives androidSourcesJar
243
- }
244
240
  }
245
241
 
246
242
  task extractAARHeaders {
@@ -278,7 +274,6 @@ if (ENABLE_PREFAB) {
278
274
  into "${project.buildDir}/headers/rnskia/"
279
275
  includeEmptyDirs = false
280
276
  include "**/*.h"
281
- duplicatesStrategy = 'include'
282
277
  eachFile {
283
278
  String path = it.path
284
279
 
@@ -3,17 +3,15 @@
3
3
  #include <memory>
4
4
  #include <utility>
5
5
 
6
- #include <ReactCommon/TurboModuleUtils.h>
7
6
  #include <jsi/jsi.h>
8
7
 
9
- #include "SkBase64.h"
10
-
8
+ #include "JsiPromises.h"
11
9
  #include "JsiSkData.h"
10
+ #include "SkBase64.h"
12
11
 
13
12
  namespace RNSkia {
14
13
 
15
14
  namespace jsi = facebook::jsi;
16
- namespace react = facebook::react;
17
15
 
18
16
  class JsiSkDataFactory : public JsiSkHostObject {
19
17
  public:
@@ -21,11 +19,11 @@ public:
21
19
  auto jsiLocalUri = arguments[0].asString(runtime);
22
20
  auto localUri = jsiLocalUri.utf8(runtime);
23
21
  auto context = getContext();
24
- return react::createPromiseAsJSIValue(
22
+ return RNJsi::JsiPromises::createPromiseAsJSIValue(
25
23
  runtime,
26
24
  [context = std::move(context), localUri = std::move(localUri)](
27
25
  jsi::Runtime &runtime,
28
- std::shared_ptr<react::Promise> promise) -> void {
26
+ std::shared_ptr<RNJsi::JsiPromises::Promise> promise) -> void {
29
27
  // Create a stream operation - this will be run in a
30
28
  // separate thread
31
29
  context->performStreamOperation(
@@ -5,6 +5,7 @@
5
5
 
6
6
  #include <jsi/jsi.h>
7
7
 
8
+ #include "JsiPromises.h"
8
9
  #include "JsiSkData.h"
9
10
  #include "JsiSkHostObjects.h"
10
11
  #include "JsiSkImage.h"
@@ -41,11 +42,11 @@ public:
41
42
  JSI_HOST_FUNCTION(MakeImageFromViewTag) {
42
43
  auto viewTag = arguments[0].asNumber();
43
44
  auto context = getContext();
44
- return react::createPromiseAsJSIValue(
45
+ return RNJsi::JsiPromises::createPromiseAsJSIValue(
45
46
  runtime,
46
- [context = std::move(context),
47
- viewTag](jsi::Runtime &runtime,
48
- std::shared_ptr<react::Promise> promise) -> void {
47
+ [context = std::move(context), viewTag](
48
+ jsi::Runtime &runtime,
49
+ std::shared_ptr<RNJsi::JsiPromises::Promise> promise) -> void {
49
50
  // Create a stream operation - this will be run on the main thread
50
51
  context->makeViewScreenshot(
51
52
  viewTag, [&runtime, context = std::move(context),
@@ -0,0 +1,39 @@
1
+ #include "JsiPromises.h"
2
+
3
+ namespace RNJsi {
4
+
5
+ JsiPromises::Promise::Promise(jsi::Runtime &rt, jsi::Function resolve,
6
+ jsi::Function reject)
7
+ : runtime_(rt), resolve_(std::move(resolve)), reject_(std::move(reject)) {}
8
+
9
+ void JsiPromises::Promise::resolve(const jsi::Value &result) {
10
+ resolve_.call(runtime_, result);
11
+ }
12
+
13
+ void JsiPromises::Promise::reject(const std::string &message) {
14
+ jsi::Object error(runtime_);
15
+ error.setProperty(runtime_, "message",
16
+ jsi::String::createFromUtf8(runtime_, message));
17
+ reject_.call(runtime_, error);
18
+ }
19
+
20
+ jsi::Value
21
+ JsiPromises::createPromiseAsJSIValue(jsi::Runtime &rt,
22
+ PromiseSetupFunctionType &&func) {
23
+ jsi::Function JSPromise = rt.global().getPropertyAsFunction(rt, "Promise");
24
+ jsi::Function fn = jsi::Function::createFromHostFunction(
25
+ rt, jsi::PropNameID::forAscii(rt, "fn"), 2,
26
+ [func = std::move(func)](jsi::Runtime &rt2, const jsi::Value &thisVal,
27
+ const jsi::Value *args, size_t count) {
28
+ jsi::Function resolve = args[0].getObject(rt2).getFunction(rt2);
29
+ jsi::Function reject = args[1].getObject(rt2).getFunction(rt2);
30
+ auto wrapper = std::make_shared<Promise>(rt2, std::move(resolve),
31
+ std::move(reject));
32
+ func(rt2, wrapper);
33
+ return jsi::Value::undefined();
34
+ });
35
+
36
+ return JSPromise.callAsConstructor(rt, fn);
37
+ }
38
+
39
+ } // namespace RNJsi
@@ -0,0 +1,50 @@
1
+ #pragma once
2
+
3
+ #include <memory>
4
+ #include <string>
5
+ #include <utility>
6
+
7
+ #include <jsi/jsi.h>
8
+
9
+ #include "SkBase64.h"
10
+
11
+ namespace RNJsi {
12
+ namespace jsi = facebook::jsi;
13
+
14
+ /**
15
+ These classes are taken from ReactCommon TurboModuleUtils. It is no longer (RN
16
+ 0.72) possible to include and uses TurboModulesUtils without a lot of trouble
17
+ when use_frameworks are true in POD file. Instead we're now just including the
18
+ implementations ourselves.
19
+ */
20
+
21
+ class LongLivedObject {
22
+ public:
23
+ void allowRelease();
24
+
25
+ protected:
26
+ LongLivedObject() = default;
27
+ virtual ~LongLivedObject() = default;
28
+ };
29
+
30
+ class JsiPromises {
31
+ public:
32
+ struct Promise : public LongLivedObject {
33
+ Promise(jsi::Runtime &rt, jsi::Function resolve, jsi::Function reject);
34
+
35
+ void resolve(const jsi::Value &result);
36
+ void reject(const std::string &error);
37
+
38
+ jsi::Runtime &runtime_;
39
+ jsi::Function resolve_;
40
+ jsi::Function reject_;
41
+ };
42
+
43
+ using PromiseSetupFunctionType =
44
+ std::function<void(jsi::Runtime &rt, std::shared_ptr<Promise>)>;
45
+
46
+ static jsi::Value createPromiseAsJSIValue(jsi::Runtime &rt,
47
+ PromiseSetupFunctionType &&func);
48
+ };
49
+
50
+ } // namespace RNJsi
@@ -55,10 +55,9 @@ public:
55
55
  void setPicture(std::shared_ptr<jsi::HostObject> picture) {
56
56
  if (picture == nullptr) {
57
57
  _picture = nullptr;
58
- return;
58
+ } else {
59
+ _picture = std::dynamic_pointer_cast<JsiSkPicture>(picture);
59
60
  }
60
-
61
- _picture = std::dynamic_pointer_cast<JsiSkPicture>(picture);
62
61
  _requestRedraw();
63
62
  }
64
63
 
@@ -107,7 +106,6 @@ public:
107
106
  // Clear picture
108
107
  std::static_pointer_cast<RNSkPictureRenderer>(getRenderer())
109
108
  ->setPicture(nullptr);
110
- requestRedraw();
111
109
  continue;
112
110
  } else if (prop.second.getType() !=
113
111
  RNJsi::JsiWrapperValueType::HostObject) {
@@ -119,9 +117,6 @@ public:
119
117
  // Save picture
120
118
  std::static_pointer_cast<RNSkPictureRenderer>(getRenderer())
121
119
  ->setPicture(prop.second.getAsHostObject());
122
-
123
- // Request redraw
124
- requestRedraw();
125
120
  }
126
121
  }
127
122
  }
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.195",
10
+ "version": "0.1.196",
11
11
  "description": "High-performance React Native Graphics using Skia",
12
12
  "main": "lib/module/index.js",
13
13
  "files": [
@@ -1,9 +0,0 @@
1
- /*
2
- * Copyright 2023 Google LLC
3
- *
4
- * Use of this source code is governed by a BSD-style license that can be
5
- * found in the LICENSE file.
6
- */
7
-
8
- // TODO(kjlubick) remove this shim after clients have been moved to the new location
9
- #include "include/codec/SkEncodedImageFormat.h" // IWYU pragma: export
@@ -1,9 +0,0 @@
1
- /*
2
- * Copyright 2023 Google LLC
3
- *
4
- * Use of this source code is governed by a BSD-style license that can be
5
- * found in the LICENSE file.
6
- */
7
-
8
- // TODO(kjlubick) remove this shim after clients have been moved to the new location
9
- #include "include/encode/SkICC.h" // IWYU pragma: export