@@ -32,6 +32,7 @@ namespace margelo::nitro::cssnitro {
3232 std::make_unique<ShadowTreeUpdateManager>();
3333 std::unordered_map<std::string, std::shared_ptr<reactnativecss::Computed<Styled>>> HybridStyleRegistry::computedMap_;
3434 std::unordered_map<std::string, std::shared_ptr<reactnativecss::Observable<std::vector<HybridStyleRule>>>> HybridStyleRegistry::styleRuleMap_;
35+ std::atomic<uint64_t > HybridStyleRegistry::nextStyleRuleId_{1 };
3536
3637 // Constructor, Destructor, and Method Implementations
3738 HybridStyleRegistry::HybridStyleRegistry () : HybridObject(" HybridStyleRegistry" ) {}
@@ -40,8 +41,18 @@ namespace margelo::nitro::cssnitro {
4041
4142 void HybridStyleRegistry::setClassname (const std::string &className,
4243 const std::vector<HybridStyleRule> &styleRules) {
44+ // Create a copy of the style rules to modify them
45+ auto rulesWithIds = styleRules;
46+
47+ // Assign unique IDs to any rules that don't have one
48+ for (auto &rule: rulesWithIds) {
49+ if (!rule.id .has_value ()) {
50+ rule.id = std::to_string (nextStyleRuleId_++);
51+ }
52+ }
53+
4354 // Reverse the style rules, this way later on we can bail early if values are already set
44- auto reversedRules = styleRules ;
55+ auto reversedRules = rulesWithIds ;
4556 std::reverse (reversedRules.begin (), reversedRules.end ());
4657
4758 auto it = styleRuleMap_.find (className);
@@ -102,13 +113,14 @@ namespace margelo::nitro::cssnitro {
102113 const std::string &variableScope,
103114 const std::string &containerScope) {
104115 Declarations declarations;
105- declarations.classNames = classNames;
106116 declarations.variableScope = variableScope;
107117
108118 std::regex whitespace{" \\ s+" };
109119 std::sregex_token_iterator tokenIt (classNames.begin (), classNames.end (), whitespace, -1 );
110120 std::sregex_token_iterator end;
111121
122+ std::vector<std::tuple<std::string, AttributeQuery>> attributeQueriesVec;
123+
112124 for (; tokenIt != end; ++tokenIt) {
113125 const std::string className = tokenIt->str ();
114126 if (className.empty ()) {
@@ -123,6 +135,12 @@ namespace margelo::nitro::cssnitro {
123135 const std::vector<HybridStyleRule> &styleRules = styleIt->second ->get ();
124136 bool hasVars = false ;
125137 for (const auto &sr: styleRules) {
138+ // Check for attribute queries
139+ if (sr.aq .has_value () && sr.id .has_value ()) {
140+ // The style rule id is already a string
141+ attributeQueriesVec.emplace_back (sr.id .value (), sr.aq .value ());
142+ }
143+
126144 // Check for variables
127145 if (sr.v .has_value ()) {
128146 hasVars = true ;
@@ -153,6 +171,11 @@ namespace margelo::nitro::cssnitro {
153171 }
154172 }
155173
174+ // Set attributeQueries if we found any
175+ if (!attributeQueriesVec.empty ()) {
176+ declarations.attributeQueries = std::move (attributeQueriesVec);
177+ }
178+
156179 return declarations;
157180 }
158181
@@ -161,7 +184,8 @@ namespace margelo::nitro::cssnitro {
161184 const std::function<void ()> &rerender,
162185 const std::string &classNames,
163186 const std::string &variableScope,
164- const std::string &containerScope) {
187+ const std::string &containerScope,
188+ const std::vector<std::string> &validAttributeQueries) {
165189 if (auto existing = computedMap_.find (componentId); existing != computedMap_.end ()) {
166190 if (existing->second ) {
167191 existing->second ->dispose ();
@@ -177,7 +201,8 @@ namespace margelo::nitro::cssnitro {
177201 rerender,
178202 *shadowUpdates_,
179203 variableScope,
180- containerScope);
204+ containerScope,
205+ validAttributeQueries);
181206
182207 computedMap_[componentId] = computed;
183208
0 commit comments