react-native-unistyles 3.0.0-alpha.8 → 3.0.0-alpha.9

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.
@@ -1,6 +1,8 @@
1
1
  #pragma once
2
2
 
3
3
  #include <jsi/jsi.h>
4
+ #include <jsi/JSIDynamic.h>
5
+ #include <folly/dynamic.h>
4
6
  #include <unordered_set>
5
7
 
6
8
  using namespace facebook;
@@ -114,4 +116,60 @@ inline Variants variantsToPairs(jsi::Runtime& rt, jsi::Object&& variants) {
114
116
  return pairs;
115
117
  }
116
118
 
119
+ inline std::vector<folly::dynamic> parseDynamicFunctionArguments(jsi::Runtime& rt, jsi::Array& arguments) {
120
+ std::vector<folly::dynamic> parsedArgument{};
121
+ size_t count = arguments.size(rt);
122
+
123
+ parsedArgument.reserve(count);
124
+
125
+ for (size_t i = 0; i < count; i++) {
126
+ jsi::Value arg = arguments.getValueAtIndex(rt, i);
127
+
128
+ if (arg.isBool()) {
129
+ parsedArgument.push_back(folly::dynamic(arg.asBool()));
130
+
131
+ continue;
132
+ }
133
+
134
+ if (arg.isNumber()) {
135
+ parsedArgument.push_back(folly::dynamic(arg.asNumber()));
136
+
137
+ continue;
138
+ }
139
+
140
+ if (arg.isString()) {
141
+ parsedArgument.push_back(folly::dynamic(arg.asString(rt).utf8(rt)));
142
+
143
+ continue;
144
+ }
145
+
146
+ if (arg.isUndefined()) {
147
+ parsedArgument.push_back(folly::dynamic());
148
+
149
+ continue;
150
+ }
151
+
152
+ if (arg.isNull()) {
153
+ parsedArgument.push_back(folly::dynamic(nullptr));
154
+
155
+ continue;
156
+ }
157
+
158
+ if (!arg.isObject()) {
159
+ continue;;
160
+ }
161
+
162
+ auto argObj = arg.asObject(rt);
163
+
164
+ // allow arrays and objects too
165
+ if (!argObj.isFunction(rt) && !argObj.isArrayBuffer(rt)) {
166
+ parsedArgument.push_back(jsi::dynamicFromValue(rt, arg));
167
+
168
+ continue;
169
+ }
170
+ }
171
+
172
+ return parsedArgument;
173
+ }
174
+
117
175
  }
@@ -14,11 +14,6 @@ enum class UnistyleType {
14
14
  DynamicFunction
15
15
  };
16
16
 
17
- struct DynamicFunctionMetadata {
18
- size_t count;
19
- std::vector<folly::dynamic> arguments;
20
- };
21
-
22
17
  struct Unistyle {
23
18
  using Shared = std::shared_ptr<Unistyle>;
24
19
 
@@ -75,7 +70,6 @@ struct UnistyleDynamicFunction: public Unistyle {
75
70
 
76
71
  std::optional<jsi::Object> unprocessedValue;
77
72
  std::optional<jsi::Function> proxiedFunction = std::nullopt;
78
- std::optional<DynamicFunctionMetadata> dynamicFunctionMetadata = std::nullopt;
79
73
  };
80
74
 
81
75
  }
@@ -8,8 +8,8 @@ namespace margelo::nitro::unistyles::core {
8
8
  using Variants = std::vector<std::pair<std::string, std::string>>;
9
9
 
10
10
  struct UnistyleData {
11
- UnistyleData(Unistyle::Shared unistyle, const Variants& variants)
12
- : unistyle{unistyle}, variants(std::move(variants)) {}
11
+ UnistyleData(Unistyle::Shared unistyle, const Variants& variants, std::vector<folly::dynamic>& arguments)
12
+ : unistyle{unistyle}, variants(std::move(variants)), dynamicFunctionMetadata{std::move(arguments)} {}
13
13
 
14
14
  UnistyleData(const UnistyleData&) = delete;
15
15
  UnistyleData(UnistyleData&& other): unistyle{other.unistyle}, variants(std::move(other.variants)) {}
@@ -17,6 +17,7 @@ struct UnistyleData {
17
17
  core::Unistyle::Shared unistyle;
18
18
  core::Variants variants;
19
19
  std::optional<jsi::Object> parsedStyle = std::nullopt;
20
+ std::optional<std::vector<folly::dynamic>> dynamicFunctionMetadata = std::nullopt;
20
21
  };
21
22
 
22
23
  }
@@ -26,24 +26,24 @@ inline static Unistyle::Shared unistyleFromValue(jsi::Runtime& rt, const jsi::Va
26
26
 
27
27
  inline static jsi::Value valueFromUnistyle(jsi::Runtime& rt, Unistyle::Shared unistyle) {
28
28
  auto wrappedUnistyle = std::make_shared<UnistyleWrapper>(unistyle);
29
-
29
+
30
30
  if (unistyle->type == UnistyleType::Object) {
31
31
  jsi::Object obj = jsi::Object(rt);
32
-
32
+
33
33
  obj.setNativeState(rt, std::move(wrappedUnistyle));
34
34
  helpers::defineHiddenProperty(rt, obj, helpers::UNISTYLES_ID.c_str(), unistyle->styleKey);
35
-
35
+
36
36
  helpers::mergeJSIObjects(rt, obj, unistyle->parsedStyle.value());
37
-
37
+
38
38
  return obj;
39
39
  }
40
-
40
+
41
41
  auto unistyleFn = std::dynamic_pointer_cast<UnistyleDynamicFunction>(unistyle);
42
42
  auto hostFn = jsi::Value(rt, unistyleFn->proxiedFunction.value()).asObject(rt).asFunction(rt);
43
43
 
44
44
  hostFn.setNativeState(rt, std::move(wrappedUnistyle));
45
45
  hostFn.setProperty(rt, helpers::UNISTYLES_ID.c_str(), unistyleFn->styleKey);
46
-
46
+
47
47
  return std::move(hostFn);
48
48
  }
49
49
 
@@ -74,19 +74,20 @@ void core::UnistylesRegistry::updateTheme(jsi::Runtime& rt, std::string& themeNa
74
74
  void core::UnistylesRegistry::linkShadowNodeWithUnistyle(
75
75
  const ShadowNodeFamily* shadowNodeFamily,
76
76
  const core::Unistyle::Shared unistyle,
77
- Variants& variants
77
+ Variants& variants,
78
+ std::vector<folly::dynamic>& arguments
78
79
  ) {
79
80
  if (!this->_shadowRegistry.contains(shadowNodeFamily)) {
80
81
  this->_shadowRegistry[shadowNodeFamily] = {};
81
82
  }
82
83
 
83
- this->_shadowRegistry[shadowNodeFamily].emplace_back(std::make_pair(unistyle, std::move(variants)));
84
+ this->_shadowRegistry[shadowNodeFamily].emplace_back(std::make_shared<UnistyleData>(unistyle, variants, arguments));
84
85
  }
85
86
 
86
87
  void core::UnistylesRegistry::unlinkShadowNodeWithUnistyle(const ShadowNodeFamily* shadowNodeFamily, const core::Unistyle::Shared unistyle) {
87
88
  auto& unistylesVec = this->_shadowRegistry[shadowNodeFamily];
88
- auto it = std::find_if(unistylesVec.begin(), unistylesVec.end(), [unistyle](std::pair<core::Unistyle::Shared, Variants> pair){
89
- return pair.first == unistyle;
89
+ auto it = std::find_if(unistylesVec.begin(), unistylesVec.end(), [unistyle](std::shared_ptr<UnistyleData> unistyleData){
90
+ return unistyleData->unistyle == unistyle;
90
91
  });
91
92
 
92
93
  if (it != unistylesVec.end()) {
@@ -124,12 +125,12 @@ core::DependencyMap core::UnistylesRegistry::buildDependencyMap(jsi::Runtime& rt
124
125
  for (const auto& pair : this->_shadowRegistry) {
125
126
  const auto& [family, unistyles] = pair;
126
127
 
127
- for (const auto& [shadowUnistyle, variants] : unistyles) {
128
- if (unistyle != shadowUnistyle) {
128
+ for (const auto& unistyleData : unistyles) {
129
+ if (unistyle != unistyleData->unistyle) {
129
130
  continue;
130
131
  }
131
132
 
132
- dependencyMap[styleSheet][family].emplace_back(unistyle, variants);
133
+ dependencyMap[styleSheet][family].emplace_back(unistyleData);
133
134
  }
134
135
  }
135
136
  }
@@ -146,12 +147,12 @@ core::DependencyMap core::UnistylesRegistry::buildDependencyMap(jsi::Runtime& rt
146
147
  for (const auto& pair : this->_shadowRegistry) {
147
148
  const auto& [family, unistyles] = pair;
148
149
 
149
- for (const auto& [shadowUnistyle, variants] : unistyles) {
150
- if (unistyle != shadowUnistyle) {
150
+ for (const auto& unistyleData : unistyles) {
151
+ if (unistyle != unistyleData->unistyle) {
151
152
  continue;
152
153
  }
153
154
 
154
- dependencyMap[styleSheet][family].emplace_back(unistyle, variants);
155
+ dependencyMap[styleSheet][family].emplace_back(unistyleData);
155
156
  }
156
157
  }
157
158
  }
@@ -2,6 +2,7 @@
2
2
 
3
3
  #include "set"
4
4
  #include <jsi/jsi.h>
5
+ #include <folly/dynamic.h>
5
6
  #include <react/renderer/uimanager/UIManager.h>
6
7
  #include <unordered_map>
7
8
  #include <unordered_set>
@@ -20,7 +21,7 @@ using namespace facebook::react;
20
21
 
21
22
  using DependencyMap = std::unordered_map<
22
23
  std::shared_ptr<core::StyleSheet>,
23
- std::unordered_map<const ShadowNodeFamily*, std::vector<UnistyleData>>
24
+ std::unordered_map<const ShadowNodeFamily*, std::vector<std::shared_ptr<UnistyleData>>>
24
25
  >;
25
26
 
26
27
  struct UnistylesRegistry: public StyleSheetRegistry {
@@ -37,7 +38,7 @@ struct UnistylesRegistry: public StyleSheetRegistry {
37
38
 
38
39
  UnistylesState& getState(jsi::Runtime& rt);
39
40
  void createState(jsi::Runtime& rt);
40
- void linkShadowNodeWithUnistyle(const ShadowNodeFamily*, const core::Unistyle::Shared, Variants& variants);
41
+ void linkShadowNodeWithUnistyle(const ShadowNodeFamily*, const core::Unistyle::Shared, Variants& variants, std::vector<folly::dynamic>&);
41
42
  void unlinkShadowNodeWithUnistyle(const ShadowNodeFamily*, const core::Unistyle::Shared);
42
43
  std::shared_ptr<core::StyleSheet> addStyleSheet(jsi::Runtime& rt, int tag, core::StyleSheetType type, jsi::Object&& rawValue);
43
44
  DependencyMap buildDependencyMap(jsi::Runtime& rt, std::vector<UnistyleDependency>& deps);
@@ -48,7 +49,7 @@ private:
48
49
 
49
50
  std::unordered_map<jsi::Runtime*, UnistylesState> _states{};
50
51
  std::unordered_map<jsi::Runtime*, std::unordered_map<int, std::shared_ptr<core::StyleSheet>>> _styleSheetRegistry{};
51
- std::unordered_map<const ShadowNodeFamily*, std::vector<std::pair<core::Unistyle::Shared, Variants>>> _shadowRegistry{};
52
+ std::unordered_map<const ShadowNodeFamily*, std::vector<std::shared_ptr<UnistyleData>>> _shadowRegistry{};
52
53
  };
53
54
 
54
55
  UnistylesRegistry& UnistylesRegistry::get() {
@@ -4,15 +4,17 @@ using namespace margelo::nitro::unistyles;
4
4
  using namespace facebook::react;
5
5
 
6
6
  jsi::Value HybridShadowRegistry::link(jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) {
7
- helpers::assertThat(rt, count == 3, "Unistyles: Invalid babel transform 'ShadowRegistry link' expected 3 arguments.");
7
+ helpers::assertThat(rt, count == 4, "Unistyles: Invalid babel transform 'ShadowRegistry link' expected 4 arguments.");
8
8
 
9
9
  ShadowNode::Shared shadowNodeWrapper = shadowNodeFromValue(rt, args[0]);
10
10
  core::Unistyle::Shared unistyleWrapper = core::unistyleFromValue(rt, args[1]);
11
11
  core::Variants variants = helpers::variantsToPairs(rt, args[2].asObject(rt));
12
+ auto rawArguments = args[3].asObject(rt).asArray(rt);
13
+ std::vector<folly::dynamic> arguments = helpers::parseDynamicFunctionArguments(rt, rawArguments);
12
14
 
13
15
  auto& registry = core::UnistylesRegistry::get();
14
16
 
15
- registry.linkShadowNodeWithUnistyle(&shadowNodeWrapper->getFamily(), unistyleWrapper, variants);
17
+ registry.linkShadowNodeWithUnistyle(&shadowNodeWrapper->getFamily(), unistyleWrapper, variants, arguments);
16
18
 
17
19
  return jsi::Value::undefined();
18
20
  }
@@ -91,7 +91,8 @@ void parser::Parser::rebuildUnistylesWithVariants(jsi::Runtime& rt, std::shared_
91
91
  continue;
92
92
  }
93
93
 
94
- this->rebuildUnistyle(rt, styleSheet, unistyle, variants);
94
+ // todo skip dynamic functions
95
+ this->rebuildUnistyle(rt, styleSheet, unistyle, variants, std::nullopt);
95
96
  }
96
97
  }
97
98
 
@@ -101,22 +102,24 @@ void parser::Parser::rebuildUnistylesInDependencyMap(jsi::Runtime& rt, Dependenc
101
102
  jsi::Object unwrappedStyleSheet = this->unwrapStyleSheet(rt, styleSheet);
102
103
 
103
104
  for (auto& [shadowNode, unistyles] : map) {
104
- for (auto& [unistyle, variants, parsedStyle] : unistyles) {
105
+ for (auto& unistyleData : unistyles) {
106
+ auto& unistyle = unistyleData->unistyle;
107
+
105
108
  // StyleSheet might have styles that are not affected
106
109
  if (!unwrappedStyleSheet.hasProperty(rt, unistyle->styleKey.c_str())) {
107
110
  continue;
108
111
  }
109
112
 
110
113
  unistyle->rawValue = unwrappedStyleSheet.getProperty(rt, unistyle->styleKey.c_str()).asObject(rt);
111
- this->rebuildUnistyle(rt, styleSheet, unistyle, variants);
112
- parsedStyle = jsi::Value(rt, unistyle->parsedStyle.value()).asObject(rt);
114
+ this->rebuildUnistyle(rt, styleSheet, unistyle, unistyleData->variants, unistyleData->dynamicFunctionMetadata);
115
+ unistyleData->parsedStyle = jsi::Value(rt, unistyle->parsedStyle.value()).asObject(rt);
113
116
  }
114
117
  }
115
118
  }
116
119
  }
117
120
 
118
121
  // rebuild single unistyle
119
- void parser::Parser::rebuildUnistyle(jsi::Runtime& rt, std::shared_ptr<StyleSheet> styleSheet, Unistyle::Shared unistyle, const Variants& variants) {
122
+ void parser::Parser::rebuildUnistyle(jsi::Runtime& rt, std::shared_ptr<StyleSheet> styleSheet, Unistyle::Shared unistyle, const Variants& variants, std::optional<std::vector<folly::dynamic>> metadata) {
120
123
  if (unistyle->type == core::UnistyleType::Object) {
121
124
  auto result = this->parseFirstLevel(rt, unistyle, variants);
122
125
 
@@ -125,20 +128,17 @@ void parser::Parser::rebuildUnistyle(jsi::Runtime& rt, std::shared_ptr<StyleShee
125
128
 
126
129
  // for functions we need to call memoized function
127
130
  // with last know arguments and parse it with new theme and mini runtime
128
- if (unistyle->type == core::UnistyleType::DynamicFunction) {
131
+ if (unistyle->type == core::UnistyleType::DynamicFunction && metadata.has_value()) {
129
132
  auto unistyleFn = std::dynamic_pointer_cast<UnistyleDynamicFunction>(unistyle);
130
- auto maybeMetadata = unistyleFn->dynamicFunctionMetadata;
131
-
132
- helpers::assertThat(rt, maybeMetadata.has_value(), "Unistyles: Your dynamic function '" + unistyleFn->styleKey + "' has no metadata and can't be processed.");
133
133
 
134
134
  // convert arguments to jsi::Value
135
- auto metadata = unistyleFn->dynamicFunctionMetadata.value();
135
+ auto dynamicFunctionMetadata = metadata.value();
136
136
  std::vector<jsi::Value> args{};
137
137
 
138
- args.reserve(3);
138
+ args.reserve(dynamicFunctionMetadata.size());
139
139
 
140
- for (int i = 0; i < metadata.count; i++) {
141
- folly::dynamic& arg = metadata.arguments.at(i);
140
+ for (int i = 0; i < dynamicFunctionMetadata.size(); i++) {
141
+ folly::dynamic& arg = dynamicFunctionMetadata.at(i);
142
142
 
143
143
  args.emplace_back(jsi::valueFromDynamic(rt, arg));
144
144
  }
@@ -146,7 +146,7 @@ void parser::Parser::rebuildUnistyle(jsi::Runtime& rt, std::shared_ptr<StyleShee
146
146
  const jsi::Value *argStart = args.data();
147
147
 
148
148
  // call cached function with memoized arguments
149
- auto functionResult = unistyleFn->proxiedFunction.value().callAsConstructor(rt, argStart, metadata.count).asObject(rt);
149
+ auto functionResult = unistyleFn->proxiedFunction.value().callAsConstructor(rt, argStart, dynamicFunctionMetadata.size()).asObject(rt);
150
150
 
151
151
  unistyleFn->unprocessedValue = std::move(functionResult);
152
152
  unistyleFn->parsedStyle = this->parseFirstLevel(rt, unistyleFn, variants);
@@ -160,9 +160,9 @@ shadow::ShadowLeafUpdates parser::Parser::dependencyMapToShadowLeafUpdates(core:
160
160
 
161
161
  for (const auto& [styleSheet, map] : dependencyMap) {
162
162
  for (const auto& [shadowNode, unistyles] : map) {
163
- for (const auto& [unistyle, variants, parsedStyle] : unistyles) {
164
- auto rawProps = this->parseStylesToShadowTreeStyles(rt, parsedStyle.value());
165
-
163
+ for (const auto& unistyleData : unistyles) {
164
+ auto rawProps = this->parseStylesToShadowTreeStyles(rt, unistyleData->parsedStyle.value());
165
+
166
166
  if (updates.contains(shadowNode)) {
167
167
  updates[shadowNode].emplace_back(std::move(rawProps));
168
168
 
@@ -177,62 +177,6 @@ shadow::ShadowLeafUpdates parser::Parser::dependencyMapToShadowLeafUpdates(core:
177
177
  return updates;
178
178
  }
179
179
 
180
- // convert jsi::Value arguments to folly::dynamic
181
- std::vector<folly::dynamic> parser::Parser::parseDynamicFunctionArguments(jsi::Runtime& rt, size_t count, const jsi::Value* arguments) {
182
- std::vector<folly::dynamic> parsedArgument{};
183
-
184
- parsedArgument.reserve(3);
185
-
186
- for (size_t i = 0; i < count; i++) {
187
- auto& arg = arguments[i];
188
-
189
- if (arg.isBool()) {
190
- parsedArgument.push_back(folly::dynamic(arg.asBool()));
191
-
192
- continue;
193
- }
194
-
195
- if (arg.isNumber()) {
196
- parsedArgument.push_back(folly::dynamic(arg.asNumber()));
197
-
198
- continue;
199
- }
200
-
201
- if (arg.isString()) {
202
- parsedArgument.push_back(folly::dynamic(arg.asString(rt).utf8(rt)));
203
-
204
- continue;
205
- }
206
-
207
- if (arg.isUndefined()) {
208
- parsedArgument.push_back(folly::dynamic());
209
-
210
- continue;
211
- }
212
-
213
- if (arg.isNull()) {
214
- parsedArgument.push_back(folly::dynamic(nullptr));
215
-
216
- continue;
217
- }
218
-
219
- if (!arg.isObject()) {
220
- continue;;
221
- }
222
-
223
- auto argObj = arg.asObject(rt);
224
-
225
- // allow arrays and objects too
226
- if (!argObj.isFunction(rt) && !argObj.isArrayBuffer(rt)) {
227
- parsedArgument.push_back(jsi::dynamicFromValue(rt, arg));
228
-
229
- continue;
230
- }
231
- }
232
-
233
- return parsedArgument;
234
- }
235
-
236
180
  // first level of StyleSheet, we can expect here different properties than on second level
237
181
  // eg. variants, compoundVariants, mq, breakpoints etc.
238
182
  jsi::Object parser::Parser::parseFirstLevel(jsi::Runtime& rt, Unistyle::Shared unistyle, std::optional<Variants> variants) {
@@ -352,13 +296,15 @@ jsi::Function parser::Parser::createDynamicFunctionProxy(jsi::Runtime& rt, Unist
352
296
 
353
297
  // memoize metadata to call it later
354
298
  auto unistyleFn = std::dynamic_pointer_cast<UnistyleDynamicFunction>(unistyle);
299
+ jsi::Array arguments = jsi::Array(rt, count);
355
300
 
356
- unistyleFn->dynamicFunctionMetadata = core::DynamicFunctionMetadata{
357
- count,
358
- this->parseDynamicFunctionArguments(rt, count, args)
359
- };
301
+ for (size_t i = 0; i < count; i++) {
302
+ arguments.setValueAtIndex(rt, i, args[i]);
303
+ }
360
304
 
361
305
  unistyleFn->unprocessedValue = jsi::Value(rt, result).asObject(rt);
306
+
307
+ // todo pass here variants
362
308
  unistyleFn->parsedStyle = this->parseFirstLevel(rt, unistyleFn, std::nullopt);
363
309
  unistyleFn->seal();
364
310
 
@@ -532,7 +478,7 @@ jsi::Value parser::Parser::getStylesForVariant(jsi::Runtime& rt, const std::stri
532
478
  ? selectedVariant.value().c_str()
533
479
  : "default";
534
480
  auto hasKey = groupValue.hasProperty(rt, selectedVariantKey);
535
-
481
+
536
482
  if (hasKey && !selectedVariant.has_value()) {
537
483
  // add 'default' selection to variants map
538
484
  variants.emplace_back(groupName, selectedVariantKey);
@@ -28,12 +28,11 @@ struct Parser {
28
28
  shadow::ShadowLeafUpdates dependencyMapToShadowLeafUpdates(core::DependencyMap& dependencyMap);
29
29
 
30
30
  private:
31
- void rebuildUnistyle(jsi::Runtime& rt, std::shared_ptr<StyleSheet> styleSheet, Unistyle::Shared unistyle, const Variants& variants);
31
+ void rebuildUnistyle(jsi::Runtime& rt, std::shared_ptr<StyleSheet> styleSheet, Unistyle::Shared unistyle, const Variants& variants, std::optional<std::vector<folly::dynamic>>);
32
32
  jsi::Object unwrapStyleSheet(jsi::Runtime& rt, std::shared_ptr<StyleSheet> styleSheet);
33
33
  jsi::Object parseFirstLevel(jsi::Runtime& rt, Unistyle::Shared unistyle, std::optional<Variants> variants);
34
34
  jsi::Value parseSecondLevel(jsi::Runtime& rt, Unistyle::Shared unistyle, jsi::Value& nestedObject);
35
35
  jsi::Function createDynamicFunctionProxy(jsi::Runtime& rt, Unistyle::Shared unistyle);
36
- std::vector<folly::dynamic> parseDynamicFunctionArguments(jsi::Runtime& rt, size_t count, const jsi::Value* arguments);
37
36
  std::vector<UnistyleDependency> parseDependencies(jsi::Runtime &rt, jsi::Object&& dependencies);
38
37
  jsi::Value parseTransforms(jsi::Runtime& rt, Unistyle::Shared unistyle, jsi::Object& obj);
39
38
  jsi::Value getValueFromBreakpoints(jsi::Runtime& rt, Unistyle::Shared unistyle, jsi::Object& obj);
@@ -14,11 +14,11 @@ const findShadowNodeForHandle = handle => {
14
14
  }
15
15
  return node;
16
16
  };
17
- HybridShadowRegistry.add = (handle, style, variants) => {
17
+ HybridShadowRegistry.add = (handle, style, variants, args) => {
18
18
  if (!handle || !style?.__unid) {
19
19
  return;
20
20
  }
21
- HybridShadowRegistry.link(findShadowNodeForHandle(handle), style, variants ?? {});
21
+ HybridShadowRegistry.link(findShadowNodeForHandle(handle), style, variants ?? {}, args ?? []);
22
22
  };
23
23
  HybridShadowRegistry.remove = (handle, style) => {
24
24
  if (!handle || !style?.__unid) {
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNativeNitroModules","require","HybridShadowRegistry","NitroModules","createHybridObject","findShadowNodeForHandle","handle","node","__internalInstanceHandle","stateNode","getScrollResponder","getNativeScrollRef","Error","add","style","variants","__unid","link","remove","unlink","UnistylesShadowRegistry","exports"],"sourceRoot":"../../../../src","sources":["specs/ShadowRegistry/index.ts"],"mappings":";;;;;;AAAA,IAAAA,wBAAA,GAAAC,OAAA;AAaA,MAAMC,oBAAoB,GAAGC,qCAAY,CAACC,kBAAkB,CAAiB,yBAAyB,CAAC;AAEvG,MAAMC,uBAAuB,GAAIC,MAAkB,IAAK;EACpD,MAAMC,IAAI,GAAGD,MAAM,EAAEE,wBAAwB,EAAEC,SAAS,EAAEF,IAAI,IACvDD,MAAM,EAAEI,kBAAkB,GAAG,CAAC,EAAEC,kBAAkB,GAAG,CAAC,EAAEH,wBAAwB,EAAEC,SAAS,EAAEF,IAAI,IACjGD,MAAM,EAAEK,kBAAkB,GAAG,CAAC,EAAEH,wBAAwB,EAAEC,SAAS,EAAEF,IAAI;EAEhF,IAAI,CAACA,IAAI,EAAE;IACP;IACA,MAAM,IAAIK,KAAK,CAAC,uDAAuD,CAAC;EAC5E;EAEA,OAAOL,IAAI;AACf,CAAC;AAEDL,oBAAoB,CAACW,GAAG,GAAG,CAACP,MAAM,EAAEQ,KAAK,EAAEC,QAAQ,KAAK;EACpD,IAAI,CAACT,MAAM,IAAI,CAACQ,KAAK,EAAEE,MAAM,EAAE;IAC3B;EACJ;EAEAd,oBAAoB,CAACe,IAAI,CAACZ,uBAAuB,CAACC,MAAM,CAAC,EAAEQ,KAAK,EAAEC,QAAQ,IAAI,CAAC,CAAC,CAAC;AACrF,CAAC;AAEDb,oBAAoB,CAACgB,MAAM,GAAG,CAACZ,MAAM,EAAEQ,KAAK,KAAK;EAC7C,IAAI,CAACR,MAAM,IAAI,CAACQ,KAAK,EAAEE,MAAM,EAAE;IAC3B;EACJ;EAEAd,oBAAoB,CAACiB,MAAM,CAACd,uBAAuB,CAACC,MAAM,CAAC,EAAEQ,KAAK,CAAC;AACvE,CAAC;AAQM,MAAMM,uBAAuB,GAAAC,OAAA,CAAAD,uBAAA,GAAGlB,oBAA4D","ignoreList":[]}
1
+ {"version":3,"names":["_reactNativeNitroModules","require","HybridShadowRegistry","NitroModules","createHybridObject","findShadowNodeForHandle","handle","node","__internalInstanceHandle","stateNode","getScrollResponder","getNativeScrollRef","Error","add","style","variants","args","__unid","link","remove","unlink","UnistylesShadowRegistry","exports"],"sourceRoot":"../../../../src","sources":["specs/ShadowRegistry/index.ts"],"mappings":";;;;;;AAAA,IAAAA,wBAAA,GAAAC,OAAA;AAaA,MAAMC,oBAAoB,GAAGC,qCAAY,CAACC,kBAAkB,CAAiB,yBAAyB,CAAC;AAEvG,MAAMC,uBAAuB,GAAIC,MAAkB,IAAK;EACpD,MAAMC,IAAI,GAAGD,MAAM,EAAEE,wBAAwB,EAAEC,SAAS,EAAEF,IAAI,IACvDD,MAAM,EAAEI,kBAAkB,GAAG,CAAC,EAAEC,kBAAkB,GAAG,CAAC,EAAEH,wBAAwB,EAAEC,SAAS,EAAEF,IAAI,IACjGD,MAAM,EAAEK,kBAAkB,GAAG,CAAC,EAAEH,wBAAwB,EAAEC,SAAS,EAAEF,IAAI;EAEhF,IAAI,CAACA,IAAI,EAAE;IACP;IACA,MAAM,IAAIK,KAAK,CAAC,uDAAuD,CAAC;EAC5E;EAEA,OAAOL,IAAI;AACf,CAAC;AAEDL,oBAAoB,CAACW,GAAG,GAAG,CAACP,MAAM,EAAEQ,KAAK,EAAEC,QAAQ,EAAEC,IAAI,KAAK;EAC1D,IAAI,CAACV,MAAM,IAAI,CAACQ,KAAK,EAAEG,MAAM,EAAE;IAC3B;EACJ;EAEAf,oBAAoB,CAACgB,IAAI,CAACb,uBAAuB,CAACC,MAAM,CAAC,EAAEQ,KAAK,EAAEC,QAAQ,IAAI,CAAC,CAAC,EAAEC,IAAI,IAAI,EAAE,CAAC;AACjG,CAAC;AAEDd,oBAAoB,CAACiB,MAAM,GAAG,CAACb,MAAM,EAAEQ,KAAK,KAAK;EAC7C,IAAI,CAACR,MAAM,IAAI,CAACQ,KAAK,EAAEG,MAAM,EAAE;IAC3B;EACJ;EAEAf,oBAAoB,CAACkB,MAAM,CAACf,uBAAuB,CAACC,MAAM,CAAC,EAAEQ,KAAK,CAAC;AACvE,CAAC;AAQM,MAAMO,uBAAuB,GAAAC,OAAA,CAAAD,uBAAA,GAAGnB,oBAA4D","ignoreList":[]}
@@ -10,11 +10,11 @@ const findShadowNodeForHandle = handle => {
10
10
  }
11
11
  return node;
12
12
  };
13
- HybridShadowRegistry.add = (handle, style, variants) => {
13
+ HybridShadowRegistry.add = (handle, style, variants, args) => {
14
14
  if (!handle || !style?.__unid) {
15
15
  return;
16
16
  }
17
- HybridShadowRegistry.link(findShadowNodeForHandle(handle), style, variants ?? {});
17
+ HybridShadowRegistry.link(findShadowNodeForHandle(handle), style, variants ?? {}, args ?? []);
18
18
  };
19
19
  HybridShadowRegistry.remove = (handle, style) => {
20
20
  if (!handle || !style?.__unid) {
@@ -1 +1 @@
1
- {"version":3,"names":["NitroModules","HybridShadowRegistry","createHybridObject","findShadowNodeForHandle","handle","node","__internalInstanceHandle","stateNode","getScrollResponder","getNativeScrollRef","Error","add","style","variants","__unid","link","remove","unlink","UnistylesShadowRegistry"],"sourceRoot":"../../../../src","sources":["specs/ShadowRegistry/index.ts"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;AAazD,MAAMC,oBAAoB,GAAGD,YAAY,CAACE,kBAAkB,CAAiB,yBAAyB,CAAC;AAEvG,MAAMC,uBAAuB,GAAIC,MAAkB,IAAK;EACpD,MAAMC,IAAI,GAAGD,MAAM,EAAEE,wBAAwB,EAAEC,SAAS,EAAEF,IAAI,IACvDD,MAAM,EAAEI,kBAAkB,GAAG,CAAC,EAAEC,kBAAkB,GAAG,CAAC,EAAEH,wBAAwB,EAAEC,SAAS,EAAEF,IAAI,IACjGD,MAAM,EAAEK,kBAAkB,GAAG,CAAC,EAAEH,wBAAwB,EAAEC,SAAS,EAAEF,IAAI;EAEhF,IAAI,CAACA,IAAI,EAAE;IACP;IACA,MAAM,IAAIK,KAAK,CAAC,uDAAuD,CAAC;EAC5E;EAEA,OAAOL,IAAI;AACf,CAAC;AAEDJ,oBAAoB,CAACU,GAAG,GAAG,CAACP,MAAM,EAAEQ,KAAK,EAAEC,QAAQ,KAAK;EACpD,IAAI,CAACT,MAAM,IAAI,CAACQ,KAAK,EAAEE,MAAM,EAAE;IAC3B;EACJ;EAEAb,oBAAoB,CAACc,IAAI,CAACZ,uBAAuB,CAACC,MAAM,CAAC,EAAEQ,KAAK,EAAEC,QAAQ,IAAI,CAAC,CAAC,CAAC;AACrF,CAAC;AAEDZ,oBAAoB,CAACe,MAAM,GAAG,CAACZ,MAAM,EAAEQ,KAAK,KAAK;EAC7C,IAAI,CAACR,MAAM,IAAI,CAACQ,KAAK,EAAEE,MAAM,EAAE;IAC3B;EACJ;EAEAb,oBAAoB,CAACgB,MAAM,CAACd,uBAAuB,CAACC,MAAM,CAAC,EAAEQ,KAAK,CAAC;AACvE,CAAC;AAQD,OAAO,MAAMM,uBAAuB,GAAGjB,oBAA4D","ignoreList":[]}
1
+ {"version":3,"names":["NitroModules","HybridShadowRegistry","createHybridObject","findShadowNodeForHandle","handle","node","__internalInstanceHandle","stateNode","getScrollResponder","getNativeScrollRef","Error","add","style","variants","args","__unid","link","remove","unlink","UnistylesShadowRegistry"],"sourceRoot":"../../../../src","sources":["specs/ShadowRegistry/index.ts"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;AAazD,MAAMC,oBAAoB,GAAGD,YAAY,CAACE,kBAAkB,CAAiB,yBAAyB,CAAC;AAEvG,MAAMC,uBAAuB,GAAIC,MAAkB,IAAK;EACpD,MAAMC,IAAI,GAAGD,MAAM,EAAEE,wBAAwB,EAAEC,SAAS,EAAEF,IAAI,IACvDD,MAAM,EAAEI,kBAAkB,GAAG,CAAC,EAAEC,kBAAkB,GAAG,CAAC,EAAEH,wBAAwB,EAAEC,SAAS,EAAEF,IAAI,IACjGD,MAAM,EAAEK,kBAAkB,GAAG,CAAC,EAAEH,wBAAwB,EAAEC,SAAS,EAAEF,IAAI;EAEhF,IAAI,CAACA,IAAI,EAAE;IACP;IACA,MAAM,IAAIK,KAAK,CAAC,uDAAuD,CAAC;EAC5E;EAEA,OAAOL,IAAI;AACf,CAAC;AAEDJ,oBAAoB,CAACU,GAAG,GAAG,CAACP,MAAM,EAAEQ,KAAK,EAAEC,QAAQ,EAAEC,IAAI,KAAK;EAC1D,IAAI,CAACV,MAAM,IAAI,CAACQ,KAAK,EAAEG,MAAM,EAAE;IAC3B;EACJ;EAEAd,oBAAoB,CAACe,IAAI,CAACb,uBAAuB,CAACC,MAAM,CAAC,EAAEQ,KAAK,EAAEC,QAAQ,IAAI,CAAC,CAAC,EAAEC,IAAI,IAAI,EAAE,CAAC;AACjG,CAAC;AAEDb,oBAAoB,CAACgB,MAAM,GAAG,CAACb,MAAM,EAAEQ,KAAK,KAAK;EAC7C,IAAI,CAACR,MAAM,IAAI,CAACQ,KAAK,EAAEG,MAAM,EAAE;IAC3B;EACJ;EAEAd,oBAAoB,CAACiB,MAAM,CAACf,uBAAuB,CAACC,MAAM,CAAC,EAAEQ,KAAK,CAAC;AACvE,CAAC;AAQD,OAAO,MAAMO,uBAAuB,GAAGlB,oBAA4D","ignoreList":[]}
@@ -1,9 +1,9 @@
1
1
  import type { UnistylesShadowRegistry as UnistylesShadowRegistrySpec } from './ShadowRegistry.nitro';
2
2
  import type { ShadowNode, Unistyle, ViewHandle } from './types';
3
3
  interface ShadowRegistry extends UnistylesShadowRegistrySpec {
4
- add(handle?: ViewHandle, style?: Unistyle, variants?: Record<string, string | boolean>): void;
4
+ add(handle?: ViewHandle, style?: Unistyle, variants?: Record<string, string | boolean>, args?: Array<any>): void;
5
5
  remove(handle?: ViewHandle, style?: Unistyle): void;
6
- link(node: ShadowNode, style: Unistyle, variants?: Record<string, string | boolean>): void;
6
+ link(node: ShadowNode, style: Unistyle, variants?: Record<string, string | boolean>, args?: Array<any>): void;
7
7
  unlink(node: ShadowNode, style: Unistyle): void;
8
8
  }
9
9
  type PrivateMethods = 'add' | 'remove' | 'link' | 'unlink';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/specs/ShadowRegistry/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,IAAI,2BAA2B,EAAE,MAAM,wBAAwB,CAAA;AACpG,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAE/D,UAAU,cAAe,SAAQ,2BAA2B;IAExD,GAAG,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,IAAI,CAAC;IAC9F,MAAM,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;IAEpD,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,IAAI,CAAC;IAC3F,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAA;CAClD;AAiCD,KAAK,cAAc,GACb,KAAK,GACL,QAAQ,GACR,MAAM,GACN,QAAQ,CAAA;AAEd,eAAO,MAAM,uBAAuB,EAA2B,IAAI,CAAC,cAAc,EAAE,cAAc,CAAC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/specs/ShadowRegistry/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,IAAI,2BAA2B,EAAE,MAAM,wBAAwB,CAAA;AACpG,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAE/D,UAAU,cAAe,SAAQ,2BAA2B;IAExD,GAAG,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IACjH,MAAM,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;IAEpD,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IAC9G,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAA;CAClD;AAiCD,KAAK,cAAc,GACb,KAAK,GACL,QAAQ,GACR,MAAM,GACN,QAAQ,CAAA;AAEd,eAAO,MAAM,uBAAuB,EAA2B,IAAI,CAAC,cAAc,EAAE,cAAc,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "3.0.0-alpha.8",
3
+ "version": "3.0.0-alpha.9",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -51,7 +51,7 @@ pluginTester({
51
51
  <View
52
52
  style={styles.container}
53
53
  ref={ref => {
54
- UnistylesShadowRegistry.add(ref, styles.container, undefined)
54
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
55
55
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
56
56
  }}
57
57
  >
@@ -112,7 +112,7 @@ pluginTester({
112
112
  <View
113
113
  style={styles.container}
114
114
  ref={ref => {
115
- UnistylesShadowRegistry.add(ref, styles.container, undefined)
115
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
116
116
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
117
117
  }}
118
118
  >
@@ -167,7 +167,7 @@ pluginTester({
167
167
  <View
168
168
  style={styles.container}
169
169
  ref={ref => {
170
- UnistylesShadowRegistry.add(ref, styles.container, undefined)
170
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
171
171
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
172
172
  }}
173
173
  >
@@ -280,7 +280,7 @@ pluginTester({
280
280
  <View
281
281
  style={styles.container}
282
282
  ref={ref => {
283
- UnistylesShadowRegistry.add(ref, styles.container, undefined)
283
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
284
284
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
285
285
  }}
286
286
  >
@@ -405,7 +405,7 @@ pluginTester({
405
405
  <View
406
406
  style={styles.container}
407
407
  ref={ref => {
408
- UnistylesShadowRegistry.add(ref, styles.container, undefined)
408
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
409
409
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
410
410
  }}
411
411
  >
@@ -78,7 +78,7 @@ pluginTester({
78
78
  <View
79
79
  style={styles.container}
80
80
  ref={ref => {
81
- UnistylesShadowRegistry.add(ref, styles.container, undefined)
81
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
82
82
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
83
83
  }}
84
84
  >
@@ -131,7 +131,7 @@ pluginTester({
131
131
  <View
132
132
  ref={_ref => {
133
133
  ref.current = _ref
134
- UnistylesShadowRegistry.add(_ref, styles.container, undefined)
134
+ UnistylesShadowRegistry.add(_ref, styles.container, undefined, undefined)
135
135
  return () => UnistylesShadowRegistry.remove(_ref, styles.container)
136
136
  }}
137
137
  style={styles.container}
@@ -192,7 +192,7 @@ pluginTester({
192
192
  ref={ref => {
193
193
  doSomething(ref)
194
194
  myRef.current = ref
195
- UnistylesShadowRegistry.add(ref, styles.container, undefined)
195
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
196
196
  return () => {
197
197
  UnistylesShadowRegistry.remove(ref, styles.container)
198
198
  }
@@ -259,7 +259,7 @@ pluginTester({
259
259
  ref={ref => {
260
260
  doSomething(ref)
261
261
  myRef.current = ref
262
- UnistylesShadowRegistry.add(ref, styles.container, undefined)
262
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
263
263
  return () => {
264
264
  ;(() => {
265
265
  customCleanup()
@@ -333,7 +333,7 @@ pluginTester({
333
333
  <View
334
334
  ref={_ref => {
335
335
  fn(_ref)
336
- UnistylesShadowRegistry.add(_ref, styles.container, undefined)
336
+ UnistylesShadowRegistry.add(_ref, styles.container, undefined, undefined)
337
337
  return () => {
338
338
  ;(() => {
339
339
  customCleanup2()
@@ -407,7 +407,7 @@ pluginTester({
407
407
  <View
408
408
  ref={_ref => {
409
409
  fn(_ref)
410
- UnistylesShadowRegistry.add(_ref, styles.container, undefined)
410
+ UnistylesShadowRegistry.add(_ref, styles.container, undefined, undefined)
411
411
  return () => {
412
412
  ;(() => {
413
413
  customCleanup2()
@@ -637,7 +637,7 @@ pluginTester({
637
637
  <View
638
638
  ref={_ref => {
639
639
  myRef.current = _ref
640
- UnistylesShadowRegistry.add(_ref, styles.container, undefined)
640
+ UnistylesShadowRegistry.add(_ref, styles.container, undefined, undefined)
641
641
  return () => UnistylesShadowRegistry.remove(_ref, styles.container)
642
642
  }}
643
643
  style={{
@@ -704,7 +704,7 @@ pluginTester({
704
704
  <View
705
705
  ref={_ref => {
706
706
  myRef.current = _ref
707
- UnistylesShadowRegistry.add(_ref, styles.container, undefined)
707
+ UnistylesShadowRegistry.add(_ref, styles.container, undefined, undefined)
708
708
  return () => UnistylesShadowRegistry.remove(_ref, styles.container)
709
709
  }}
710
710
  style={[
@@ -766,7 +766,7 @@ pluginTester({
766
766
  <View
767
767
  ref={_ref => {
768
768
  myRef.current = _ref
769
- UnistylesShadowRegistry.add(_ref, styles.container, undefined)
769
+ UnistylesShadowRegistry.add(_ref, styles.container, undefined, undefined)
770
770
  return () => UnistylesShadowRegistry.remove(_ref, styles.container)
771
771
  }}
772
772
  style={[styles.container]}
@@ -825,9 +825,7 @@ pluginTester({
825
825
  <View
826
826
  ref={_ref => {
827
827
  myRef.current = _ref
828
-
829
- styles.container(1, 2, _ref)
830
- UnistylesShadowRegistry.add(_ref, styles.container, undefined)
828
+ UnistylesShadowRegistry.add(_ref, styles.container, undefined, [1, 2])
831
829
  return () => UnistylesShadowRegistry.remove(_ref, styles.container)
832
830
  }}
833
831
  style={[styles.container(1, 2)]}
@@ -887,9 +885,7 @@ pluginTester({
887
885
  <View
888
886
  ref={_ref => {
889
887
  myRef.current = _ref
890
-
891
- styles.container(1, 2, _ref)
892
- UnistylesShadowRegistry.add(_ref, styles.container, undefined)
888
+ UnistylesShadowRegistry.add(_ref, styles.container, undefined, [1, 2])
893
889
  return () => UnistylesShadowRegistry.remove(_ref, styles.container)
894
890
  }}
895
891
  style={{ backgroundColor: 'red', ...styles.container(1, 2) }}
@@ -964,8 +960,7 @@ pluginTester({
964
960
  <View
965
961
  ref={_ref => {
966
962
  myRef.current = _ref
967
- uhh.dkk(_ref)
968
- UnistylesShadowRegistry.add(_ref, uhh.dkk, __uni__variants)
963
+ UnistylesShadowRegistry.add(_ref, uhh.dkk, __uni__variants, [])
969
964
  return () => UnistylesShadowRegistry.remove(_ref, uhh.dkk)
970
965
  }}
971
966
  style={uhh.dkk()}
@@ -1033,8 +1028,7 @@ pluginTester({
1033
1028
  <View
1034
1029
  ref={_ref => {
1035
1030
  myRef.current = _ref
1036
- uhh.dkk(_ref)
1037
- UnistylesShadowRegistry.add(_ref, uhh.dkk, undefined)
1031
+ UnistylesShadowRegistry.add(_ref, uhh.dkk, undefined, [])
1038
1032
  return () => UnistylesShadowRegistry.remove(_ref, uhh.dkk)
1039
1033
  }}
1040
1034
  style={uhh.dkk()}
@@ -1086,24 +1080,21 @@ pluginTester({
1086
1080
  <View
1087
1081
  style={styles.container(1, 5)}
1088
1082
  ref={ref => {
1089
- styles.container(1, 5, ref)
1090
- UnistylesShadowRegistry.add(ref, styles.container, undefined)
1083
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, [1, 5])
1091
1084
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
1092
1085
  }}
1093
1086
  />
1094
1087
  <View
1095
1088
  style={styles.container(2, 6)}
1096
1089
  ref={ref => {
1097
- styles.container(2, 6, ref)
1098
- UnistylesShadowRegistry.add(ref, styles.container, undefined)
1090
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, [2, 6])
1099
1091
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
1100
1092
  }}
1101
1093
  />
1102
1094
  <View
1103
1095
  style={styles.container(5, 1)}
1104
1096
  ref={ref => {
1105
- styles.container(5, 1, ref)
1106
- UnistylesShadowRegistry.add(ref, styles.container, undefined)
1097
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, [5, 1])
1107
1098
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
1108
1099
  }}
1109
1100
  />
@@ -1152,10 +1143,8 @@ pluginTester({
1152
1143
  <View
1153
1144
  style={[styles.container(1, 5), styles.container2(1, 6)]}
1154
1145
  ref={ref => {
1155
- styles.container(1, 5, ref)
1156
- UnistylesShadowRegistry.add(ref, styles.container, undefined)
1157
- styles.container2(1, 6, ref)
1158
- UnistylesShadowRegistry.add(ref, styles.container2, undefined)
1146
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, [1, 5])
1147
+ UnistylesShadowRegistry.add(ref, styles.container2, undefined, [1, 6])
1159
1148
  return () => {
1160
1149
  ;(() => UnistylesShadowRegistry.remove(ref, styles.container))()
1161
1150
  UnistylesShadowRegistry.remove(ref, styles.container2)
@@ -41,7 +41,7 @@ pluginTester({
41
41
  <View
42
42
  style={styles.container}
43
43
  ref={ref => {
44
- UnistylesShadowRegistry.add(ref, styles.container, undefined)
44
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
45
45
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
46
46
  }}
47
47
  >
@@ -88,7 +88,7 @@ pluginTester({
88
88
  <View
89
89
  style={styles.container}
90
90
  ref={ref => {
91
- UnistylesShadowRegistry.add(ref, styles.container, undefined)
91
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
92
92
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
93
93
  }}
94
94
  >
@@ -136,7 +136,7 @@ pluginTester({
136
136
  <View
137
137
  style={styles.container}
138
138
  ref={ref => {
139
- UnistylesShadowRegistry.add(ref, styles.container, undefined)
139
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
140
140
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
141
141
  }}
142
142
  >
@@ -185,7 +185,7 @@ pluginTester({
185
185
  <View
186
186
  style={styles.container}
187
187
  ref={ref => {
188
- UnistylesShadowRegistry.add(ref, styles.container, undefined)
188
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
189
189
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
190
190
  }}
191
191
  >
@@ -235,7 +235,7 @@ pluginTester({
235
235
  <View
236
236
  style={styles.container}
237
237
  ref={ref => {
238
- UnistylesShadowRegistry.add(ref, styles.container, undefined)
238
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
239
239
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
240
240
  }}
241
241
  >
@@ -286,7 +286,7 @@ pluginTester({
286
286
  <View
287
287
  style={styles.container}
288
288
  ref={ref => {
289
- UnistylesShadowRegistry.add(ref, styles.container, undefined)
289
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
290
290
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
291
291
  }}
292
292
  >
@@ -338,7 +338,7 @@ pluginTester({
338
338
  <View
339
339
  style={styles.container}
340
340
  ref={ref => {
341
- UnistylesShadowRegistry.add(ref, styles.container, undefined)
341
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
342
342
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
343
343
  }}
344
344
  >
@@ -392,7 +392,7 @@ pluginTester({
392
392
  <View
393
393
  style={styles.container}
394
394
  ref={ref => {
395
- UnistylesShadowRegistry.add(ref, styles.container, undefined)
395
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
396
396
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
397
397
  }}
398
398
  >
@@ -454,7 +454,7 @@ pluginTester({
454
454
  <View
455
455
  style={styles.container}
456
456
  ref={ref => {
457
- UnistylesShadowRegistry.add(ref, styles.container, undefined)
457
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
458
458
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
459
459
  }}
460
460
  >
package/plugin/ref.js CHANGED
@@ -20,19 +20,14 @@ function addRef(t, path, metadata, state) {
20
20
  const newRefFunction = t.arrowFunctionExpression(
21
21
  [t.identifier('ref')],
22
22
  t.blockStatement([
23
- metadata.dynamicFunction ? t.expressionStatement(
24
- t.callExpression(
25
- metadata.dynamicFunction.callee,
26
- metadata.dynamicFunction.arguments.concat(t.identifier('ref'))
27
- )
28
- ) : null,
29
23
  t.expressionStatement(
30
24
  t.callExpression(
31
25
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
32
26
  [
33
27
  t.identifier('ref'),
34
28
  t.memberExpression(t.identifier(metadata.styleObj), t.identifier(metadata.styleProp)),
35
- t.identifier(hasVariants ? '__uni__variants' : 'undefined')
29
+ t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
30
+ metadata.dynamicFunction ? t.arrayExpression(metadata.dynamicFunction.arguments) : t.identifier('undefined')
36
31
  ]
37
32
  )
38
33
  ),
@@ -44,7 +39,7 @@ function addRef(t, path, metadata, state) {
44
39
  )
45
40
  )
46
41
  )
47
- ].filter(Boolean))
42
+ ])
48
43
  )
49
44
 
50
45
  const newRefProp = t.jsxAttribute(
@@ -74,12 +69,6 @@ function overrideRef(t, path, refProp, metadata, state) {
74
69
  t.identifier(uniqueRefName)
75
70
  )
76
71
  ),
77
- metadata.dynamicFunction ? t.expressionStatement(
78
- t.callExpression(
79
- metadata.dynamicFunction.callee,
80
- metadata.dynamicFunction.arguments.concat(t.identifier(uniqueRefName))
81
- )
82
- ) : null,
83
72
  t.expressionStatement(
84
73
  t.callExpression(
85
74
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
@@ -87,7 +76,8 @@ function overrideRef(t, path, refProp, metadata, state) {
87
76
  [
88
77
  t.identifier(uniqueRefName),
89
78
  t.memberExpression(t.identifier(metadata.styleObj), t.identifier(metadata.styleProp)),
90
- t.identifier(hasVariants ? '__uni__variants' : 'undefined')
79
+ t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
80
+ metadata.dynamicFunction ? t.arrayExpression(metadata.dynamicFunction.arguments) : t.identifier('undefined')
91
81
  ]
92
82
  )
93
83
  ),
@@ -99,7 +89,7 @@ function overrideRef(t, path, refProp, metadata, state) {
99
89
  )
100
90
  )
101
91
  )
102
- ].filter(Boolean))
92
+ ])
103
93
  )
104
94
 
105
95
  refProp.value = t.jsxExpressionContainer(newRefFunction)
@@ -120,19 +110,14 @@ function overrideRef(t, path, refProp, metadata, state) {
120
110
  [t.identifier('ref')],
121
111
  t.blockStatement([
122
112
  ...userStatements.filter(statement => !t.isReturnStatement(statement)),
123
- metadata.dynamicFunction ? t.expressionStatement(
124
- t.callExpression(
125
- metadata.dynamicFunction.callee,
126
- metadata.dynamicFunction.arguments.concat(t.identifier('ref'))
127
- )
128
- ) : null,
129
113
  t.expressionStatement(
130
114
  t.callExpression(
131
115
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
132
116
  [
133
117
  t.identifier('ref'),
134
118
  t.memberExpression(t.identifier(metadata.styleObj), t.identifier(metadata.styleProp)),
135
- t.identifier(hasVariants ? '__uni__variants' : 'undefined')
119
+ t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
120
+ metadata.dynamicFunction ? t.arrayExpression(metadata.dynamicFunction.arguments) : t.identifier('undefined')
136
121
  ]
137
122
  )
138
123
  ),
@@ -152,7 +137,7 @@ function overrideRef(t, path, refProp, metadata, state) {
152
137
  )
153
138
  ]))
154
139
  )
155
- ].filter(Boolean))
140
+ ])
156
141
  )
157
142
 
158
143
  refProp.value = t.jsxExpressionContainer(newRefFunction)
@@ -185,19 +170,14 @@ function overrideRef(t, path, refProp, metadata, state) {
185
170
  t.expressionStatement(
186
171
  t.callExpression(userFunctionName, [t.identifier(uniqueRefName)])
187
172
  ),
188
- metadata.dynamicFunction ? t.expressionStatement(
189
- t.callExpression(
190
- metadata.dynamicFunction.callee,
191
- metadata.dynamicFunction.arguments.concat(t.identifier(uniqueRefName))
192
- )
193
- ) : null,
194
173
  t.expressionStatement(
195
174
  t.callExpression(
196
175
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
197
176
  [
198
177
  t.identifier(uniqueRefName),
199
178
  t.memberExpression(t.identifier(metadata.styleObj), t.identifier(metadata.styleProp)),
200
- t.identifier(hasVariants ? '__uni__variants' : 'undefined')
179
+ t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
180
+ metadata.dynamicFunction ? t.arrayExpression(metadata.dynamicFunction.arguments) : t.identifier('undefined')
201
181
  ]
202
182
  )
203
183
  ),
@@ -216,7 +196,7 @@ function overrideRef(t, path, refProp, metadata, state) {
216
196
  )
217
197
  ]))
218
198
  )
219
- ].filter(Boolean))
199
+ ])
220
200
  )
221
201
 
222
202
  refProp.value = t.jsxExpressionContainer(newRefFunction)
@@ -4,10 +4,10 @@ import type { ShadowNode, Unistyle, ViewHandle } from './types'
4
4
 
5
5
  interface ShadowRegistry extends UnistylesShadowRegistrySpec {
6
6
  // Babel API
7
- add(handle?: ViewHandle, style?: Unistyle, variants?: Record<string, string | boolean>): void,
7
+ add(handle?: ViewHandle, style?: Unistyle, variants?: Record<string, string | boolean>, args?: Array<any>): void,
8
8
  remove(handle?: ViewHandle, style?: Unistyle): void,
9
9
  // JSI
10
- link(node: ShadowNode, style: Unistyle, variants?: Record<string, string | boolean>): void,
10
+ link(node: ShadowNode, style: Unistyle, variants?: Record<string, string | boolean>, args?: Array<any>): void,
11
11
  unlink(node: ShadowNode, style: Unistyle): void
12
12
  }
13
13
 
@@ -26,12 +26,12 @@ const findShadowNodeForHandle = (handle: ViewHandle) => {
26
26
  return node
27
27
  }
28
28
 
29
- HybridShadowRegistry.add = (handle, style, variants) => {
29
+ HybridShadowRegistry.add = (handle, style, variants, args) => {
30
30
  if (!handle || !style?.__unid) {
31
31
  return
32
32
  }
33
33
 
34
- HybridShadowRegistry.link(findShadowNodeForHandle(handle), style, variants ?? {})
34
+ HybridShadowRegistry.link(findShadowNodeForHandle(handle), style, variants ?? {}, args ?? [])
35
35
  }
36
36
 
37
37
  HybridShadowRegistry.remove = (handle, style) => {