@shopify/react-native-skia 0.1.167 → 0.1.170

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.
@@ -47,7 +47,7 @@ public:
47
47
  count > 1 && !arguments[1].isUndefined() && !arguments[1].isNull()
48
48
  ? JsiSkMatrix::fromValue(runtime, arguments[1])
49
49
  : nullptr;
50
- auto mode = count > 2 && arguments[2].asBool()
50
+ auto mode = count > 2 && arguments[2].isBool() && arguments[2].getBool()
51
51
  ? SkPath::kExtend_AddPathMode
52
52
  : SkPath::kAppend_AddPathMode;
53
53
  if (matrix == nullptr) {
@@ -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.167",
10
+ "version": "0.1.170",
11
11
  "description": "High-performance React Native Graphics using Skia",
12
12
  "main": "lib/module/index.js",
13
13
  "files": [