Skip to content

Commit b5074e0

Browse files
authored
Merge pull request #1175 from jpudysz/feature/scoped-themes-with-unistyles
fix: components wrapped in withUnistyles don't follow ScopedTheme
2 parents 0982397 + f278c71 commit b5074e0

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

packages/unistyles/cxx/core/UnistyleWrapper.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,29 @@ inline static jsi::Value objectFromUnistyle(jsi::Runtime& rt, std::shared_ptr<Hy
158158
) {
159159
auto& registry = UnistylesRegistry::get();
160160
auto unistyle = registry.getUnistyleById(unistyleID);
161+
auto scopedTheme = registry.getScopedTheme();
162+
parser::Parser parser(unistylesRuntime);
161163

162-
parser::Parser(unistylesRuntime).rebuildUnistyle(rt, unistyle, variants, parsedArguments);
164+
// scoped theme path — parse with scope so `withUnistyles`-wrapped
165+
// components inside <ScopedTheme> reflect the scope instead of the global theme
166+
if (scopedTheme.has_value() && unistyle->styleKey != helpers::EXOTIC_STYLE_KEY) {
167+
std::vector<folly::dynamic> scopedArguments = parsedArguments.has_value()
168+
? parsedArguments.value()
169+
: std::vector<folly::dynamic>{};
170+
171+
auto unistyleData = std::make_shared<UnistyleData>(unistyle, variants, scopedArguments, scopedTheme);
172+
auto parsedStyleSheet = parser.getParsedStyleSheetForScopedTheme(rt, unistyle, scopedTheme.value());
173+
174+
if (!parsedStyleSheet.isUndefined()) {
175+
parser.rebuildUnistyleWithScopedTheme(rt, parsedStyleSheet, unistyleData);
176+
177+
if (unistyleData->parsedStyle.has_value()) {
178+
return jsi::Value(rt, unistyleData->parsedStyle.value()).asObject(rt);
179+
}
180+
}
181+
}
182+
183+
parser.rebuildUnistyle(rt, unistyle, variants, parsedArguments);
163184

164185
return jsi::Value(rt, unistyle->parsedStyle.value()).asObject(rt);
165186
});

0 commit comments

Comments
 (0)