react-native-unistyles 3.0.0-alpha.10 → 3.0.0-alpha.11

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.
@@ -7,6 +7,8 @@
7
7
 
8
8
  namespace margelo::nitro::unistyles::core {
9
9
 
10
+ class StyleSheet;
11
+
10
12
  using namespace facebook;
11
13
 
12
14
  enum class UnistyleType {
@@ -17,8 +19,8 @@ enum class UnistyleType {
17
19
  struct Unistyle {
18
20
  using Shared = std::shared_ptr<Unistyle>;
19
21
 
20
- Unistyle(UnistyleType type, std::string styleKey, jsi::Object& rawObject)
21
- : styleKey{styleKey}, type{type}, rawValue{std::move(rawObject)} {}
22
+ Unistyle(UnistyleType type, std::string styleKey, jsi::Object& rawObject, std::shared_ptr<StyleSheet> styleSheet)
23
+ : styleKey{styleKey}, type{type}, rawValue{std::move(rawObject)}, parent{styleSheet} {}
22
24
  virtual ~Unistyle() = default;
23
25
 
24
26
  Unistyle(const Unistyle&) = delete;
@@ -29,6 +31,7 @@ struct Unistyle {
29
31
  jsi::Object rawValue;
30
32
  std::optional<jsi::Object> parsedStyle;
31
33
  std::vector<UnistyleDependency> dependencies{};
34
+ std::shared_ptr<StyleSheet> parent;
32
35
 
33
36
  inline void addDependency(UnistyleDependency dependency) {
34
37
  // we can't add dependencies if unistyle is sealed
@@ -62,8 +65,8 @@ struct UnistyleDynamicFunction: public Unistyle {
62
65
  // unprocessedValue <- object generated after calling proxy and user's original function
63
66
  // parsedStyle <- parsed with Unistyle's parser
64
67
 
65
- UnistyleDynamicFunction(UnistyleType type, std::string styleKey, jsi::Object& rawObject)
66
- : Unistyle(type, styleKey, rawObject) {}
68
+ UnistyleDynamicFunction(UnistyleType type, std::string styleKey, jsi::Object& rawObject, std::shared_ptr<StyleSheet> styleSheet)
69
+ : Unistyle(type, styleKey, rawObject, styleSheet) {}
67
70
 
68
71
  UnistyleDynamicFunction(const UnistyleDynamicFunction&) = delete;
69
72
  UnistyleDynamicFunction(UnistyleDynamicFunction&& other) = delete;
@@ -21,7 +21,25 @@ inline static Unistyle::Shared unistyleFromValue(jsi::Runtime& rt, const jsi::Va
21
21
  return nullptr;
22
22
  }
23
23
 
24
- return value.getObject(rt).getNativeState<UnistyleWrapper>(rt)->unistyle;
24
+ auto obj = value.getObject(rt);
25
+
26
+ if (!obj.hasNativeState(rt)) {
27
+ throw jsi::JSError(rt, R"(Unistyles: Style is not bound!
28
+
29
+ Potential reasons:
30
+ - You likely used the spread operator on a Unistyle style outside of a JSX component
31
+ - You're mixing React Native's StyleSheet styles with Unistyles styles
32
+
33
+ If you need to merge styles, do it within the style prop of your JSX component:
34
+
35
+ style={{...styles.container, ...styles.otherProp}} or style={[styles.container, styles.otherProp]}
36
+
37
+ Copying a Unistyle style outside of a JSX element will remove its internal C++ state, leading to unexpected behavior.
38
+
39
+ If you're mixing React Native and Unistyle StyleSheet styles, move your static styles into Unistyles to avoid conflicts.)");
40
+ }
41
+
42
+ return obj.getNativeState<UnistyleWrapper>(rt)->unistyle;
25
43
  }
26
44
 
27
45
  inline static jsi::Value valueFromUnistyle(jsi::Runtime& rt, Unistyle::Shared unistyle) {
@@ -104,57 +104,40 @@ std::shared_ptr<core::StyleSheet> core::UnistylesRegistry::addStyleSheet(jsi::Ru
104
104
  core::DependencyMap core::UnistylesRegistry::buildDependencyMap(jsi::Runtime& rt, std::vector<UnistyleDependency>& deps) {
105
105
  DependencyMap dependencyMap;
106
106
  std::set<UnistyleDependency> uniqueDependencies(deps.begin(), deps.end());
107
-
108
- for (const auto& [_, styleSheet] : this->_styleSheetRegistry[&rt]) {
109
- for (const auto& [_, unistyle] : styleSheet->unistyles) {
110
- // check if in the given stylesheet we have unistyle
111
- // that depends on something affected
107
+
108
+ for (const auto& [family, unistyles] : this->_shadowRegistry) {
109
+ for (const auto& unistyleData : unistyles) {
112
110
  bool hasAnyOfDependencies = std::any_of(
113
- unistyle->dependencies.begin(),
114
- unistyle->dependencies.end(),
111
+ unistyleData->unistyle->dependencies.begin(),
112
+ unistyleData->unistyle->dependencies.end(),
115
113
  [&uniqueDependencies](UnistyleDependency dep) {
116
114
  return std::find(uniqueDependencies.begin(), uniqueDependencies.end(), dep) != uniqueDependencies.end();
117
115
  }
118
116
  );
119
-
117
+
120
118
  if (!hasAnyOfDependencies) {
121
119
  continue;
122
120
  }
123
-
124
- // if so, we need to find shadow family too
125
- for (const auto& pair : this->_shadowRegistry) {
126
- const auto& [family, unistyles] = pair;
127
-
128
- for (const auto& unistyleData : unistyles) {
129
- if (unistyle != unistyleData->unistyle) {
130
- continue;
131
- }
132
-
133
- dependencyMap[styleSheet][family].emplace_back(unistyleData);
134
- }
121
+
122
+ // we need to take in count all unistyles from the shadowNode
123
+ // as user might be using spreads and not all of them may have dependencies
124
+ for (const auto& unistyleData : unistyles) {
125
+ dependencyMap[family].emplace_back(unistyleData);
135
126
  }
127
+
128
+ break;
136
129
  }
137
130
  }
138
-
131
+
139
132
  return dependencyMap;
140
133
  }
141
134
 
142
135
  core::DependencyMap core::UnistylesRegistry::buildDependencyMap(jsi::Runtime& rt) {
143
136
  DependencyMap dependencyMap;
144
-
145
- for (const auto& [_, styleSheet] : this->_styleSheetRegistry[&rt]) {
146
- for (const auto& [_, unistyle] : styleSheet->unistyles) {
147
- for (const auto& pair : this->_shadowRegistry) {
148
- const auto& [family, unistyles] = pair;
149
-
150
- for (const auto& unistyleData : unistyles) {
151
- if (unistyle != unistyleData->unistyle) {
152
- continue;
153
- }
154
-
155
- dependencyMap[styleSheet][family].emplace_back(unistyleData);
156
- }
157
- }
137
+
138
+ for (const auto& [family, unistyles] : this->_shadowRegistry) {
139
+ for (const auto& unistyleData : unistyles) {
140
+ dependencyMap[family].emplace_back(unistyleData);
158
141
  }
159
142
  }
160
143
 
@@ -19,10 +19,7 @@ struct UnistylesState;
19
19
  using namespace facebook;
20
20
  using namespace facebook::react;
21
21
 
22
- using DependencyMap = std::unordered_map<
23
- std::shared_ptr<core::StyleSheet>,
24
- std::unordered_map<const ShadowNodeFamily*, std::vector<std::shared_ptr<UnistyleData>>>
25
- >;
22
+ using DependencyMap = std::unordered_map<const ShadowNodeFamily*, std::vector<std::shared_ptr<UnistyleData>>>;
26
23
 
27
24
  struct UnistylesRegistry: public StyleSheetRegistry {
28
25
  static UnistylesRegistry& get();
@@ -5,29 +5,29 @@ 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
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
12
  auto rawArguments = args[3].asObject(rt).asArray(rt);
13
13
  std::vector<folly::dynamic> arguments = helpers::parseDynamicFunctionArguments(rt, rawArguments);
14
-
14
+
15
15
  auto& registry = core::UnistylesRegistry::get();
16
-
16
+
17
17
  registry.linkShadowNodeWithUnistyle(&shadowNodeWrapper->getFamily(), unistyleWrapper, variants, arguments);
18
-
18
+
19
19
  return jsi::Value::undefined();
20
20
  }
21
21
 
22
22
  jsi::Value HybridShadowRegistry::unlink(jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) {
23
23
  helpers::assertThat(rt, count == 2, "Unistyles: Invalid babel transform 'ShadowRegistry unlink' expected 2 arguments.");
24
-
24
+
25
25
  ShadowNode::Shared shadowNodeWrapper = shadowNodeFromValue(rt, args[0]);
26
26
  core::Unistyle::Shared unistyleWrapper = core::unistyleFromValue(rt, args[1]);
27
-
27
+
28
28
  auto& registry = core::UnistylesRegistry::get();
29
29
 
30
30
  registry.unlinkShadowNodeWithUnistyle(&shadowNodeWrapper->getFamily(), unistyleWrapper);
31
-
31
+
32
32
  return jsi::Value::undefined();
33
33
  }
@@ -20,7 +20,8 @@ void parser::Parser::buildUnistyles(jsi::Runtime& rt, std::shared_ptr<StyleSheet
20
20
  styleSheet->unistyles[styleKey] = std::make_shared<UnistyleDynamicFunction>(
21
21
  UnistyleType::DynamicFunction,
22
22
  styleKey,
23
- styleValue
23
+ styleValue,
24
+ styleSheet
24
25
  );
25
26
 
26
27
  return;
@@ -29,7 +30,8 @@ void parser::Parser::buildUnistyles(jsi::Runtime& rt, std::shared_ptr<StyleSheet
29
30
  styleSheet->unistyles[styleKey] = std::make_shared<Unistyle>(
30
31
  UnistyleType::Object,
31
32
  styleKey,
32
- styleValue
33
+ styleValue,
34
+ styleSheet
33
35
  );
34
36
  });
35
37
  }
@@ -98,22 +100,22 @@ void parser::Parser::rebuildUnistylesWithVariants(jsi::Runtime& rt, std::shared_
98
100
 
99
101
  // rebuild all unistyles that are affected by platform event
100
102
  void parser::Parser::rebuildUnistylesInDependencyMap(jsi::Runtime& rt, DependencyMap& dependencyMap) {
101
- for (auto& [styleSheet, map] : dependencyMap) {
103
+ for (auto& [shadowNode, unistyles] : dependencyMap) {
104
+ auto styleSheet = unistyles.begin()->get()->unistyle->parent;
105
+
102
106
  jsi::Object unwrappedStyleSheet = this->unwrapStyleSheet(rt, styleSheet);
103
107
 
104
- for (auto& [shadowNode, unistyles] : map) {
105
- for (auto& unistyleData : unistyles) {
106
- auto& unistyle = unistyleData->unistyle;
108
+ for (auto& unistyleData : unistyles) {
109
+ auto& unistyle = unistyleData->unistyle;
107
110
 
108
- // StyleSheet might have styles that are not affected
109
- if (!unwrappedStyleSheet.hasProperty(rt, unistyle->styleKey.c_str())) {
110
- continue;
111
- }
112
-
113
- unistyle->rawValue = unwrappedStyleSheet.getProperty(rt, unistyle->styleKey.c_str()).asObject(rt);
114
- this->rebuildUnistyle(rt, styleSheet, unistyle, unistyleData->variants, unistyleData->dynamicFunctionMetadata);
115
- unistyleData->parsedStyle = jsi::Value(rt, unistyle->parsedStyle.value()).asObject(rt);
111
+ // StyleSheet might have styles that are not affected
112
+ if (!unwrappedStyleSheet.hasProperty(rt, unistyle->styleKey.c_str())) {
113
+ continue;
116
114
  }
115
+
116
+ unistyle->rawValue = unwrappedStyleSheet.getProperty(rt, unistyle->styleKey.c_str()).asObject(rt);
117
+ this->rebuildUnistyle(rt, styleSheet, unistyle, unistyleData->variants, unistyleData->dynamicFunctionMetadata);
118
+ unistyleData->parsedStyle = jsi::Value(rt, unistyle->parsedStyle.value()).asObject(rt);
117
119
  }
118
120
  }
119
121
  }
@@ -148,7 +150,7 @@ void parser::Parser::rebuildUnistyle(jsi::Runtime& rt, std::shared_ptr<StyleShee
148
150
  // call cached function with memoized arguments
149
151
  auto functionResult = unistyleFn->rawValue
150
152
  .asFunction(rt)
151
- .callAsConstructor(rt, argStart, dynamicFunctionMetadata.size())
153
+ .call(rt, argStart, dynamicFunctionMetadata.size())
152
154
  .asObject(rt);
153
155
 
154
156
  unistyleFn->unprocessedValue = std::move(functionResult);
@@ -160,21 +162,11 @@ void parser::Parser::rebuildUnistyle(jsi::Runtime& rt, std::shared_ptr<StyleShee
160
162
  shadow::ShadowLeafUpdates parser::Parser::dependencyMapToShadowLeafUpdates(core::DependencyMap& dependencyMap) {
161
163
  shadow::ShadowLeafUpdates updates;
162
164
  auto& rt = this->_unistylesRuntime->getRuntime();
163
-
164
- for (const auto& [styleSheet, map] : dependencyMap) {
165
- for (const auto& [shadowNode, unistyles] : map) {
166
- for (const auto& unistyleData : unistyles) {
167
- auto rawProps = this->parseStylesToShadowTreeStyles(rt, unistyleData->parsedStyle.value());
168
-
169
- if (updates.contains(shadowNode)) {
170
- updates[shadowNode].emplace_back(std::move(rawProps));
171
-
172
- continue;
173
- }
174
-
175
- updates.emplace(shadowNode, std::vector<RawProps>{std::move(rawProps)});
176
- }
177
- }
165
+
166
+ for (const auto& [shadowNode, unistyles] : dependencyMap) {
167
+ auto rawProps = this->parseStylesToShadowTreeStyles(rt, unistyles);
168
+
169
+ updates.emplace(shadowNode, std::move(rawProps));
178
170
  }
179
171
 
180
172
  return updates;
@@ -617,18 +609,20 @@ jsi::Value parser::Parser::parseSecondLevel(jsi::Runtime &rt, Unistyle::Shared u
617
609
  return parsedStyle;
618
610
  }
619
611
 
620
- // convert jsi::Object to RawValue with int colors
621
- RawProps parser::Parser::parseStylesToShadowTreeStyles(jsi::Runtime& rt, const jsi::Object& styles) {
612
+ // convert unistyles to RawValue with int colors
613
+ RawProps parser::Parser::parseStylesToShadowTreeStyles(jsi::Runtime& rt, const std::vector<std::shared_ptr<UnistyleData>>& unistyles) {
622
614
  jsi::Object convertedStyles = jsi::Object(rt);
623
615
  auto& state = core::UnistylesRegistry::get().getState(rt);
616
+
617
+ for (const auto& unistyleData : unistyles) {
618
+ helpers::enumerateJSIObject(rt, unistyleData->parsedStyle.value(), [&](const std::string& propertyName, jsi::Value& propertyValue){
619
+ if (this->isColor(propertyName)) {
620
+ return convertedStyles.setProperty(rt, propertyName.c_str(), jsi::Value(state.parseColor(propertyValue)));
621
+ }
624
622
 
625
- helpers::enumerateJSIObject(rt, styles, [&](const std::string& propertyName, jsi::Value& propertyValue){
626
- if (this->isColor(propertyName)) {
627
- return convertedStyles.setProperty(rt, propertyName.c_str(), jsi::Value(state.parseColor(propertyValue)));
628
- }
629
-
630
- convertedStyles.setProperty(rt, propertyName.c_str(), propertyValue);
631
- });
623
+ convertedStyles.setProperty(rt, propertyName.c_str(), propertyValue);
624
+ });
625
+ }
632
626
 
633
627
  return RawProps(rt, std::move(convertedStyles));
634
628
  }
@@ -40,7 +40,7 @@ private:
40
40
  jsi::Value getStylesForVariant(jsi::Runtime& rt, const std::string groupName, jsi::Object&& groupValue, std::optional<std::string> selectedVariant, Variants& variants);
41
41
  jsi::Object parseCompoundVariants(jsi::Runtime& rt, Unistyle::Shared unistyle, jsi::Object& obj, Variants& variants);
42
42
  bool shouldApplyCompoundVariants(jsi::Runtime& rt, const Variants& variants, jsi::Object& compoundVariant);
43
- RawProps parseStylesToShadowTreeStyles(jsi::Runtime& rt, const jsi::Object& parsedStyles);
43
+ RawProps parseStylesToShadowTreeStyles(jsi::Runtime& rt, const std::vector<std::shared_ptr<UnistyleData>>& unistyles);
44
44
  bool isColor(const std::string& propertyName);
45
45
 
46
46
  std::shared_ptr<HybridUnistylesRuntime> _unistylesRuntime;
@@ -8,6 +8,6 @@ namespace margelo::nitro::unistyles::shadow {
8
8
  using namespace facebook;
9
9
  using namespace facebook::react;
10
10
 
11
- using ShadowLeafUpdates = std::unordered_map<const ShadowNodeFamily*, std::vector<RawProps>>;
11
+ using ShadowLeafUpdates = std::unordered_map<const ShadowNodeFamily*, RawProps>;
12
12
 
13
13
  }
@@ -106,14 +106,9 @@ ShadowNode::Unshared shadow::ShadowTreeManager::cloneShadowTree(jsi::Runtime& rt
106
106
  *shadowNode.getContextContainer()
107
107
  };
108
108
 
109
- updatedProps = shadowNode.getProps();
110
-
111
- // we may have multiple Unistyles for single node, so we must apply them all
112
- for (const auto& props: rawPropsIt->second) {
113
- updatedProps = shadowNode
114
- .getComponentDescriptor()
115
- .cloneProps(propsParserContext, updatedProps, RawProps(props));
116
- }
109
+ updatedProps = shadowNode
110
+ .getComponentDescriptor()
111
+ .cloneProps(propsParserContext, shadowNode.getProps(), RawProps(rawPropsIt->second));
117
112
  }
118
113
 
119
114
  return shadowNode.clone({
@@ -15,7 +15,7 @@ const findShadowNodeForHandle = handle => {
15
15
  return node;
16
16
  };
17
17
  HybridShadowRegistry.add = (handle, style, variants, args) => {
18
- if (!handle || !style?.__unid) {
18
+ if (!handle) {
19
19
  return;
20
20
  }
21
21
  HybridShadowRegistry.link(findShadowNodeForHandle(handle), style, variants ?? {}, args ?? []);
@@ -1 +1 @@
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":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3,"names":["_reactNativeNitroModules","require","HybridShadowRegistry","NitroModules","createHybridObject","findShadowNodeForHandle","handle","node","__internalInstanceHandle","stateNode","getScrollResponder","getNativeScrollRef","Error","add","style","variants","args","link","remove","__unid","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,EAAE;IACT;EACJ;EAEAJ,oBAAoB,CAACe,IAAI,CAACZ,uBAAuB,CAACC,MAAM,CAAC,EAAEQ,KAAK,EAAEC,QAAQ,IAAI,CAAC,CAAC,EAAEC,IAAI,IAAI,EAAE,CAAC;AACjG,CAAC;AAEDd,oBAAoB,CAACgB,MAAM,GAAG,CAACZ,MAAM,EAAEQ,KAAK,KAAK;EAC7C,IAAI,CAACR,MAAM,IAAI,CAACQ,KAAK,EAAEK,MAAM,EAAE;IAC3B;EACJ;EAEAjB,oBAAoB,CAACkB,MAAM,CAACf,uBAAuB,CAACC,MAAM,CAAC,EAAEQ,KAAK,CAAC;AACvE,CAAC;AAQM,MAAMO,uBAAuB,GAAAC,OAAA,CAAAD,uBAAA,GAAGnB,oBAA4D","ignoreList":[]}
@@ -11,7 +11,7 @@ const findShadowNodeForHandle = handle => {
11
11
  return node;
12
12
  };
13
13
  HybridShadowRegistry.add = (handle, style, variants, args) => {
14
- if (!handle || !style?.__unid) {
14
+ if (!handle) {
15
15
  return;
16
16
  }
17
17
  HybridShadowRegistry.link(findShadowNodeForHandle(handle), style, variants ?? {}, args ?? []);
@@ -1 +1 @@
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
+ {"version":3,"names":["NitroModules","HybridShadowRegistry","createHybridObject","findShadowNodeForHandle","handle","node","__internalInstanceHandle","stateNode","getScrollResponder","getNativeScrollRef","Error","add","style","variants","args","link","remove","__unid","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,EAAE;IACT;EACJ;EAEAH,oBAAoB,CAACc,IAAI,CAACZ,uBAAuB,CAACC,MAAM,CAAC,EAAEQ,KAAK,EAAEC,QAAQ,IAAI,CAAC,CAAC,EAAEC,IAAI,IAAI,EAAE,CAAC;AACjG,CAAC;AAEDb,oBAAoB,CAACe,MAAM,GAAG,CAACZ,MAAM,EAAEQ,KAAK,KAAK;EAC7C,IAAI,CAACR,MAAM,IAAI,CAACQ,KAAK,EAAEK,MAAM,EAAE;IAC3B;EACJ;EAEAhB,oBAAoB,CAACiB,MAAM,CAACf,uBAAuB,CAACC,MAAM,CAAC,EAAEQ,KAAK,CAAC;AACvE,CAAC;AAQD,OAAO,MAAMO,uBAAuB,GAAGlB,oBAA4D","ignoreList":[]}
@@ -3,7 +3,7 @@ import type { ShadowNode, Unistyle, ViewHandle } from './types';
3
3
  interface ShadowRegistry extends UnistylesShadowRegistrySpec {
4
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>, args?: Array<any>): 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,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AAC,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,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;IAC/G,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.10",
3
+ "version": "3.0.0-alpha.11",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -16,6 +16,7 @@ pluginTester({
16
16
  {
17
17
  title: 'Should detect dependencies in variants',
18
18
  code: `
19
+ import { View, Text } from 'react-native'
19
20
  import { StyleSheet } from 'react-native-unistyles'
20
21
 
21
22
  export const Example = () => {
@@ -44,12 +45,13 @@ pluginTester({
44
45
  `,
45
46
  output: `
46
47
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
48
+ import { View, Text } from 'react-native'
47
49
  import { StyleSheet } from 'react-native-unistyles'
48
50
 
49
51
  export const Example = () => {
50
52
  return (
51
53
  <View
52
- style={styles.container}
54
+ style={[styles.container]}
53
55
  ref={ref => {
54
56
  UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
55
57
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
@@ -82,6 +84,7 @@ pluginTester({
82
84
  {
83
85
  title: 'Should detect dependencies in breakpoints',
84
86
  code: `
87
+ import { View, Text } from 'react-native'
85
88
  import { StyleSheet } from 'react-native-unistyles'
86
89
 
87
90
  export const Example = () => {
@@ -105,12 +108,13 @@ pluginTester({
105
108
  `,
106
109
  output: `
107
110
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
111
+ import { View, Text } from 'react-native'
108
112
  import { StyleSheet } from 'react-native-unistyles'
109
113
 
110
114
  export const Example = () => {
111
115
  return (
112
116
  <View
113
- style={styles.container}
117
+ style={[styles.container]}
114
118
  ref={ref => {
115
119
  UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
116
120
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
@@ -140,6 +144,7 @@ pluginTester({
140
144
  {
141
145
  title: 'Should detect dependencies in calculations',
142
146
  code: `
147
+ import { View, Text } from 'react-native'
143
148
  import { StyleSheet } from 'react-native-unistyles'
144
149
 
145
150
  export const Example = () => {
@@ -160,12 +165,13 @@ pluginTester({
160
165
  `,
161
166
  output: `
162
167
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
168
+ import { View, Text } from 'react-native'
163
169
  import { StyleSheet } from 'react-native-unistyles'
164
170
 
165
171
  export const Example = () => {
166
172
  return (
167
173
  <View
168
- style={styles.container}
174
+ style={[styles.container]}
169
175
  ref={ref => {
170
176
  UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
171
177
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
@@ -192,6 +198,7 @@ pluginTester({
192
198
  {
193
199
  title: 'Should detect dependencies in _web',
194
200
  code: `
201
+ import { View, Text } from 'react-native'
195
202
  import { StyleSheet } from 'react-native-unistyles'
196
203
 
197
204
  export const Example = () => {
@@ -273,12 +280,13 @@ pluginTester({
273
280
  `,
274
281
  output: `
275
282
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
283
+ import { View, Text } from 'react-native'
276
284
  import { StyleSheet } from 'react-native-unistyles'
277
285
 
278
286
  export const Example = () => {
279
287
  return (
280
288
  <View
281
- style={styles.container}
289
+ style={[styles.container]}
282
290
  ref={ref => {
283
291
  UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
284
292
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
@@ -371,6 +379,7 @@ pluginTester({
371
379
  {
372
380
  title: 'Should allow user to use arrow functions with body for dynamic functions',
373
381
  code: `
382
+ import { View, Text } from 'react-native'
374
383
  import { StyleSheet } from 'react-native-unistyles'
375
384
 
376
385
  export const Example = () => {
@@ -398,12 +407,13 @@ pluginTester({
398
407
  `,
399
408
  output: `
400
409
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
410
+ import { View, Text } from 'react-native'
401
411
  import { StyleSheet } from 'react-native-unistyles'
402
412
 
403
413
  export const Example = () => {
404
414
  return (
405
415
  <View
406
- style={styles.container}
416
+ style={[styles.container]}
407
417
  ref={ref => {
408
418
  UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
409
419
  return () => UnistylesShadowRegistry.remove(ref, styles.container)