@shopify/react-native-skia 0.1.169 → 0.1.171

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,6 +12,11 @@ set (SKIA_SKSHAPER_LIB "skshaper")
12
12
  #set (SKIA_SKPARAGRAPH_LIB "skparagraph")
13
13
  #set (SKIA_SKUNICODE_LIB "skunicode")
14
14
 
15
+ # Clear some variables
16
+ unset(LIBRN_DIR CACHE)
17
+ unset(libfbjni_link_DIRS CACHE)
18
+ unset(libfbjni_include_DIRS CACHE)
19
+
15
20
  set(build_DIR ${CMAKE_SOURCE_DIR}/build)
16
21
  file(GLOB LIBRN_DIR "${PREBUILT_DIR}/${ANDROID_ABI}")
17
22
  file(GLOB libfbjni_link_DIRS "${build_DIR}/fbjni*.aar/jni/${ANDROID_ABI}")
@@ -114,49 +119,72 @@ find_library(
114
119
  LOG_LIB
115
120
  log
116
121
  )
117
-
118
122
  message("-- LOG : " ${LOG_LIB})
119
123
 
120
- if(${REACT_NATIVE_VERSION} LESS 66)
121
- # JSI lib didn't exist on RN 0.65 and before. Simply omit it.
122
- set (JSI_LIB "")
123
- else()
124
- # RN 0.66 distributes libjsi.so, can be used instead of compiling jsi.cpp manually.
125
- find_library(
126
- JSI_LIB
127
- jsi
128
- PATHS ${LIBRN_DIR}
129
- NO_CMAKE_FIND_ROOT_PATH
130
- )
131
- endif()
132
-
133
- message("-- JSI : " ${JSI_LIB})
124
+ if(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
125
+ # We need to find packages since from RN 0.71 binaries are prebuilt
126
+ find_package(fbjni REQUIRED CONFIG)
127
+ find_package(ReactAndroid REQUIRED CONFIG)
128
+ endif()
134
129
 
135
- find_library(
136
- REACT_LIB
137
- react_nativemodule_core
130
+ unset(JSI_LIB CACHE)
131
+ if(${REACT_NATIVE_VERSION} LESS 66)
132
+ # JSI lib didn't exist on RN 0.65 and before. Simply omit it.
133
+ set (JSI_LIB "")
134
+ elseif(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
135
+ # RN 0.71 distributes prebuilt binaries.
136
+ set (JSI_LIB ReactAndroid::jsi)
137
+ else()
138
+ # RN 0.66 distributes libjsi.so, can be used instead of compiling jsi.cpp manually.
139
+ find_library(
140
+ JSI_LIB
141
+ jsi
138
142
  PATHS ${LIBRN_DIR}
139
143
  NO_CMAKE_FIND_ROOT_PATH
140
- )
141
-
144
+ )
145
+ endif()
146
+ message("-- JSI : " ${JSI_LIB})
147
+
148
+ unset(REACT_LIB CACHE)
149
+ if(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
150
+ # RN 0.71 distributes prebuilt binaries.
151
+ set (REACT_LIB ReactAndroid::react_nativemodule_core)
152
+ else()
153
+ find_library(
154
+ REACT_LIB
155
+ react_nativemodule_core
156
+ PATHS ${LIBRN_DIR}
157
+ NO_CMAKE_FIND_ROOT_PATH
158
+ )
159
+ endif()
142
160
  message("-- REACT : " ${REACT_LIB})
143
161
 
144
- find_library(
145
- FBJNI_LIBRARY
146
- fbjni
147
- PATHS ${libfbjni_link_DIRS}
148
- NO_CMAKE_FIND_ROOT_PATH
149
- )
150
-
162
+ unset(FBJNI_LIBRARY CACHE)
163
+ if(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
164
+ # RN 0.71 distributes prebuilt binaries.
165
+ set (FBJNI_LIBRARY fbjni::fbjni)
166
+ else()
167
+ find_library(
168
+ FBJNI_LIBRARY
169
+ fbjni
170
+ PATHS ${libfbjni_link_DIRS}
171
+ NO_CMAKE_FIND_ROOT_PATH
172
+ )
173
+ endif()
151
174
  message("-- FBJNI : " ${FBJNI_LIBRARY})
152
175
 
153
- find_library(
154
- TURBOMODULES_LIB
155
- turbomodulejsijni
156
- PATHS ${LIBRN_DIR}
157
- NO_CMAKE_FIND_ROOT_PATH
158
- )
159
-
176
+ unset(TURBOMODULES_LIB CACHE)
177
+ if(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
178
+ # RN 0.71 distributes prebuilt binaries.
179
+ set (TURBOMODULES_LIB "ReactAndroid::turbomodulejsijni")
180
+ else()
181
+ find_library(
182
+ TURBOMODULES_LIB
183
+ turbomodulejsijni
184
+ PATHS ${LIBRN_DIR}
185
+ NO_CMAKE_FIND_ROOT_PATH
186
+ )
187
+ endif()
160
188
  message("-- TURBO : " ${TURBOMODULES_LIB})
161
189
 
162
190
  # Link
@@ -47,7 +47,7 @@ def nodeModules = findNodeModules(projectDir)
47
47
  logger.warn("react-native-skia: node_modules/ found at: ${nodeModules}")
48
48
 
49
49
  def sourceBuild = false
50
- def defaultDir = null
50
+ def defaultDir
51
51
 
52
52
  if (rootProject.ext.has('reactNativeAndroidRoot')) {
53
53
  defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
@@ -55,7 +55,7 @@ if (rootProject.ext.has('reactNativeAndroidRoot')) {
55
55
  sourceBuild = true
56
56
  defaultDir = project(':ReactAndroid').projectDir
57
57
  } else {
58
- defaultDir = file("$nodeModules/react-native/android")
58
+ defaultDir = file("$nodeModules/react-native")
59
59
  }
60
60
 
61
61
  if (!defaultDir.exists()) {
@@ -78,7 +78,7 @@ if (gradle.startParameter.taskRequests.args[0].toString().contains("Release")) {
78
78
 
79
79
  def reactProperties = new Properties()
80
80
  file("$nodeModules/react-native/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
81
- def FULL_RN_VERSION = reactProperties.getProperty("VERSION_NAME")
81
+ def FULL_RN_VERSION = (System.getenv("REACT_NATIVE_OVERRIDE_VERSION") ?: reactProperties.getProperty("VERSION_NAME"))
82
82
  def REACT_NATIVE_VERSION = FULL_RN_VERSION.split("\\.")[1].toInteger()
83
83
 
84
84
  logger.warn("react-native-skia: RN Version: ${REACT_NATIVE_VERSION} / ${FULL_RN_VERSION}")
@@ -136,6 +136,10 @@ android {
136
136
  }
137
137
  }
138
138
 
139
+ buildFeatures {
140
+ prefab true
141
+ }
142
+
139
143
  packagingOptions {
140
144
  excludes = [
141
145
  "**/libc++_shared.so",
@@ -146,8 +150,6 @@ android {
146
150
  ]
147
151
  }
148
152
 
149
-
150
-
151
153
  // Create new configurations that can be referred to in dependencies.
152
154
  // The Android Gradle Plugin 3.* does not allow hooking into existing
153
155
  // configurations like `implementation`.
@@ -181,17 +183,25 @@ dependencies {
181
183
  //noinspection GradleDynamicVersion
182
184
  implementation 'com.facebook.react:react-native:+' // From node_modules
183
185
 
184
- //noinspection GradleDynamicVersion
185
- extractHeaders("com.facebook.fbjni:fbjni:0.2.2:headers")
186
- //noinspection GradleDynamicVersion
187
- extractJNI("com.facebook.fbjni:fbjni:0.2.2")
186
+ if (REACT_NATIVE_VERSION < 71) {
187
+ logger.warn("react-native-skia: Extracting files from AAR (pre RN 0.71)")
188
+ //noinspection GradleDynamicVersion
189
+ extractHeaders("com.facebook.fbjni:fbjni:0.2.2:headers")
190
+ //noinspection GradleDynamicVersion
191
+ extractJNI("com.facebook.fbjni:fbjni:0.2.2")
192
+ }
188
193
 
189
194
  if (!sourceBuild) {
190
195
  def rnAarMatcher = "**/react-native/**/*${buildType}.aar"
191
196
  if (REACT_NATIVE_VERSION < 69) {
197
+ logger.warn("react-native-skia: aar state pre 69. match **/**/*.aar")
192
198
  rnAarMatcher = "**/**/*.aar"
199
+ } else if (REACT_NATIVE_VERSION >= 71) {
200
+ logger.warn("react-native-skia: aar state post 70, do nothing")
201
+ return
193
202
  }
194
- def rnAAR = fileTree("${nodeModules}/react-native/android").matching({ it.include rnAarMatcher }).singleFile
203
+ def rnAAR = fileTree("${nodeModules}/react-native/android").matching({ it.include rnAarMatcher }).singleFile
204
+ logger.warn("react-native-skia: Extracting JNI files (pre RN 0.71) ${rnAAR}")
195
205
  extractJNI(files(rnAAR))
196
206
  }
197
207
  }
@@ -13,15 +13,15 @@ namespace RNJsi {
13
13
  namespace jsi = facebook::jsi;
14
14
 
15
15
  enum struct PropType {
16
- Undefined = 1,
17
- Null = 2,
18
- Bool = 4,
19
- Number = 8,
20
- String = 16,
21
- Object = 32,
22
- HostObject = 64,
23
- HostFunction = 128,
24
- Array = 256
16
+ Undefined = 0,
17
+ Null = 1, // Keep undefined / null constant so that we can do checks faster
18
+ Bool = 2,
19
+ Number = 3,
20
+ String = 4,
21
+ Object = 5,
22
+ HostObject = 6,
23
+ HostFunction = 7,
24
+ Array = 8
25
25
  };
26
26
 
27
27
  using PropId = const char *;
@@ -80,7 +80,7 @@ public:
80
80
  /**
81
81
  Returns true if the value is undefined or null.
82
82
  */
83
- bool isUndefinedOrNull() const { return isUndefined() || isNull(); }
83
+ bool isUndefinedOrNull() const { return _type <= PropType::Null; }
84
84
 
85
85
  /**
86
86
  Returns true if the value is undefined.
@@ -41,9 +41,9 @@ public:
41
41
  // Materialize children first so that any inner nodes get the opportunity
42
42
  // to calculate their state before this node continues.
43
43
  for (auto &child : getChildren()) {
44
- auto decl = std::dynamic_pointer_cast<JsiBaseDomDeclarationNode>(child);
45
- if (decl != nullptr) {
46
- decl->decorateContext(context);
44
+ if (child->getNodeClass() == JsiDomNodeClass::DeclarationNode) {
45
+ std::static_pointer_cast<JsiBaseDomDeclarationNode>(child)
46
+ ->decorateContext(context);
47
47
  }
48
48
  }
49
49
 
@@ -55,6 +55,10 @@ public:
55
55
  #endif
56
56
  }
57
57
 
58
+ JsiDomNodeClass getNodeClass() override {
59
+ return JsiDomNodeClass::DeclarationNode;
60
+ }
61
+
58
62
  protected:
59
63
  /**
60
64
  Invalidates and marks then context as changed. The implementation in the
@@ -30,6 +30,11 @@ public:
30
30
 
31
31
  static std::atomic<size_t> NodeIdent = 1000;
32
32
 
33
+ typedef enum {
34
+ RenderNode = 1,
35
+ DeclarationNode = 2,
36
+ } JsiDomNodeClass;
37
+
33
38
  /**
34
39
  Implements an abstract base class for nodes in the Skia Reconciler. This node
35
40
  coresponds to the native implementation of the Node.ts class in Javascript.
@@ -174,6 +179,12 @@ public:
174
179
  */
175
180
  virtual void invalidateContext() = 0;
176
181
 
182
+ /*
183
+ Returns the class of node so that we can do loops faster without
184
+ having to check using runtime type information
185
+ */
186
+ virtual JsiDomNodeClass getNodeClass() = 0;
187
+
177
188
  /**
178
189
  Updates any pending property changes in all nodes and child nodes. This
179
190
  function will swap any pending property changes in this and children with any
@@ -149,6 +149,10 @@ public:
149
149
  }
150
150
  }
151
151
 
152
+ JsiDomNodeClass getNodeClass() override {
153
+ return JsiDomNodeClass::RenderNode;
154
+ }
155
+
152
156
  protected:
153
157
  /**
154
158
  Invalidates and marks then context as changed.
@@ -211,9 +215,9 @@ private:
211
215
  */
212
216
  void materializeDeclarations() {
213
217
  for (auto &child : getChildren()) {
214
- auto ptr = std::dynamic_pointer_cast<JsiBaseDomDeclarationNode>(child);
215
- if (ptr != nullptr) {
216
- ptr->decorateContext(_localContext.get());
218
+ if (child->getNodeClass() == JsiDomNodeClass::DeclarationNode) {
219
+ std::static_pointer_cast<JsiBaseDomDeclarationNode>(child)
220
+ ->decorateContext(_localContext.get());
217
221
  }
218
222
  }
219
223
  }
@@ -86,9 +86,7 @@ public:
86
86
  {
87
87
  // Swap buffers
88
88
  std::lock_guard<std::mutex> lock(_swapMutex);
89
- auto tmp = _value;
90
- _value = _buffer;
91
- _buffer = tmp;
89
+ _value.swap(_buffer);
92
90
 
93
91
  // turn off pending changes flag
94
92
  _hasNewValue = false;
@@ -15,9 +15,8 @@ public:
15
15
 
16
16
  void renderNode(DrawingContext *context) override {
17
17
  for (auto &child : getChildren()) {
18
- auto renderNode = std::dynamic_pointer_cast<JsiDomRenderNode>(child);
19
- if (renderNode != nullptr) {
20
- renderNode->render(context);
18
+ if (child->getNodeClass() == JsiDomNodeClass::RenderNode) {
19
+ std::static_pointer_cast<JsiDomRenderNode>(child)->render(context);
21
20
  }
22
21
  }
23
22
  }
@@ -15,7 +15,8 @@ public:
15
15
  }
16
16
 
17
17
  void updateDerivedValue() override {
18
- if (_fontProp->value().getType() != PropType::HostObject) {
18
+ if (!_fontProp->isSet() ||
19
+ _fontProp->value().getType() != PropType::HostObject) {
19
20
  throw std::runtime_error("Expected SkFont object for the Font property.");
20
21
  }
21
22
 
@@ -66,6 +66,16 @@ void RNSkMetalCanvasProvider::renderToCanvas(const std::function<void(SkCanvas*)
66
66
  return;
67
67
  }
68
68
 
69
+ // Make sure to NOT render or try any render operations while we're in the background or inactive.
70
+ // This will cause an error that might clear the CAMetalLayer so that the canvas is empty when
71
+ // the app receives focus again.
72
+ // Reference: https://github.com/Shopify/react-native-skia/issues/1257
73
+ auto state = UIApplication.sharedApplication.applicationState;
74
+ if (state == UIApplicationStateBackground || state == UIApplicationStateInactive)
75
+ {
76
+ return;
77
+ }
78
+
69
79
  // Get render context for current thread
70
80
  auto renderContext = getMetalRenderContext();
71
81
 
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.169",
10
+ "version": "0.1.171",
11
11
  "description": "High-performance React Native Graphics using Skia",
12
12
  "main": "lib/module/index.js",
13
13
  "files": [