react-native-unistyles 3.0.0-beta.7 → 3.0.0-beta.8

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.
Files changed (79) hide show
  1. package/README.md +16 -0
  2. package/android/CMakeLists.txt +2 -1
  3. package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +9 -1
  4. package/cxx/common/Helpers.h +85 -0
  5. package/cxx/core/UnistylesCommitHook.cpp +20 -17
  6. package/cxx/core/UnistylesMountHook.cpp +2 -2
  7. package/cxx/core/UnistylesMountHook.h +1 -4
  8. package/cxx/core/UnistylesRegistry.cpp +8 -6
  9. package/cxx/hybridObjects/HybridShadowRegistry.cpp +2 -5
  10. package/cxx/hybridObjects/HybridStyleSheet.cpp +1 -1
  11. package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +5 -1
  12. package/cxx/parser/Parser.cpp +74 -9
  13. package/cxx/shadowTree/ShadowTrafficController.h +10 -4
  14. package/cxx/shadowTree/ShadowTreeManager.cpp +38 -35
  15. package/lib/commonjs/components/native/ImageBackground.js +26 -30
  16. package/lib/commonjs/components/native/ImageBackground.js.map +1 -1
  17. package/lib/commonjs/components/native/Pressable.native.js +12 -1
  18. package/lib/commonjs/components/native/Pressable.native.js.map +1 -1
  19. package/lib/commonjs/core/createUnistylesElement.native.js +4 -0
  20. package/lib/commonjs/core/createUnistylesElement.native.js.map +1 -1
  21. package/lib/commonjs/core/createUnistylesImageBackground.js +4 -0
  22. package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -1
  23. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js +1 -1
  24. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  25. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +14 -7
  26. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
  27. package/lib/commonjs/specs/ShadowRegistry/index.js +1 -1
  28. package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
  29. package/lib/module/components/native/ImageBackground.js +26 -30
  30. package/lib/module/components/native/ImageBackground.js.map +1 -1
  31. package/lib/module/components/native/Pressable.native.js +12 -1
  32. package/lib/module/components/native/Pressable.native.js.map +1 -1
  33. package/lib/module/core/createUnistylesElement.native.js +4 -0
  34. package/lib/module/core/createUnistylesElement.native.js.map +1 -1
  35. package/lib/module/core/createUnistylesImageBackground.js +4 -0
  36. package/lib/module/core/createUnistylesImageBackground.js.map +1 -1
  37. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js +1 -1
  38. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  39. package/lib/module/core/withUnistyles/withUnistyles.native.js +14 -7
  40. package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
  41. package/lib/module/specs/ShadowRegistry/index.js +1 -1
  42. package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
  43. package/lib/typescript/src/components/native/ImageBackground.d.ts.map +1 -1
  44. package/lib/typescript/src/components/native/Pressable.native.d.ts.map +1 -1
  45. package/lib/typescript/src/core/createUnistylesElement.native.d.ts.map +1 -1
  46. package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -1
  47. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -1
  48. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
  49. package/lib/typescript/src/types/stylesheet.d.ts +1 -1
  50. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
  51. package/nitrogen/generated/android/c++/JFunc_void_UnistylesNativeMiniRuntime.hpp +2 -2
  52. package/nitrogen/generated/android/c++/JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.hpp +2 -2
  53. package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.cpp +19 -19
  54. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_UnistylesNativeMiniRuntime.kt +7 -2
  55. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.kt +7 -2
  56. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/HybridNativePlatformSpec.kt +22 -22
  57. package/nitrogen/generated/android/unistyles+autolinking.cmake +16 -0
  58. package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Umbrella.hpp +0 -1
  59. package/nitrogen/generated/shared/c++/Dimensions.hpp +1 -0
  60. package/nitrogen/generated/shared/c++/Insets.hpp +1 -0
  61. package/nitrogen/generated/shared/c++/UnistylesCxxMiniRuntime.hpp +1 -0
  62. package/nitrogen/generated/shared/c++/UnistylesNativeMiniRuntime.hpp +1 -0
  63. package/package.json +28 -18
  64. package/plugin/index.d.ts +51 -18
  65. package/plugin/index.js +791 -178
  66. package/src/components/native/ImageBackground.tsx +3 -4
  67. package/src/components/native/Pressable.native.tsx +16 -1
  68. package/src/core/createUnistylesElement.native.tsx +5 -0
  69. package/src/core/createUnistylesImageBackground.tsx +5 -0
  70. package/src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts +1 -1
  71. package/src/core/withUnistyles/withUnistyles.native.tsx +40 -14
  72. package/src/specs/ShadowRegistry/index.ts +1 -0
  73. package/src/types/stylesheet.ts +1 -1
  74. package/plugin/consts.js +0 -63
  75. package/plugin/exotic.js +0 -54
  76. package/plugin/import.js +0 -51
  77. package/plugin/ref.js +0 -11
  78. package/plugin/stylesheet.js +0 -565
  79. package/plugin/variants.js +0 -66
package/README.md CHANGED
@@ -18,6 +18,19 @@
18
18
  yarn add react-native-unistyles@beta
19
19
  ```
20
20
 
21
+ Install dependencies:
22
+
23
+ ```shell
24
+ yarn add react-native-edge-to-edge react-native-nitro-modules@0.22.1
25
+ ```
26
+
27
+ > Always use fixed version of `react-native-nitro-modules` to avoid unexpected behaviors.
28
+
29
+ | react-native-unistyles | react-native-nitro-modules |
30
+ |------------------------|----------------------------|
31
+ | 3.0.0.beta.7 | 0.22.1 |
32
+ | 3.0.0.nightly-20250226 | 0.24.1 |
33
+
21
34
  Then follow [installation guides](https://unistyl.es/v3/start/getting-started) for your platform.
22
35
 
23
36
  ## [Documentation](https://unistyl.es/)
@@ -77,6 +90,9 @@ Then follow [installation guides](https://unistyl.es/v3/start/getting-started) f
77
90
  <a href="https://github.com/dacoto97">
78
91
  <img src="https://avatars.githubusercontent.com/u/16915053?v=4" height="70px" width="70px" alt="dacoto97" />
79
92
  </a>
93
+ <a href="https://github.com/chinamcafee">
94
+ <img src="https://avatars.githubusercontent.com/u/3439961?v=4" height="70px" width="70px" alt="chinamcafee" />
95
+ </a>
80
96
 
81
97
  ## Past sponsors
82
98
 
@@ -23,7 +23,8 @@ include_directories(
23
23
  ../cxx/shadowTree
24
24
  )
25
25
 
26
- string(APPEND CMAKE_CXX_FLAGS " -DFOLLY_NO_CONFIG=1 -DFOLLY_CFG_NO_COROUTINES=1 -DFOLLY_MOBILE=1")
26
+ # Nitro appends all Folly Flags, leaving it empty
27
+ string(APPEND CMAKE_CXX_FLAGS " ")
27
28
 
28
29
  set_target_properties(unistyles PROPERTIES
29
30
  CXX_STANDARD 20
@@ -24,6 +24,7 @@ class NativePlatformInsets(
24
24
  private val getMiniRuntime: () -> UnistylesNativeMiniRuntime,
25
25
  private val diffMiniRuntime: () -> Array<UnistyleDependency>
26
26
  ) {
27
+ private var _shouldListenToImeEvents = false
27
28
  private val _imeListeners: MutableList<CxxImeListener> = mutableListOf()
28
29
  private var _insets: Insets = Insets(0.0, 0.0, 0.0, 0.0, 0.0)
29
30
 
@@ -113,6 +114,8 @@ class NativePlatformInsets(
113
114
  }
114
115
 
115
116
  fun startInsetsListener() {
117
+ _shouldListenToImeEvents = true
118
+
116
119
  reactContext.currentActivity?.let { activity ->
117
120
  activity.findViewById<View>(android.R.id.content)?.let { mainView ->
118
121
  ViewCompat.setOnApplyWindowInsetsListener(mainView) { _, insets ->
@@ -130,6 +133,10 @@ class NativePlatformInsets(
130
133
  insets: WindowInsetsCompat,
131
134
  runningAnimations: List<WindowInsetsAnimationCompat>
132
135
  ): WindowInsetsCompat {
136
+ if (!_shouldListenToImeEvents) {
137
+ return insets
138
+ }
139
+
133
140
  runningAnimations.firstOrNull()?.let {
134
141
  val bottomInset = insets.getInsets(WindowInsetsCompat.Type.ime()).bottom.toDouble() - this@NativePlatformInsets._insets.bottom
135
142
  val nextBottomInset = if (bottomInset < 0) {
@@ -160,9 +167,10 @@ class NativePlatformInsets(
160
167
  reactContext.currentActivity?.let { activity ->
161
168
  activity.window?.decorView?.let { view ->
162
169
  ViewCompat.setOnApplyWindowInsetsListener(view, null)
163
- ViewCompat.setWindowInsetsAnimationCallback(view, null)
164
170
  }
165
171
  }
172
+
173
+ _shouldListenToImeEvents = false
166
174
  }
167
175
 
168
176
  fun addImeListener(listener: CxxImeListener) {
@@ -225,4 +225,89 @@ inline static jsi::Array dependenciesToJSIArray(jsi::Runtime& rt, const std::vec
225
225
  return result;
226
226
  }
227
227
 
228
+ inline void debugPrintJSIObject(jsi::Runtime& rt, std::string& name, jsi::Object& obj) {
229
+ auto console = rt.global().getPropertyAsObject(rt, "console");
230
+ auto log = console.getPropertyAsFunction(rt, "log");
231
+ auto parser = [&](const std::string& key, jsi::Value& value){
232
+ if (value.isBool()) {
233
+ std::string output = key + ": " + (value.getBool() ? "true" : "false");
234
+ log.call(rt, output);
235
+
236
+ return;
237
+ }
238
+
239
+ if (value.isNumber()) {
240
+ std::string output = key + ": " + std::to_string(value.getNumber());
241
+ log.call(rt, output);
242
+
243
+ return;
244
+ }
245
+
246
+ if (value.isString()) {
247
+ std::string output = key + ": " + value.getString(rt).utf8(rt);
248
+ log.call(rt, output);
249
+
250
+ return;
251
+ }
252
+
253
+ if (value.isUndefined()) {
254
+ std::string output = key + ": undefined";
255
+ log.call(rt, output);
256
+
257
+ return;
258
+ }
259
+
260
+ if (value.isNull()) {
261
+ std::string output = key + ": null";
262
+ log.call(rt, output);
263
+
264
+ return;
265
+ }
266
+ };
267
+
268
+ log.call(rt, "===" + name + "===");
269
+
270
+ enumerateJSIObject(rt, obj, [&](const std::string& key, jsi::Value& value){
271
+ if (value.isObject()) {
272
+ if (value.asObject(rt).isArray(rt)) {
273
+ iterateJSIArray(rt, value.asObject(rt).asArray(rt), [&](size_t i, jsi::Value& nestedValue){
274
+ std::string printableKey = key + ": Array[" + std::to_string(i) + "]";
275
+
276
+ log.call(rt, printableKey);
277
+
278
+ if (nestedValue.isObject()) {
279
+ enumerateJSIObject(rt, nestedValue.asObject(rt), [&](const std::string& nestedKey, jsi::Value& nestedValue){
280
+ parser(nestedKey, nestedValue);
281
+ });
282
+ } else {
283
+ parser(printableKey, nestedValue);
284
+ }
285
+
286
+ std::string endKey = key + ": Array[end]";
287
+
288
+ log.call(rt, endKey);
289
+ });
290
+ }
291
+
292
+ if (value.asObject(rt).isFunction(rt)) {
293
+ std::string output = key + ": [Function]";
294
+
295
+ log.call(rt, output);
296
+
297
+ return;
298
+ }
299
+
300
+ enumerateJSIObject(rt, value.asObject(rt), [&](const std::string& nestedKey, jsi::Value& nestedValue){
301
+ parser(nestedKey, nestedValue);
302
+ });
303
+
304
+ return;
305
+ }
306
+
307
+ parser(key, value);
308
+ });
309
+
310
+ log.call(rt, "===/" + name + "===");
311
+ }
312
+
228
313
  }
@@ -29,21 +29,24 @@ RootShadowNode::Unshared core::UnistylesCommitHook::shadowTreeWillCommit(
29
29
  // this is React Native / Reanimated commit
30
30
  // merge Unistyles updates before it completes
31
31
  auto& registry = core::UnistylesRegistry::get();
32
- auto& shadowLeafUpdates = registry.trafficController.getUpdates();
33
-
34
- // oops, no updates from Unistyles yet, skip it!
35
- if (shadowLeafUpdates.size() == 0) {
36
- return newRootShadowNode;
37
- }
38
-
39
- auto affectedNodes = shadow::ShadowTreeManager::findAffectedNodes(*rootNode, shadowLeafUpdates);
40
-
41
- registry.trafficController.stopUnistylesTraffic();
42
-
43
- // we have few updates, so merge it
44
- return std::static_pointer_cast<RootShadowNode>(shadow::ShadowTreeManager::cloneShadowTree(
45
- *rootNode,
46
- shadowLeafUpdates,
47
- affectedNodes
48
- ));
32
+
33
+ return registry.trafficController.withLock([&](){
34
+ auto& shadowLeafUpdates = registry.trafficController.getUpdates();
35
+
36
+ // oops, no updates from Unistyles yet, skip it!
37
+ if (shadowLeafUpdates.size() == 0) {
38
+ return newRootShadowNode;
39
+ }
40
+
41
+ auto affectedNodes = shadow::ShadowTreeManager::findAffectedNodes(*rootNode, shadowLeafUpdates);
42
+
43
+ registry.trafficController.stopUnistylesTraffic();
44
+
45
+ // we have few updates, so merge it
46
+ return std::static_pointer_cast<RootShadowNode>(shadow::ShadowTreeManager::cloneShadowTree(
47
+ *rootNode,
48
+ shadowLeafUpdates,
49
+ affectedNodes
50
+ ));
51
+ });
49
52
  }
@@ -22,7 +22,7 @@ void core::UnistylesMountHook::shadowTreeDidMount(RootShadowNode::Shared const &
22
22
  // one more time merge Unistyles changes
23
23
  auto& registry = core::UnistylesRegistry::get();
24
24
 
25
- if (!registry.trafficController.shouldStop()) {
26
- shadow::ShadowTreeManager::updateShadowTree(this->_uiManager->getShadowTreeRegistry());
25
+ if (registry.trafficController.shouldStop()) {
26
+ registry.trafficController.resumeUnistylesTraffic();
27
27
  }
28
28
  }
@@ -3,15 +3,13 @@
3
3
  #include <react/renderer/uimanager/UIManager.h>
4
4
  #include <react/renderer/uimanager/UIManagerMountHook.h>
5
5
  #include "ShadowTreeManager.h"
6
- #include "HybridUnistylesRuntime.h"
7
6
 
8
7
  namespace margelo::nitro::unistyles::core {
9
8
 
10
9
  using namespace facebook::react;
11
10
 
12
11
  struct UnistylesMountHook : public UIManagerMountHook {
13
- UnistylesMountHook(std::shared_ptr<UIManager> uiManager, std::shared_ptr<HybridUnistylesRuntime> unistylesRuntime)
14
- : _uiManager{uiManager}, _unistylesRuntime{unistylesRuntime} {
12
+ UnistylesMountHook(std::shared_ptr<UIManager> uiManager): _uiManager{uiManager} {
15
13
  _uiManager->registerMountHook(*this);
16
14
  }
17
15
 
@@ -21,7 +19,6 @@ struct UnistylesMountHook : public UIManagerMountHook {
21
19
 
22
20
  private:
23
21
  std::shared_ptr<UIManager> _uiManager;
24
- std::shared_ptr<HybridUnistylesRuntime> _unistylesRuntime;
25
22
  };
26
23
 
27
24
  }
@@ -108,12 +108,14 @@ void core::UnistylesRegistry::removeDuplicatedUnistyles(jsi::Runtime& rt, const
108
108
  }
109
109
 
110
110
  void core::UnistylesRegistry::unlinkShadowNodeWithUnistyles(jsi::Runtime& rt, const ShadowNodeFamily* shadowNodeFamily) {
111
- this->_shadowRegistry[&rt].erase(shadowNodeFamily);
112
- this->trafficController.removeShadowNode(shadowNodeFamily);
113
-
114
- if (this->_shadowRegistry[&rt].empty()) {
115
- this->_shadowRegistry.erase(&rt);
116
- }
111
+ this->trafficController.withLock([this, &rt, shadowNodeFamily](){
112
+ this->_shadowRegistry[&rt].erase(shadowNodeFamily);
113
+ this->trafficController.removeShadowNode(shadowNodeFamily);
114
+
115
+ if (this->_shadowRegistry[&rt].empty()) {
116
+ this->_shadowRegistry.erase(&rt);
117
+ }
118
+ });
117
119
  }
118
120
 
119
121
  std::shared_ptr<core::StyleSheet> core::UnistylesRegistry::addStyleSheet(jsi::Runtime& rt, int unid, core::StyleSheetType type, jsi::Object&& rawValue) {
@@ -49,7 +49,6 @@ jsi::Value HybridShadowRegistry::link(jsi::Runtime &rt, const jsi::Value &thisVa
49
49
  }
50
50
 
51
51
  auto parser = parser::Parser(this->_unistylesRuntime);
52
- auto parsedStyleSheet = jsi::Value::undefined();
53
52
  std::vector<std::shared_ptr<core::UnistyleData>> unistylesData{};
54
53
 
55
54
  // create unistyleData based on wrappers
@@ -77,10 +76,8 @@ jsi::Value HybridShadowRegistry::link(jsi::Runtime &rt, const jsi::Value &thisVa
77
76
  );
78
77
 
79
78
  // before linking we need to check if given unistyle is affected by scoped theme
80
- if (scopedTheme.has_value()) {
81
- if (parsedStyleSheet.isUndefined()) {
82
- parsedStyleSheet = parser.getParsedStyleSheetForScopedTheme(rt, unistyle, scopedTheme.value());
83
- }
79
+ if (scopedTheme.has_value() && unistyle->styleKey != helpers::EXOTIC_STYLE_KEY) {
80
+ auto parsedStyleSheet = parser.getParsedStyleSheetForScopedTheme(rt, unistyle, scopedTheme.value());
84
81
 
85
82
  // if so we need to force update
86
83
  parser.rebuildUnistyleWithScopedTheme(rt, parsedStyleSheet, unistyleData);
@@ -261,7 +261,7 @@ void HybridStyleSheet::registerHooks(jsi::Runtime& rt) {
261
261
  core::UnistylesRegistry::get().trafficController.restore();
262
262
 
263
263
  this->_unistylesCommitHook = std::make_shared<core::UnistylesCommitHook>(this->_uiManager);
264
- this->_unistylesMountHook = std::make_shared<core::UnistylesMountHook>(this->_uiManager, this->_unistylesRuntime);
264
+ this->_unistylesMountHook = std::make_shared<core::UnistylesMountHook>(this->_uiManager);
265
265
  }
266
266
 
267
267
  void HybridStyleSheet::onPlatformDependenciesChange(std::vector<UnistyleDependency> dependencies) {
@@ -73,9 +73,13 @@ void HybridUnistylesRuntime::setTheme(const std::string &themeName) {
73
73
  helpers::assertThat(*_rt, !this->getHasAdaptiveThemes(), "Unistyles: You're trying to set theme to: '" + themeName + "', but adaptiveThemes are enabled.");
74
74
 
75
75
  auto& state = core::UnistylesRegistry::get().getState(*_rt);
76
+ auto currentThemeName = state.getCurrentThemeName();
76
77
 
77
78
  state.setTheme(themeName);
78
- this->_onDependenciesChange({UnistyleDependency::THEME, UnistyleDependency::THEMENAME});
79
+
80
+ if (currentThemeName.value() != themeName) {
81
+ this->_onDependenciesChange({UnistyleDependency::THEME, UnistyleDependency::THEMENAME});
82
+ }
79
83
  };
80
84
 
81
85
  void HybridUnistylesRuntime::setAdaptiveThemes(bool isEnabled) {
@@ -62,10 +62,10 @@ jsi::Value parser::Parser::getParsedStyleSheetForScopedTheme(jsi::Runtime& rt, c
62
62
  .asObject(rt);
63
63
  }
64
64
 
65
- void parser::Parser::rebuildUnistyleWithScopedTheme(jsi::Runtime& rt, jsi::Value& jsScopedTheme, std::shared_ptr<core::UnistyleData> unistyleData) {
66
- auto parsedStyleSheet = jsScopedTheme.isUndefined()
65
+ void parser::Parser::rebuildUnistyleWithScopedTheme(jsi::Runtime& rt, jsi::Value& scopedStyleSheet, std::shared_ptr<core::UnistyleData> unistyleData) {
66
+ auto parsedStyleSheet = scopedStyleSheet.isUndefined()
67
67
  ? this->getParsedStyleSheetForScopedTheme(rt, unistyleData->unistyle, unistyleData->scopedTheme.value())
68
- : jsScopedTheme.asObject(rt);
68
+ : scopedStyleSheet.asObject(rt);
69
69
 
70
70
  if (parsedStyleSheet.isUndefined()) {
71
71
  return;
@@ -305,6 +305,7 @@ void parser::Parser::rebuildUnistylesInDependencyMap(jsi::Runtime& rt, Dependenc
305
305
  unistyle->rawValue = parsedStyleSheetsWithDefaultTheme[unistyleStyleSheet].asObject(rt).getProperty(rt, unistyle->styleKey.c_str()).asObject(rt);
306
306
  this->rebuildUnistyle(rt, unistyle, unistyleData->variants, unistyleData->dynamicFunctionMetadata);
307
307
  unistyleData->parsedStyle = jsi::Value(rt, unistyle->parsedStyle.value()).asObject(rt);
308
+ unistyle->isDirty = true;
308
309
  }
309
310
 
310
311
  if (!parsedUnistyles.contains(unistyle)) {
@@ -880,21 +881,43 @@ jsi::Value parser::Parser::parseSecondLevel(jsi::Runtime &rt, Unistyle::Shared u
880
881
 
881
882
  return;
882
883
  }
883
-
884
+
885
+ auto isArray = nestedObjectStyle.isArray(rt);
886
+
887
+ if (!isArray) {
888
+ parsedStyle.setProperty(rt, propertyName.c_str(), this->getValueFromBreakpoints(rt, unistyle, nestedObjectStyle));
889
+ }
890
+
884
891
  // possible with variants and compoundVariants
885
- if (nestedObjectStyle.isArray(rt) && propertyName == "transform") {
892
+ if (propertyName == "transform") {
886
893
  parsedStyle.setProperty(rt, propertyName.c_str(), parseTransforms(rt, unistyle, nestedObjectStyle));
887
894
 
888
895
  return;
889
896
  }
890
897
 
891
- if (nestedObjectStyle.isArray(rt) && propertyName == "fontVariant") {
898
+ if (propertyName == "boxShadow") {
899
+ parsedStyle.setProperty(rt, propertyName.c_str(), parseBoxShadow(rt, unistyle, nestedObjectStyle));
900
+
901
+ return;
902
+ }
903
+
904
+ if (propertyName == "filter") {
905
+ parsedStyle.setProperty(rt, propertyName.c_str(), parseFilters(rt, unistyle, nestedObjectStyle));
906
+
907
+ return;
908
+ }
909
+
910
+ if (propertyName == "fontVariant") {
892
911
  parsedStyle.setProperty(rt, propertyName.c_str(), propertyValue);
893
912
 
894
913
  return;
895
914
  }
896
915
 
897
- parsedStyle.setProperty(rt, propertyName.c_str(), this->getValueFromBreakpoints(rt, unistyle, nestedObjectStyle));
916
+ if (propertyName == "shadowOffset" || propertyName == "textShadowOffset") {
917
+ parsedStyle.setProperty(rt, propertyName.c_str(), this->parseSecondLevel(rt, unistyle, propertyValue));
918
+
919
+ return;
920
+ }
898
921
  });
899
922
 
900
923
  return parsedStyle;
@@ -908,7 +931,7 @@ folly::dynamic parser::Parser::parseStylesToShadowTreeStyles(jsi::Runtime& rt, c
908
931
  for (const auto& unistyleData : unistyles) {
909
932
  // this can happen for exotic stylesheets
910
933
  if (!unistyleData->parsedStyle.has_value()) {
911
- return nullptr;
934
+ continue;
912
935
  }
913
936
 
914
937
  helpers::enumerateJSIObject(rt, unistyleData->parsedStyle.value(), [&](const std::string& propertyName, jsi::Value& propertyValue){
@@ -916,7 +939,49 @@ folly::dynamic parser::Parser::parseStylesToShadowTreeStyles(jsi::Runtime& rt, c
916
939
  return convertedStyles.setProperty(rt, propertyName.c_str(), jsi::Value(state.parseColor(propertyValue)));
917
940
  }
918
941
 
919
- convertedStyles.setProperty(rt, propertyName.c_str(), propertyValue);
942
+ if (!propertyValue.isObject()) {
943
+ return convertedStyles.setProperty(rt, propertyName.c_str(), propertyValue);
944
+ }
945
+
946
+ auto objValue = propertyValue.asObject(rt);
947
+
948
+ if (!objValue.isArray(rt)) {
949
+ return convertedStyles.setProperty(rt, propertyName.c_str(), propertyValue);
950
+ }
951
+
952
+ // parse nested arrays like boxShadow
953
+ auto arrValue = objValue.asArray(rt);
954
+ auto parsedArray = jsi::Array(rt, arrValue.length(rt));
955
+
956
+ helpers::iterateJSIArray(rt, arrValue, [&](size_t i, jsi::Value& nestedValue){
957
+ if (nestedValue.isObject()) {
958
+ jsi::Object obj = jsi::Object(rt);
959
+
960
+ helpers::enumerateJSIObject(rt, nestedValue.asObject(rt), [&](const std::string& propertyName, jsi::Value& propertyValue){
961
+ if (this->isColor(propertyName)) {
962
+ obj.setProperty(rt, propertyName.c_str(), state.parseColor(propertyValue));
963
+
964
+ return;
965
+ }
966
+
967
+ obj.setProperty(rt, propertyName.c_str(), propertyValue);
968
+ });
969
+
970
+ parsedArray.setValueAtIndex(rt, i, std::move(obj));
971
+
972
+ return;
973
+ }
974
+
975
+ if (this->isColor(propertyName)) {
976
+ parsedArray.setValueAtIndex(rt, i, jsi::Value(state.parseColor(nestedValue)));
977
+
978
+ return;
979
+ }
980
+
981
+ parsedArray.setValueAtIndex(rt, i, nestedValue);
982
+ });
983
+
984
+ return convertedStyles.setProperty(rt, propertyName.c_str(), parsedArray);
920
985
  });
921
986
  }
922
987
 
@@ -21,7 +21,7 @@ struct ShadowTrafficController {
21
21
  }
22
22
 
23
23
  inline shadow::ShadowLeafUpdates& getUpdates() {
24
- std::lock_guard<std::mutex> lock(_mutex);
24
+ // call it only within withLock!
25
25
 
26
26
  return _unistylesUpdates;
27
27
  }
@@ -45,8 +45,7 @@ struct ShadowTrafficController {
45
45
  }
46
46
 
47
47
  inline void removeShadowNode(const ShadowNodeFamily* shadowNodeFamily) {
48
- std::lock_guard<std::mutex> lock(_mutex);
49
-
48
+ // call it only within withLock!
50
49
  if (_unistylesUpdates.contains(shadowNodeFamily)) {
51
50
  _unistylesUpdates.erase(shadowNodeFamily);
52
51
  }
@@ -58,7 +57,14 @@ struct ShadowTrafficController {
58
57
  _unistylesUpdates = {};
59
58
  _canCommit = false;
60
59
  }
61
-
60
+
61
+ template <typename F>
62
+ inline auto withLock(F&& func) {
63
+ std::lock_guard<std::mutex> lock(_mutex);
64
+
65
+ return std::forward<F>(func)();
66
+ }
67
+
62
68
  private:
63
69
  std::atomic<bool> _canCommit = false;
64
70
  shadow::ShadowLeafUpdates _unistylesUpdates{};
@@ -8,43 +8,46 @@ using AffectedNodes = std::unordered_map<const ShadowNodeFamily*, std::unordered
8
8
 
9
9
  void shadow::ShadowTreeManager::updateShadowTree(const ShadowTreeRegistry& shadowTreeRegistry) {
10
10
  auto& registry = core::UnistylesRegistry::get();
11
- auto updates = registry.trafficController.getUpdates();
12
-
13
- if (updates.empty()) {
14
- return;
15
- }
16
-
17
- shadowTreeRegistry.enumerate([&updates](const ShadowTree& shadowTree, bool& stop){
18
- // we could iterate via updates and create multiple commits
19
- // but it can cause performance issues for hundreds of nodes
20
- // so let's mutate Shadow Tree in single transaction
21
- auto transaction = [&](const RootShadowNode& oldRootShadowNode) {
22
- auto affectedNodes = shadow::ShadowTreeManager::findAffectedNodes(oldRootShadowNode, updates);
23
- auto newRootNode = std::static_pointer_cast<RootShadowNode>(shadow::ShadowTreeManager::cloneShadowTree(
24
- oldRootShadowNode,
25
- updates,
26
- affectedNodes
27
- ));
28
-
29
- // set unistyles trait
30
- auto unistylesRootNode = std::reinterpret_pointer_cast<core::UnistylesCommitShadowNode>(newRootNode);
31
-
32
- unistylesRootNode->addUnistylesCommitTrait();
33
-
34
- return newRootNode;
35
- };
36
-
37
- // commit once!
38
- // CommitOptions:
39
- // enableStateReconciliation: https://reactnative.dev/architecture/render-pipeline#react-native-renderer-state-updates
40
- // mountSynchronously: must be true as this is update from C++ not React
41
- shadowTree.commit(transaction, {false, true});
11
+
12
+ registry.trafficController.withLock([&](){
13
+ auto updates = registry.trafficController.getUpdates();
42
14
 
15
+ if (updates.empty()) {
16
+ return;
17
+ }
43
18
 
44
- // for now we're assuming single surface, can be improved in the future
45
- // stop = true means stop enumerating next shadow tree
46
- // so in other words first shadow tree is our desired tree
47
- stop = true;
19
+ shadowTreeRegistry.enumerate([&updates](const ShadowTree& shadowTree, bool& stop){
20
+ // we could iterate via updates and create multiple commits
21
+ // but it can cause performance issues for hundreds of nodes
22
+ // so let's mutate Shadow Tree in single transaction
23
+ auto transaction = [&](const RootShadowNode& oldRootShadowNode) {
24
+ auto affectedNodes = shadow::ShadowTreeManager::findAffectedNodes(oldRootShadowNode, updates);
25
+ auto newRootNode = std::static_pointer_cast<RootShadowNode>(shadow::ShadowTreeManager::cloneShadowTree(
26
+ oldRootShadowNode,
27
+ updates,
28
+ affectedNodes
29
+ ));
30
+
31
+ // set unistyles trait
32
+ auto unistylesRootNode = std::reinterpret_pointer_cast<core::UnistylesCommitShadowNode>(newRootNode);
33
+
34
+ unistylesRootNode->addUnistylesCommitTrait();
35
+
36
+ return newRootNode;
37
+ };
38
+
39
+ // commit once!
40
+ // CommitOptions:
41
+ // enableStateReconciliation: https://reactnative.dev/architecture/render-pipeline#react-native-renderer-state-updates
42
+ // mountSynchronously: must be true as this is update from C++ not React
43
+ shadowTree.commit(transaction, {false, true});
44
+
45
+
46
+ // for now we're assuming single surface, can be improved in the future
47
+ // stop = true means stop enumerating next shadow tree
48
+ // so in other words first shadow tree is our desired tree
49
+ stop = true;
50
+ });
48
51
  });
49
52
  }
50
53
 
@@ -18,39 +18,35 @@ const UnistylesImageBackground = /*#__PURE__*/(0, _react.forwardRef)((props, for
18
18
  let storedImageRef = null;
19
19
  const styleClassNames = (0, _core.getClassName)(props.style);
20
20
  const imageClassNames = (0, _core.getClassName)(props.imageStyle);
21
- return (
22
- /*#__PURE__*/
23
- // @ts-expect-error - RN types are not compatible with RNW styles
24
- (0, _jsxRuntime.jsx)(_reactNative.ImageBackground, {
25
- ...props,
26
- style: styleClassNames,
27
- imageStyle: imageClassNames,
28
- ref: (0, _utils2.isServer)() ? undefined : ref => {
29
- if (!ref) {
30
- // @ts-expect-error hidden from TS
31
- _web.UnistylesShadowRegistry.remove(storedRef, styleClassNames?.hash);
32
- }
33
- storedRef = ref;
21
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.ImageBackground, {
22
+ ...props,
23
+ style: styleClassNames,
24
+ imageStyle: imageClassNames,
25
+ ref: (0, _utils2.isServer)() ? undefined : ref => {
26
+ if (!ref) {
34
27
  // @ts-expect-error hidden from TS
35
- _web.UnistylesShadowRegistry.add(ref, styleClassNames?.hash);
36
- if (typeof forwardedRef === 'function') {
37
- return forwardedRef(ref);
38
- }
39
- if (forwardedRef) {
40
- forwardedRef.current = ref;
41
- }
42
- },
43
- imageRef: (0, _utils2.isServer)() ? undefined : ref => {
44
- if (!ref) {
45
- // @ts-expect-error hidden from TS
46
- _web.UnistylesShadowRegistry.remove(storedImageRef, imageClassNames?.hash);
47
- }
48
- storedImageRef = ref;
28
+ _web.UnistylesShadowRegistry.remove(storedRef, styleClassNames?.hash);
29
+ }
30
+ storedRef = ref;
31
+ // @ts-expect-error hidden from TS
32
+ _web.UnistylesShadowRegistry.add(ref, styleClassNames?.hash);
33
+ if (typeof forwardedRef === 'function') {
34
+ return forwardedRef(ref);
35
+ }
36
+ if (forwardedRef) {
37
+ forwardedRef.current = ref;
38
+ }
39
+ },
40
+ imageRef: (0, _utils2.isServer)() ? undefined : ref => {
41
+ if (!ref) {
49
42
  // @ts-expect-error hidden from TS
50
- _web.UnistylesShadowRegistry.add(ref, imageClassNames?.hash);
43
+ _web.UnistylesShadowRegistry.remove(storedImageRef, imageClassNames?.hash);
51
44
  }
52
- })
53
- );
45
+ storedImageRef = ref;
46
+ // @ts-expect-error hidden from TS
47
+ _web.UnistylesShadowRegistry.add(ref, imageClassNames?.hash);
48
+ }
49
+ });
54
50
  });
55
51
  const ImageBackground = exports.ImageBackground = (0, _utils.copyComponentProperties)(_reactNative.ImageBackground, UnistylesImageBackground);
56
52
  //# sourceMappingURL=ImageBackground.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_core","_utils","_web","_utils2","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","UnistylesImageBackground","forwardRef","props","forwardedRef","storedRef","storedImageRef","styleClassNames","getClassName","style","imageClassNames","imageStyle","jsx","ImageBackground","ref","isServer","undefined","UnistylesShadowRegistry","remove","hash","add","current","imageRef","exports","copyComponentProperties","NativeImageBackground"],"sourceRoot":"../../../../src","sources":["components/native/ImageBackground.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AAEA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,IAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AAA0C,IAAAM,WAAA,GAAAN,OAAA;AAAA,SAAAO,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAT,wBAAAS,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,CAAA,SAAAG,CAAA,GAAAP,CAAA,GA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O,GAAGP,GAAG;QAC9B;MACJ,CAAE;MACFQ,QAAQ,EAAE,IAAAP,gBAAQ,EAAC,CAAC,GAAGC,SAAS,GAAGF,GAAG,IAAI;QACtC,IAAI,CAACA,GAAG,EAAE;UACN;UACAG,4BAAuB,CAACC,MAAM,CAACZ,cAAc,EAAEI,eAAe,EAAES,IAAI,CAAC;QACzE;QAEAb,cAAc,GAAGQ,GAAG;QACpB;QACAG,4BAAuB,CAACG,GAAG,CAACN,GAAG,EAAEJ,eAAe,EAAES,IAAI,CAAC;MAC3D;IAAE,CACL;EAAC;AAEV,CAAC,CAAC;AAEK,MAAMN,eAAe,GAAAU,OAAA,CAAAV,eAAA,GAAG,IAAAW,8BAAuB,EAACC,4BAAqB,EAAExB,wBAAwB,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_core","_utils","_web","_utils2","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","UnistylesImageBackground","forwardRef","props","forwardedRef","storedRef","storedImageRef","styleClassNames","getClassName","style","imageClassNames","imageStyle","jsx","ImageBackground","ref","isServer","undefined","UnistylesShadowRegistry","remove","hash","add","current","imageRef","exports","copyComponentProperties","NativeImageBackground"],"sourceRoot":"../../../../src","sources":["components/native/ImageBackground.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AAEA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,IAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AAA0C,IAAAM,WAAA,GAAAN,OAAA;AAAA,SAAAO,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAA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