react-native-unistyles 3.0.16 → 3.0.17

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.
package/README.md CHANGED
@@ -21,14 +21,14 @@ yarn add react-native-unistyles
21
21
  Install dependencies:
22
22
 
23
23
  ```shell
24
- yarn add react-native-edge-to-edge react-native-nitro-modules@0.31.2
24
+ yarn add react-native-edge-to-edge react-native-nitro-modules@0.31.3
25
25
  ```
26
26
 
27
27
  > To avoid unexpected behavior, always use a fixed version of `react-native-nitro-modules`
28
28
 
29
29
  | react-native-unistyles | react-native-nitro-modules |
30
30
  |------------------------|----------------------------|
31
- | 3.0.0 | 0.31.2 |
31
+ | 3.0.0 | 0.31.3 |
32
32
 
33
33
  Then follow [installation guides](https://unistyl.es/v3/start/getting-started) for your platform.
34
34
 
@@ -74,6 +74,9 @@ Then follow [installation guides](https://unistyl.es/v3/start/getting-started) f
74
74
  <a href="https://github.com/kerwanp">
75
75
  <img src="https://avatars.githubusercontent.com/u/36955373?v=4" height="70px" width="70px" alt="kerwanp" />
76
76
  </a>
77
+ <a href="https://github.com/rauchg">
78
+ <img src="https://avatars.githubusercontent.com/u/13041?v=4" height="70px" width="70px" alt="rauchg" />
79
+ </a>
77
80
 
78
81
  ## Past sponsors
79
82
 
@@ -251,9 +251,9 @@ void HybridStyleSheet::loadExternalMethods(const jsi::Value& thisValue, jsi::Run
251
251
  auto maybeProcessColorFn = jsMethods.asObject(rt).getProperty(rt, "processColor");
252
252
 
253
253
  helpers::assertThat(rt, maybeProcessColorFn.isObject(), "Unistyles: Can't load processColor function from JS.");
254
-
254
+
255
255
  auto maybeParseBoxShadowStringFn = jsMethods.asObject(rt).getProperty(rt, "parseBoxShadowString");
256
-
256
+
257
257
  helpers::assertThat(rt, maybeParseBoxShadowStringFn.isObject(), "Unistyles: Can't load parseBoxShadowString function from JS.");
258
258
 
259
259
  auto processColorFn = maybeProcessColorFn.asObject(rt).asFunction(rt);
@@ -386,25 +386,36 @@ void HybridStyleSheet::onImeChange(UnistylesNativeMiniRuntime miniRuntime) {
386
386
  }
387
387
 
388
388
  void HybridStyleSheet::notifyJSListeners(std::vector<UnistyleDependency>& dependencies) {
389
- if (!dependencies.empty()) {
390
- std::for_each(this->_changeListeners.begin(), this->_changeListeners.end(), [&](auto& listener){
391
- (*listener)(dependencies);
392
- });
389
+ if (dependencies.empty()) {
390
+ return;
391
+ }
392
+
393
+ std::vector<std::function<void(std::vector<UnistyleDependency>&)>> callbacks;
394
+ {
395
+ std::lock_guard<std::mutex> lock(this->_listenersMutex);
396
+ callbacks.reserve(this->_changeListeners.size());
397
+
398
+ for (auto& [id, listener] : this->_changeListeners) {
399
+ callbacks.push_back(*listener);
400
+ }
401
+ }
402
+
403
+ for (auto& callback : callbacks) {
404
+ callback(dependencies);
393
405
  }
394
406
  }
395
407
 
396
408
  std::function<void ()> HybridStyleSheet::addChangeListener(const std::function<void (const std::vector<UnistyleDependency>&)>& onChanged) {
397
- auto listener = std::make_unique<std::function<void(std::vector<UnistyleDependency>&)>>(onChanged);
409
+ static size_t nextListenerId = 0;
398
410
 
399
- this->_changeListeners.push_back(std::move(listener));
411
+ std::lock_guard<std::mutex> lock(this->_listenersMutex);
400
412
 
401
- return [this, listenerPtr = this->_changeListeners.back().get()](){
402
- auto it = std::find_if(this->_changeListeners.begin(), this->_changeListeners.end(), [listenerPtr](auto& ptr) {
403
- return ptr.get() == listenerPtr;
404
- });
413
+ size_t id = nextListenerId++;
414
+ auto listener = std::make_unique<std::function<void(std::vector<UnistyleDependency>&)>>(onChanged);
415
+ this->_changeListeners[id] = std::move(listener);
405
416
 
406
- if (it != this->_changeListeners.end()) {
407
- this->_changeListeners.erase(it);
408
- }
417
+ return [this, id](){
418
+ std::lock_guard<std::mutex> lock(this->_listenersMutex);
419
+ this->_changeListeners.erase(id);
409
420
  };
410
421
  }
@@ -2,6 +2,8 @@
2
2
 
3
3
  #include <cmath>
4
4
  #include <jsi/jsi.h>
5
+ #include <mutex>
6
+ #include <unordered_map>
5
7
  #include "HybridUnistylesRuntime.h"
6
8
  #include "HybridUnistylesStyleSheetSpec.hpp"
7
9
  #include "RNStyle.h"
@@ -72,7 +74,8 @@ private:
72
74
 
73
75
  bool isInitialized = false;
74
76
  double __unid = -1;
75
- std::vector<std::unique_ptr<const std::function<void(std::vector<UnistyleDependency>&)>>> _changeListeners{};
77
+ std::unordered_map<size_t, std::unique_ptr<std::function<void(std::vector<UnistyleDependency>&)>>> _changeListeners{};
78
+ std::mutex _listenersMutex;
76
79
  std::shared_ptr<HybridUnistylesRuntime> _unistylesRuntime;
77
80
  std::shared_ptr<UIManager> _uiManager;
78
81
  };
@@ -60,6 +60,12 @@ namespace margelo::nitro::unistyles {
60
60
  method(_javaPart);
61
61
  }
62
62
 
63
+ std::string JHybridNativePlatformSpec::toString() {
64
+ static const auto method = javaClassStatic()->getMethod<jni::JString()>("toString");
65
+ auto javaString = method(_javaPart);
66
+ return javaString->toStdString();
67
+ }
68
+
63
69
  // Properties
64
70
 
65
71
 
@@ -41,6 +41,7 @@ namespace margelo::nitro::unistyles {
41
41
  public:
42
42
  size_t getExternalMemorySize() noexcept override;
43
43
  void dispose() noexcept override;
44
+ std::string toString() override;
44
45
 
45
46
  public:
46
47
  inline const jni::global_ref<JHybridNativePlatformSpec::javaobject>& getJavaPart() const noexcept {
@@ -24,6 +24,8 @@ data class Dimensions(
24
24
  @Keep
25
25
  val height: Double
26
26
  ) {
27
+ /* primary constructor */
28
+
27
29
  private companion object {
28
30
  /**
29
31
  * Constructor called from C++
@@ -36,6 +36,11 @@ abstract class HybridNativePlatformSpec: HybridObject() {
36
36
  super.updateNative(hybridData)
37
37
  }
38
38
 
39
+ // Default implementation of `HybridObject.toString()`
40
+ override fun toString(): String {
41
+ return "[HybridObject NativePlatform]"
42
+ }
43
+
39
44
  // Properties
40
45
 
41
46
 
@@ -33,6 +33,8 @@ data class Insets(
33
33
  @Keep
34
34
  val ime: Double
35
35
  ) {
36
+ /* primary constructor */
37
+
36
38
  private companion object {
37
39
  /**
38
40
  * Constructor called from C++
@@ -51,6 +51,8 @@ data class UnistylesNativeMiniRuntime(
51
51
  @Keep
52
52
  val isLandscape: Boolean
53
53
  ) {
54
+ /* primary constructor */
55
+
54
56
  private companion object {
55
57
  /**
56
58
  * Constructor called from C++
@@ -69,6 +69,9 @@ namespace margelo::nitro::unistyles {
69
69
  void dispose() noexcept override {
70
70
  _swiftPart.dispose();
71
71
  }
72
+ std::string toString() override {
73
+ return _swiftPart.toString();
74
+ }
72
75
 
73
76
  public:
74
77
  // Properties
@@ -34,6 +34,13 @@ public protocol HybridNativePlatformSpec_protocol: HybridObject {
34
34
  func unregisterPlatformListeners() throws -> Void
35
35
  }
36
36
 
37
+ public extension HybridNativePlatformSpec_protocol {
38
+ /// Default implementation of ``HybridObject.toString``
39
+ func toString() -> String {
40
+ return "[HybridObject NativePlatform]"
41
+ }
42
+ }
43
+
37
44
  /// See ``HybridNativePlatformSpec``
38
45
  open class HybridNativePlatformSpec_base {
39
46
  private weak var cxxWrapper: HybridNativePlatformSpec_cxx? = nil
@@ -76,7 +76,7 @@ open class HybridNativePlatformSpec_cxx {
76
76
  */
77
77
  public func getCxxPart() -> bridge.std__shared_ptr_HybridNativePlatformSpec_ {
78
78
  let cachedCxxPart = self.__cxxPart.lock()
79
- if cachedCxxPart.__convertToBool() {
79
+ if Bool(fromCxx: cachedCxxPart) {
80
80
  return cachedCxxPart
81
81
  } else {
82
82
  let newCxxPart = bridge.create_std__shared_ptr_HybridNativePlatformSpec_(self.toUnsafe())
@@ -105,6 +105,14 @@ open class HybridNativePlatformSpec_cxx {
105
105
  self.__implementation.dispose()
106
106
  }
107
107
 
108
+ /**
109
+ * Call toString() on the Swift class.
110
+ */
111
+ @inline(__always)
112
+ public func toString() -> String {
113
+ return self.__implementation.toString()
114
+ }
115
+
108
116
  // Properties
109
117
 
110
118
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "3.0.16",
3
+ "version": "3.0.17",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "NODE_ENV=babel-test jest ./plugin",
@@ -11,7 +11,6 @@
11
11
  "check:ci": "biome check",
12
12
  "prepare": "husky && bob build && yarn plugin:build && yarn repack:plugin:build",
13
13
  "precommit": "concurrently 'yarn tsc' 'yarn lint' 'yarn check' 'yarn test' 'yarn circular:check'",
14
- "release": "release-it",
15
14
  "plugin:build": "node plugin/esbuild.js",
16
15
  "repack:plugin:build": "node repack-plugin/esbuild.js",
17
16
  "circular:check": "dpdm --no-warning --no-tree -T --exit-code circular:1 src/**/*.ts",
@@ -136,7 +135,6 @@
136
135
  "@callstack/repack": "5.1.0",
137
136
  "@commitlint/config-conventional": "19.8.1",
138
137
  "@react-native/normalize-colors": "0.79.2",
139
- "@release-it/conventional-changelog": "8.0.2",
140
138
  "@rspack/core": "1.3.10",
141
139
  "@types/jest": "29.5.14",
142
140
  "@types/react": "19.1.4",
@@ -148,15 +146,14 @@
148
146
  "husky": "9.1.7",
149
147
  "jest": "29.7.0",
150
148
  "metro-react-native-babel-preset": "0.77.0",
151
- "nitrogen": "0.31.2",
149
+ "nitrogen": "0.31.3",
152
150
  "react": "19.1.0",
153
151
  "react-native": "0.79.2",
154
152
  "react-native-builder-bob": "0.40.10",
155
- "react-native-nitro-modules": "0.31.2",
153
+ "react-native-nitro-modules": "0.31.3",
156
154
  "react-native-reanimated": "3.17.5",
157
155
  "react-native-web": "0.20.0",
158
156
  "react-test-renderer": "19.1.0",
159
- "release-it": "17.11.0",
160
157
  "typescript": "5.8.3"
161
158
  },
162
159
  "peerDependencies": {
@@ -200,63 +197,6 @@
200
197
  "@commitlint/config-conventional"
201
198
  ]
202
199
  },
203
- "release-it": {
204
- "git": {
205
- "commitMessage": "chore: release ${version}",
206
- "tagName": "v${version}"
207
- },
208
- "npm": {
209
- "publish": true
210
- },
211
- "github": {
212
- "release": true
213
- },
214
- "plugins": {
215
- "@release-it/conventional-changelog": {
216
- "writerOpts": {
217
- "groupBy": "type",
218
- "commitGroupsSort": [
219
- "feat",
220
- "fix",
221
- "perf",
222
- "refactor",
223
- "docs",
224
- "chore"
225
- ],
226
- "commitsSort": [
227
- "scope",
228
- "subject"
229
- ]
230
- },
231
- "types": [
232
- {
233
- "type": "feat",
234
- "section": "Features"
235
- },
236
- {
237
- "type": "fix",
238
- "section": "Bug Fixes"
239
- },
240
- {
241
- "type": "perf",
242
- "section": "Performance Improvements"
243
- },
244
- {
245
- "type": "refactor",
246
- "section": "Code Refactoring"
247
- },
248
- {
249
- "type": "docs",
250
- "section": "Documentation"
251
- },
252
- {
253
- "type": "chore",
254
- "section": "Maintenance"
255
- }
256
- ]
257
- }
258
- }
259
- },
260
200
  "react-native-builder-bob": {
261
201
  "source": "src",
262
202
  "output": "lib",
package/plugin/index.js CHANGED
@@ -355,14 +355,33 @@ function isKindOfStyleSheet(path2, state) {
355
355
  if (path2.node.arguments.length !== 1) {
356
356
  return false;
357
357
  }
358
- if (!t4.isObjectExpression(path2.node.arguments[0])) {
358
+ const { callee } = path2.node;
359
+ const isCreateCall = t4.isMemberExpression(callee) && t4.isIdentifier(callee.property) && callee.property.name === "create" && (t4.isIdentifier(callee.object) || t4.isMemberExpression(callee.object));
360
+ if (!isCreateCall) {
359
361
  return false;
360
362
  }
361
- if (!path2.node.arguments[0].properties.some((property) => t4.isObjectProperty(property) && t4.isObjectExpression(property.value))) {
363
+ const argument = path2.node.arguments[0];
364
+ if (t4.isArrowFunctionExpression(argument)) {
365
+ if (argument.params.length > 2) {
366
+ return false;
367
+ }
368
+ if (t4.isObjectExpression(argument.body) && argument.body.properties.length > 0) {
369
+ return true;
370
+ }
371
+ if (t4.isBlockStatement(argument.body)) {
372
+ const returnStatements = getReturnStatementsFromBody(argument.body);
373
+ return returnStatements.some(
374
+ (ret) => ret.argument && t4.isObjectExpression(ret.argument) && ret.argument.properties.length > 0
375
+ );
376
+ }
362
377
  return false;
363
378
  }
364
- const { callee } = path2.node;
365
- return t4.isMemberExpression(callee) && t4.isIdentifier(callee.property) && callee.property.name === "create" && t4.isIdentifier(callee.object);
379
+ if (t4.isObjectExpression(argument)) {
380
+ return argument.properties.some(
381
+ (property) => t4.isObjectProperty(property) && t4.isObjectExpression(property.value)
382
+ );
383
+ }
384
+ return false;
366
385
  }
367
386
  function addStyleSheetTag(path2, state) {
368
387
  const str = state.filename?.replace(state.cwd, "") ?? "";