@shopify/react-native-skia 0.1.155 → 0.1.156

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) 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/types/NodeType.js +1 -0
  95. package/lib/commonjs/dom/types/NodeType.js.map +1 -1
  96. package/lib/commonjs/dom/types/SkDOM.js.map +1 -1
  97. package/lib/commonjs/renderer/HostComponents.js +3 -0
  98. package/lib/commonjs/renderer/HostComponents.js.map +1 -1
  99. package/lib/commonjs/renderer/components/Group.js +19 -4
  100. package/lib/commonjs/renderer/components/Group.js.map +1 -1
  101. package/lib/commonjs/renderer/components/Paint.js +6 -1
  102. package/lib/commonjs/renderer/components/Paint.js.map +1 -1
  103. package/lib/commonjs/views/SkiaPictureView.js +3 -2
  104. package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
  105. package/lib/commonjs/views/SkiaView.js +6 -3
  106. package/lib/commonjs/views/SkiaView.js.map +1 -1
  107. package/lib/module/dom/nodes/JsiSkDOM.js +5 -0
  108. package/lib/module/dom/nodes/JsiSkDOM.js.map +1 -1
  109. package/lib/module/dom/nodes/LayerNode.js +32 -0
  110. package/lib/module/dom/nodes/LayerNode.js.map +1 -0
  111. package/lib/module/dom/types/NodeType.js +1 -0
  112. package/lib/module/dom/types/NodeType.js.map +1 -1
  113. package/lib/module/dom/types/SkDOM.js.map +1 -1
  114. package/lib/module/renderer/HostComponents.js +3 -0
  115. package/lib/module/renderer/HostComponents.js.map +1 -1
  116. package/lib/module/renderer/components/Group.js +16 -3
  117. package/lib/module/renderer/components/Group.js.map +1 -1
  118. package/lib/module/renderer/components/Paint.js +7 -1
  119. package/lib/module/renderer/components/Paint.js.map +1 -1
  120. package/lib/module/views/SkiaPictureView.js +2 -2
  121. package/lib/module/views/SkiaPictureView.js.map +1 -1
  122. package/lib/module/views/SkiaView.js +4 -2
  123. package/lib/module/views/SkiaView.js.map +1 -1
  124. package/lib/typescript/src/dom/nodes/JsiSkDOM.d.ts +2 -0
  125. package/lib/typescript/src/dom/nodes/LayerNode.d.ts +8 -0
  126. package/lib/typescript/src/dom/types/NodeType.d.ts +1 -0
  127. package/lib/typescript/src/dom/types/SkDOM.d.ts +1 -0
  128. package/lib/typescript/src/renderer/HostComponents.d.ts +2 -1
  129. package/lib/typescript/src/renderer/components/Group.d.ts +5 -1
  130. package/lib/typescript/src/views/SkiaView.d.ts +3 -0
  131. package/libs/android/arm64-v8a/libskottie.a +0 -0
  132. package/libs/android/arm64-v8a/libsksg.a +0 -0
  133. package/libs/android/armeabi-v7a/libskottie.a +0 -0
  134. package/libs/android/armeabi-v7a/libsksg.a +0 -0
  135. package/libs/android/x86/libskottie.a +0 -0
  136. package/libs/android/x86/libsksg.a +0 -0
  137. package/libs/android/x86_64/libskottie.a +0 -0
  138. package/libs/android/x86_64/libsksg.a +0 -0
  139. package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
  140. package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  141. package/libs/ios/libskottie.xcframework/Info.plist +42 -0
  142. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
  143. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
  144. package/libs/ios/libsksg.xcframework/Info.plist +42 -0
  145. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
  146. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
  147. package/libs/ios/libskshaper.xcframework/Info.plist +5 -5
  148. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
  149. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
  150. package/libs/ios/libsvg.xcframework/Info.plist +5 -5
  151. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
  152. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
  153. package/package.json +3 -1
  154. package/src/dom/nodes/JsiSkDOM.ts +5 -0
  155. package/src/dom/nodes/LayerNode.ts +35 -0
  156. package/src/dom/types/NodeType.ts +1 -0
  157. package/src/dom/types/SkDOM.ts +1 -0
  158. package/src/renderer/HostComponents.ts +3 -0
  159. package/src/renderer/components/Group.tsx +16 -3
  160. package/src/renderer/components/Paint.tsx +7 -1
  161. package/src/views/SkiaPictureView.tsx +2 -3
  162. package/src/views/SkiaView.tsx +2 -2
@@ -1,108 +1,99 @@
1
-
2
1
  #pragma once
3
2
 
3
+ #include <memory>
4
+
4
5
  #include <jsi/jsi.h>
5
6
 
6
- namespace RNJsi
7
- {
8
- using namespace facebook;
7
+ namespace RNJsi {
8
+ namespace jsi = facebook::jsi;
9
9
 
10
10
  /**
11
- Implements a simple wrapper class for JSI primitives like numbers and boolean values. Objects,
12
- strings and arrays are stored as values inside a property holder. The class also provides a method
13
- for comparing values that will compare numbers, booleans and strings.
11
+ Implements a simple wrapper class for JSI primitives like numbers and boolean
12
+ values. Objects, strings and arrays are stored as values inside a property
13
+ holder. The class also provides a method for comparing values that will compare
14
+ numbers, booleans and strings.
14
15
  */
15
- class JsiSimpleValueWrapper
16
- {
16
+ class JsiSimpleValueWrapper {
17
17
  private:
18
- enum ValueType {
19
- NonInitialized,
20
- Undefined,
21
- Null,
22
- Bool,
23
- Number,
24
- JsiValue
25
- };
18
+ enum ValueType { NonInitialized, Undefined, Null, Bool, Number, JsiValue };
26
19
 
27
20
  public:
28
- JsiSimpleValueWrapper(jsi::Runtime& runtime) :
29
- _type(ValueType::NonInitialized),
30
- _propNameId(jsi::PropNameID::forUtf8(runtime, "value"))
31
- {}
21
+ explicit JsiSimpleValueWrapper(jsi::Runtime &runtime)
22
+ : _type(ValueType::NonInitialized),
23
+ _propNameId(jsi::PropNameID::forUtf8(runtime, "value")) {}
32
24
 
33
- jsi::Value getCurrent(jsi::Runtime &runtime)
34
- {
35
- switch (_type)
36
- {
37
- case ValueType::NonInitialized:
38
- return nullptr;
39
- case ValueType::Undefined:
40
- return jsi::Value::undefined();
41
- case ValueType::Null:
42
- return jsi::Value::null();
43
- case ValueType::Bool:
44
- return _boolValue;
45
- case ValueType::Number:
46
- return _numberValue;
47
- case ValueType::JsiValue:
48
- if (_valueHolder == nullptr) {
49
- return jsi::Value::undefined();
50
- }
51
- return _valueHolder->getProperty(runtime, _propNameId);
25
+ jsi::Value getCurrent(jsi::Runtime &runtime) {
26
+ switch (_type) {
27
+ case ValueType::NonInitialized:
28
+ return nullptr;
29
+ case ValueType::Undefined:
30
+ return jsi::Value::undefined();
31
+ case ValueType::Null:
32
+ return jsi::Value::null();
33
+ case ValueType::Bool:
34
+ return _boolValue;
35
+ case ValueType::Number:
36
+ return _numberValue;
37
+ case ValueType::JsiValue:
38
+ if (_valueHolder == nullptr) {
39
+ return jsi::Value::undefined();
52
40
  }
41
+ return _valueHolder->getProperty(runtime, _propNameId);
53
42
  }
43
+ }
54
44
 
55
- void setCurrent(jsi::Runtime &runtime, const jsi::Value &value)
56
- {
57
- if(value.isNumber()) {
58
- _type = ValueType::Number;
59
- _numberValue = value.asNumber();
60
- } else if(value.isBool()) {
61
- _type = ValueType::Bool;
62
- _boolValue = value.getBool();
63
- } else if(value.isUndefined()) {
64
- _type = ValueType::Undefined;
65
- } else if(value.isNull()) {
66
- _type = ValueType::Null;
67
- } else {
68
- _type = ValueType::JsiValue;
69
- // Save as javascript object - we don't want to have to copy strings, objects and values
70
- if(_valueHolder == nullptr) {
71
- _valueHolder = std::make_shared<jsi::Object>(runtime);
72
- }
73
- _valueHolder->setProperty(runtime, _propNameId, value);
45
+ void setCurrent(jsi::Runtime &runtime, const jsi::Value &value) {
46
+ if (value.isNumber()) {
47
+ _type = ValueType::Number;
48
+ _numberValue = value.asNumber();
49
+ } else if (value.isBool()) {
50
+ _type = ValueType::Bool;
51
+ _boolValue = value.getBool();
52
+ } else if (value.isUndefined()) {
53
+ _type = ValueType::Undefined;
54
+ } else if (value.isNull()) {
55
+ _type = ValueType::Null;
56
+ } else {
57
+ _type = ValueType::JsiValue;
58
+ // Save as javascript object - we don't want to have to copy strings,
59
+ // objects and values
60
+ if (_valueHolder == nullptr) {
61
+ _valueHolder = std::make_shared<jsi::Object>(runtime);
74
62
  }
63
+ _valueHolder->setProperty(runtime, _propNameId, value);
75
64
  }
65
+ }
76
66
 
77
- bool equals(jsi::Runtime& runtime, const jsi::Value &value) {
78
- if (_type == ValueType::NonInitialized) {
79
- return false;
80
- }
81
- if(value.isNumber() && _type == ValueType::Number) {
82
- return _numberValue == value.asNumber();
83
- } else if(value.isBool() && _type == ValueType::Bool) {
84
- return _boolValue == value.getBool();
85
- } else if(value.isUndefined()) {
86
- return _type == ValueType::Undefined;
87
- } else if(value.isNull()) {
88
- return _type == ValueType::Null;
89
- } else if(value.isString()) {
90
- auto current = getCurrent(runtime);
91
- if (current.isString()) {
92
- return jsi::String::strictEquals(runtime, value.asString(runtime), current.asString(runtime));
93
- }
94
- return false;
67
+ bool equals(jsi::Runtime &runtime, const jsi::Value &value) {
68
+ if (_type == ValueType::NonInitialized) {
69
+ return false;
70
+ }
71
+ if (value.isNumber() && _type == ValueType::Number) {
72
+ return _numberValue == value.asNumber();
73
+ } else if (value.isBool() && _type == ValueType::Bool) {
74
+ return _boolValue == value.getBool();
75
+ } else if (value.isUndefined()) {
76
+ return _type == ValueType::Undefined;
77
+ } else if (value.isNull()) {
78
+ return _type == ValueType::Null;
79
+ } else if (value.isString()) {
80
+ auto current = getCurrent(runtime);
81
+ if (current.isString()) {
82
+ return jsi::String::strictEquals(runtime, value.asString(runtime),
83
+ current.asString(runtime));
95
84
  }
96
85
  return false;
97
86
  }
87
+ return false;
88
+ }
98
89
 
99
90
  private:
100
- jsi::PropNameID _propNameId;
101
- std::shared_ptr<jsi::Object> _valueHolder;
91
+ jsi::PropNameID _propNameId;
92
+ std::shared_ptr<jsi::Object> _valueHolder;
102
93
 
103
- bool _boolValue;
104
- double _numberValue;
94
+ bool _boolValue;
95
+ double _numberValue;
105
96
 
106
- ValueType _type;
97
+ ValueType _type;
107
98
  };
108
- }
99
+ } // namespace RNJsi
@@ -1,46 +1,42 @@
1
-
2
1
  #pragma once
3
2
 
4
3
  #include <jsi/jsi.h>
4
+ #include <memory>
5
+ #include <string>
6
+
7
+ namespace RNJsi {
8
+ namespace jsi = facebook::jsi;
5
9
 
6
- namespace RNJsi
7
- {
8
- using namespace facebook;
9
-
10
- enum JsiWrapperValueType
11
- {
12
- NonInitialized,
13
- Undefined,
14
- Null,
15
- Bool,
16
- Number,
17
- String,
18
- Object,
19
- Function,
20
- Array,
21
- HostObject,
22
- Unknown
10
+ enum JsiWrapperValueType {
11
+ NonInitialized,
12
+ Undefined,
13
+ Null,
14
+ Bool,
15
+ Number,
16
+ String,
17
+ Object,
18
+ Function,
19
+ Array,
20
+ HostObject,
21
+ Unknown
23
22
  };
24
23
 
25
24
  /**
26
- Implements a simple wrapper class for JSI values where the value can be read without asking the runtime for any assistance
27
- Meaning that we can access members without being on the JS thread.
25
+ Implements a simple wrapper class for JSI values where the value can be read
26
+ without asking the runtime for any assistance Meaning that we can access
27
+ members without being on the JS thread.
28
28
  */
29
- class JsiValueWrapper
30
- {
29
+ class JsiValueWrapper {
31
30
  public:
32
- JsiValueWrapper(jsi::Runtime& runtime) :
33
- _type(JsiWrapperValueType::NonInitialized)
34
- {}
35
-
36
- JsiValueWrapper(jsi::Runtime& runtime, const jsi::Value &value) :
37
- _type(JsiWrapperValueType::NonInitialized)
38
- {
31
+ explicit JsiValueWrapper(jsi::Runtime &runtime)
32
+ : _type(JsiWrapperValueType::NonInitialized) {}
33
+
34
+ JsiValueWrapper(jsi::Runtime &runtime, const jsi::Value &value)
35
+ : _type(JsiWrapperValueType::NonInitialized) {
39
36
  setCurrent(runtime, value);
40
37
  }
41
38
 
42
- void setCurrent(jsi::Runtime &runtime, const jsi::Value &value)
43
- {
39
+ void setCurrent(jsi::Runtime &runtime, const jsi::Value &value) {
44
40
  if (value.isNumber()) {
45
41
  _type = JsiWrapperValueType::Number;
46
42
  _numberValue = value.asNumber();
@@ -59,11 +55,13 @@ public:
59
55
  _objectValue = std::make_shared<jsi::Object>(value.asObject(runtime));
60
56
  if (_objectValue->isFunction(runtime)) {
61
57
  _type = JsiWrapperValueType::Function;
62
- _functionValue = std::make_shared<jsi::Function>(_objectValue->asFunction(runtime));
58
+ _functionValue =
59
+ std::make_shared<jsi::Function>(_objectValue->asFunction(runtime));
63
60
  _objectValue = nullptr;
64
61
  } else if (_objectValue->isArray(runtime)) {
65
62
  _type = JsiWrapperValueType::Array;
66
- _arrayValue = std::make_shared<jsi::Array>(_objectValue->asArray(runtime));
63
+ _arrayValue =
64
+ std::make_shared<jsi::Array>(_objectValue->asArray(runtime));
67
65
  _objectValue = nullptr;
68
66
  } else if (_objectValue->isHostObject(runtime)) {
69
67
  _type = JsiWrapperValueType::HostObject;
@@ -74,7 +72,7 @@ public:
74
72
  throw std::runtime_error("Could not store jsi::Value of provided type");
75
73
  }
76
74
  // Save in value holder as well so that we can return current
77
- if(_valueHolder == nullptr) {
75
+ if (_valueHolder == nullptr) {
78
76
  _valueHolder = std::make_shared<jsi::Object>(runtime);
79
77
  }
80
78
  _valueHolder->setProperty(runtime, "current", value);
@@ -82,57 +80,57 @@ public:
82
80
 
83
81
  bool isUndefinedOrNull() {
84
82
  return _type == JsiWrapperValueType::Undefined ||
85
- _type == JsiWrapperValueType::Null;
83
+ _type == JsiWrapperValueType::Null;
86
84
  }
87
-
85
+
88
86
  bool getAsBool() {
89
87
  assert(_type == JsiWrapperValueType::Bool);
90
88
  return _boolValue;
91
89
  }
92
-
90
+
93
91
  double getAsNumber() {
94
92
  assert(_type == JsiWrapperValueType::Number);
95
93
  return _numberValue;
96
94
  }
97
-
98
- const std::string& getAsString() {
95
+
96
+ const std::string &getAsString() {
99
97
  assert(_type == JsiWrapperValueType::String);
100
98
  return _stringValue;
101
99
  }
102
-
100
+
103
101
  std::shared_ptr<jsi::Function> getAsFunction() {
104
102
  assert(_type == JsiWrapperValueType::Function);
105
103
  return _functionValue;
106
104
  }
107
-
105
+
108
106
  std::shared_ptr<jsi::Array> getAsArray() {
109
107
  assert(_type == JsiWrapperValueType::Array);
110
108
  return _arrayValue;
111
109
  }
112
-
110
+
113
111
  std::shared_ptr<jsi::Object> getAsObject() {
114
112
  assert(_type == JsiWrapperValueType::Object);
115
113
  return _objectValue;
116
114
  }
117
-
115
+
118
116
  std::shared_ptr<jsi::HostObject> getAsHostObject() {
119
117
  assert(_type == JsiWrapperValueType::HostObject);
120
118
  return _hostObjectValue;
121
119
  }
122
-
120
+
123
121
  JsiWrapperValueType getType() { return _type; }
124
122
 
125
123
  private:
126
- std::shared_ptr<jsi::Object> _valueHolder;
124
+ std::shared_ptr<jsi::Object> _valueHolder;
127
125
 
128
- bool _boolValue;
129
- double _numberValue;
130
- std::string _stringValue;
131
- std::shared_ptr<jsi::Object> _objectValue;
132
- std::shared_ptr<jsi::Function> _functionValue;
133
- std::shared_ptr<jsi::Array> _arrayValue;
134
- std::shared_ptr<jsi::HostObject> _hostObjectValue;
126
+ bool _boolValue;
127
+ double _numberValue;
128
+ std::string _stringValue;
129
+ std::shared_ptr<jsi::Object> _objectValue;
130
+ std::shared_ptr<jsi::Function> _functionValue;
131
+ std::shared_ptr<jsi::Array> _arrayValue;
132
+ std::shared_ptr<jsi::HostObject> _hostObjectValue;
135
133
 
136
- JsiWrapperValueType _type;
134
+ JsiWrapperValueType _type;
137
135
  };
138
- }
136
+ } // namespace RNJsi
@@ -1,68 +1,65 @@
1
-
2
1
  #pragma once
3
2
 
4
3
  #include <array>
4
+ #include <memory>
5
5
 
6
6
  #include <JsiHostObject.h>
7
- #include <RNSkPlatformContext.h>
8
7
  #include <RNSkClockValue.h>
8
+ #include <RNSkPlatformContext.h>
9
9
  #include <jsi/jsi.h>
10
10
 
11
- namespace RNSkia
12
- {
13
- using namespace facebook;
11
+ namespace RNSkia {
12
+ namespace jsi = facebook::jsi;
14
13
 
15
14
  /**
16
15
  Implements an animation that can be used to drive other values
17
16
  */
18
- class RNSkAnimation : public RNSkClockValue
19
- {
20
-
17
+ class RNSkAnimation : public RNSkClockValue {
18
+
21
19
  public:
22
20
  RNSkAnimation(std::shared_ptr<RNSkPlatformContext> platformContext,
23
- size_t identifier,
24
- jsi::Runtime& runtime,
25
- const jsi::Value *arguments,
26
- size_t count) :
27
- RNSkClockValue(platformContext, identifier, runtime, arguments, count) {
21
+ size_t identifier, jsi::Runtime &runtime,
22
+ const jsi::Value *arguments, size_t count)
23
+ : RNSkClockValue(platformContext, identifier, runtime, arguments, count) {
28
24
  // Save the update function
29
- _updateFunction = std::make_shared<jsi::Function>(arguments[0].asObject(runtime).asFunction(runtime));
30
-
25
+ _updateFunction = std::make_shared<jsi::Function>(
26
+ arguments[0].asObject(runtime).asFunction(runtime));
27
+
31
28
  // Set state to undefined initially.
32
29
  _args[1] = jsi::Value::undefined();
33
30
  }
34
-
31
+
35
32
  JSI_HOST_FUNCTION(cancel) {
36
33
  stopClock();
37
34
  return jsi::Value::undefined();
38
35
  }
39
-
36
+
40
37
  JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(RNSkAnimation, cancel))
41
38
 
42
-
43
39
  protected:
44
-
45
40
  void tick(jsi::Runtime &runtime, const jsi::Value &value) override {
46
41
  // Set up arguments and call the update function
47
42
  _args[0] = value.asNumber();
48
- _args[1] = _updateFunction->call(runtime, static_cast<const jsi::Value*>(_args.data()), _args.size());
49
-
43
+ _args[1] = _updateFunction->call(
44
+ runtime, static_cast<const jsi::Value *>(_args.data()), _args.size());
45
+
50
46
  // Get finished
51
- auto finished = _args[1].asObject(runtime).getProperty(runtime, "finished").getBool();
52
- if(finished) {
47
+ auto finished =
48
+ _args[1].asObject(runtime).getProperty(runtime, "finished").getBool();
49
+ if (finished) {
53
50
  stopClock();
54
51
  }
55
-
52
+
56
53
  // Get the next value
57
- auto nextValue = _args[1].asObject(runtime).getProperty(runtime, "current").asNumber();
58
-
54
+ auto nextValue =
55
+ _args[1].asObject(runtime).getProperty(runtime, "current").asNumber();
56
+
59
57
  // Update self
60
58
  update(runtime, nextValue);
61
59
  }
62
-
60
+
63
61
  private:
64
-
65
62
  std::shared_ptr<jsi::Function> _updateFunction;
66
63
  std::array<jsi::Value, 2> _args;
67
64
  };
68
- }
65
+ } // namespace RNSkia
@@ -4,81 +4,70 @@
4
4
  #include <mutex>
5
5
  #include <utility>
6
6
 
7
- namespace RNSkia
8
- {
7
+ namespace RNSkia {
9
8
 
10
- RNSkDispatchQueue::~RNSkDispatchQueue()
11
- {
12
- // Signal to dispatch threads that it's time to wrap up
13
- std::unique_lock<std::mutex> lock(lock_);
14
- quit_ = true;
15
- lock.unlock();
16
- cv_.notify_all();
9
+ RNSkDispatchQueue::~RNSkDispatchQueue() {
10
+ // Signal to dispatch threads that it's time to wrap up
11
+ std::unique_lock<std::mutex> lock(lock_);
12
+ quit_ = true;
13
+ lock.unlock();
14
+ cv_.notify_all();
17
15
 
18
- // Wait for threads to finish before we exit
19
- for (size_t i = 0; i < threads_.size(); i++)
20
- {
21
- if (threads_[i].joinable())
22
- {
23
- threads_[i].join();
24
- }
16
+ // Wait for threads to finish before we exit
17
+ for (size_t i = 0; i < threads_.size(); i++) {
18
+ if (threads_[i].joinable()) {
19
+ threads_[i].join();
25
20
  }
26
21
  }
22
+ }
27
23
 
28
- RNSkDispatchQueue::RNSkDispatchQueue(std::string name, size_t thread_cnt)
29
- : name_{std::move(name)}, threads_(thread_cnt)
30
- {
31
- for (size_t i = 0; i < threads_.size(); i++)
32
- {
33
- threads_[i] = std::thread(&RNSkDispatchQueue::dispatch_thread_handler, this);
34
- }
24
+ RNSkDispatchQueue::RNSkDispatchQueue(std::string name, size_t thread_cnt)
25
+ : name_{std::move(name)}, threads_(thread_cnt) {
26
+ for (size_t i = 0; i < threads_.size(); i++) {
27
+ threads_[i] =
28
+ std::thread(&RNSkDispatchQueue::dispatch_thread_handler, this);
35
29
  }
30
+ }
36
31
 
37
- void RNSkDispatchQueue::dispatch(const fp_t &op)
38
- {
39
- std::unique_lock<std::mutex> lock(lock_);
40
- q_.push(op);
32
+ void RNSkDispatchQueue::dispatch(const fp_t &op) {
33
+ std::unique_lock<std::mutex> lock(lock_);
34
+ q_.push(op);
41
35
 
42
- // Manual unlocking is done before notifying, to avoid waking up
43
- // the waiting thread only to block again (see notify_one for details)
44
- lock.unlock();
45
- cv_.notify_one();
46
- }
36
+ // Manual unlocking is done before notifying, to avoid waking up
37
+ // the waiting thread only to block again (see notify_one for details)
38
+ lock.unlock();
39
+ cv_.notify_one();
40
+ }
47
41
 
48
- void RNSkDispatchQueue::dispatch(fp_t &&op)
49
- {
50
- std::unique_lock<std::mutex> lock(lock_);
51
- q_.push(std::move(op));
42
+ void RNSkDispatchQueue::dispatch(fp_t &&op) {
43
+ std::unique_lock<std::mutex> lock(lock_);
44
+ q_.push(std::move(op));
52
45
 
53
- // Manual unlocking is done before notifying, to avoid waking up
54
- // the waiting thread only to block again (see notify_one for details)
55
- lock.unlock();
56
- cv_.notify_one();
57
- }
46
+ // Manual unlocking is done before notifying, to avoid waking up
47
+ // the waiting thread only to block again (see notify_one for details)
48
+ lock.unlock();
49
+ cv_.notify_one();
50
+ }
58
51
 
59
- void RNSkDispatchQueue::dispatch_thread_handler(void)
60
- {
61
- std::unique_lock<std::mutex> lock(lock_);
52
+ void RNSkDispatchQueue::dispatch_thread_handler(void) {
53
+ std::unique_lock<std::mutex> lock(lock_);
62
54
 
63
- do
64
- {
65
- // Wait until we have data or a quit signal
66
- cv_.wait(lock, [this]
67
- { return (q_.size() || quit_); });
55
+ do {
56
+ // Wait until we have data or a quit signal
57
+ cv_.wait(lock, [this] { return (q_.size() || quit_); });
68
58
 
69
- // after wait, we own the lock
70
- if (!quit_ && q_.size())
71
- {
72
- auto op = std::move(q_.front());
73
- q_.pop();
59
+ // after wait, we own the lock
60
+ if (!quit_ && q_.size()) {
61
+ auto op = std::move(q_.front());
62
+ q_.pop();
74
63
 
75
- // unlock now that we're done messing with the queue
76
- lock.unlock();
64
+ // unlock now that we're done messing with the queue
65
+ lock.unlock();
77
66
 
78
- op();
67
+ op();
79
68
 
80
- lock.lock();
81
- }
82
- } while (!quit_);
83
- }
69
+ lock.lock();
70
+ }
71
+ } while (!quit_);
72
+ }
84
73
  } // namespace RNSkia
@@ -1,3 +1,5 @@
1
+ #pragma once
2
+
1
3
  #include <condition_variable>
2
4
  #include <cstdint>
3
5
  #include <cstdio>
@@ -15,7 +17,7 @@ class RNSkDispatchQueue {
15
17
  typedef std::function<void(void)> fp_t;
16
18
 
17
19
  public:
18
- RNSkDispatchQueue(std::string name, size_t thread_cnt = 1);
20
+ explicit RNSkDispatchQueue(std::string name, size_t thread_cnt = 1);
19
21
 
20
22
  ~RNSkDispatchQueue();
21
23
 
@@ -13,11 +13,9 @@
13
13
 
14
14
  namespace RNSkia {
15
15
 
16
- using namespace facebook;
17
- using namespace RNJsi;
18
- using namespace std::chrono;
16
+ namespace jsi = facebook::jsi;
19
17
 
20
- class RNSkInfoObject : public JsiHostObject {
18
+ class RNSkInfoObject : public RNJsi::JsiHostObject {
21
19
  public:
22
20
  JSI_PROPERTY_GET(width) { return _width; }
23
21
  JSI_PROPERTY_GET(height) { return _height; }
@@ -34,9 +32,10 @@ public:
34
32
  touchObj.setProperty(runtime, "x", t.x);
35
33
  touchObj.setProperty(runtime, "y", t.y);
36
34
  touchObj.setProperty(runtime, "force", t.force);
37
- touchObj.setProperty(runtime, "type", (double)t.type);
38
- touchObj.setProperty(runtime, "timestamp", (double)t.timestamp / 1000.0);
39
- touchObj.setProperty(runtime, "id", (double)t.id);
35
+ touchObj.setProperty(runtime, "type", static_cast<double>(t.type));
36
+ touchObj.setProperty(runtime, "timestamp",
37
+ static_cast<double>(t.timestamp / 1000.0));
38
+ touchObj.setProperty(runtime, "id", static_cast<double>(t.id));
40
39
  touches.setValueAtIndex(runtime, n, touchObj);
41
40
  }
42
41
  ops.setValueAtIndex(runtime, i, touches);
@@ -67,13 +66,14 @@ public:
67
66
 
68
67
  void endDrawOperation() { _touchesCache.clear(); }
69
68
 
70
- void updateTouches(std::vector<RNSkTouchInfo>& touches) {
69
+ void updateTouches(std::vector<RNSkTouchInfo> &touches) {
71
70
  std::lock_guard<std::mutex> lock(_mutex);
72
71
  // Add timestamp
73
- auto ms = std::chrono::duration_cast<milliseconds>(
74
- system_clock::now().time_since_epoch()).count();
75
-
76
- for(size_t i=0; i<touches.size(); i++) {
72
+ auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(
73
+ std::chrono::system_clock::now().time_since_epoch())
74
+ .count();
75
+
76
+ for (size_t i = 0; i < touches.size(); i++) {
77
77
  touches.at(i).timestamp = ms;
78
78
  }
79
79
  _currentTouches.push_back(std::move(touches));