@@ -36,12 +36,20 @@ void parser::Parser::buildUnistyles(jsi::Runtime& rt, std::shared_ptr<StyleSheet
36
36
});
37
37
}
38
38
39
+ void parser::Parser::rebuildUnistyleWithVariants (jsi::Runtime& rt, std::shared_ptr<UnistyleData> unistyleData) {
40
+ if (unistyleData->unistyle ->parent == nullptr || unistyleData->unistyle ->parent ->type == StyleSheetType::Static) {
41
+ return ;
42
+ }
43
+
44
+ unistyleData->parsedStyle = this ->parseFirstLevel (rt, unistyleData->unistyle , unistyleData->variants );
45
+ }
46
+
39
47
jsi::Value parser::Parser::getParsedStyleSheetForScopedTheme (jsi::Runtime& rt, core::Unistyle::Shared unistyle, std::string& scopedTheme) {
40
48
// for static stylesheets and exotic styles we don't need to do anything
41
49
if (unistyle->parent == nullptr || unistyle->parent ->type == StyleSheetType::Static) {
42
50
return jsi::Value::undefined ();
43
51
}
44
-
52
+
45
53
auto & state = core::UnistylesRegistry::get ().getState (rt);
46
54
auto jsTheme = state.getJSThemeByName (scopedTheme);
47
55
@@ -51,9 +59,9 @@ jsi::Value parser::Parser::getParsedStyleSheetForScopedTheme(jsi::Runtime& rt, c
51
59
.call (rt, std::move (jsTheme))
52
60
.asObject (rt);
53
61
}
54
-
62
+
55
63
auto miniRuntime = this ->_unistylesRuntime ->getMiniRuntimeAsValue (rt, std::nullopt);
56
-
64
+
57
65
return unistyle->parent ->rawValue
58
66
.asFunction (rt)
59
67
.call (rt, std::move (jsTheme), std::move (miniRuntime))
@@ -64,29 +72,29 @@ void parser::Parser::rebuildUnistyleWithScopedTheme(jsi::Runtime& rt, jsi::Value
64
72
auto parsedStyleSheet = jsScopedTheme.isUndefined ()
65
73
? this ->getParsedStyleSheetForScopedTheme (rt, unistyleData->unistyle , unistyleData->scopedTheme .value ())
66
74
: jsScopedTheme.asObject (rt);
67
-
75
+
68
76
if (parsedStyleSheet.isUndefined ()) {
69
77
return ;
70
78
}
71
-
79
+
72
80
// get target style
73
81
auto targetStyle = parsedStyleSheet.asObject (rt).getProperty (rt, unistyleData->unistyle ->styleKey .c_str ()).asObject (rt);
74
82
75
83
// for object we just need to parse it
76
84
if (unistyleData->unistyle ->type == UnistyleType::Object) {
77
85
// we need to temporarly swap rawValue to enforce correct parings
78
86
auto sharedRawValue = std::move (unistyleData->unistyle ->rawValue );
79
-
87
+
80
88
unistyleData->unistyle ->rawValue = std::move (targetStyle);
81
89
unistyleData->parsedStyle = this ->parseFirstLevel (rt, unistyleData->unistyle , unistyleData->variants );
82
90
unistyleData->unistyle ->rawValue = std::move (sharedRawValue);
83
-
91
+
84
92
return ;
85
93
}
86
-
94
+
87
95
// for functions we need to call them with memoized arguments
88
96
auto unistyleFn = std::dynamic_pointer_cast<UnistyleDynamicFunction>(unistyleData->unistyle );
89
-
97
+
90
98
// convert arguments to jsi::Value
91
99
std::vector<jsi::Value> args{};
92
100
auto arguments = unistyleData->dynamicFunctionMetadata .value ();
@@ -100,7 +108,7 @@ void parser::Parser::rebuildUnistyleWithScopedTheme(jsi::Runtime& rt, jsi::Value
100
108
}
101
109
102
110
const jsi::Value *argStart = args.data ();
103
-
111
+
104
112
// we need to temporarly swap unprocessed value to enforce correct parings
105
113
auto sharedUnprocessedValue = std::move (unistyleFn->unprocessedValue );
106
114
@@ -224,29 +232,29 @@ void parser::Parser::rebuildUnistylesInDependencyMap(jsi::Runtime& rt, Dependenc
224
232
if (!parsedStyleSheetsWithDefaultTheme[unistyleStyleSheet].asObject (rt).hasProperty (rt, unistyle->styleKey .c_str ())) {
225
233
continue ;
226
234
}
227
-
235
+
228
236
// for scoped themes we need to parse unistyle exclusively
229
237
if (unistyleData->scopedTheme .has_value ()) {
230
238
std::vector<folly::dynamic> arguments = {};
231
-
239
+
232
240
if (unistyleData->dynamicFunctionMetadata .has_value ()) {
233
241
arguments = unistyleData->dynamicFunctionMetadata .value ();
234
242
}
235
-
243
+
236
244
auto parsedStyleSheet = jsi::Value::undefined ();
237
245
auto scopedThemeName = unistyleData->scopedTheme .value ();
238
-
246
+
239
247
// check if we have theme in cache
240
248
if (parsedStyleSheetsWithScopedTheme.contains (scopedThemeName)) {
241
249
if (parsedStyleSheetsWithScopedTheme[scopedThemeName].contains (unistyle->parent )) {
242
250
parsedStyleSheet = jsi::Value (rt, parsedStyleSheetsWithScopedTheme[scopedThemeName][unistyle->parent ]);
243
251
}
244
252
}
245
-
253
+
246
254
// if not, let's build it
247
255
if (parsedStyleSheet.isUndefined ()) {
248
256
parsedStyleSheet = this ->getParsedStyleSheetForScopedTheme (rt, unistyle, unistyleData->scopedTheme .value ());
249
-
257
+
250
258
if (!parsedStyleSheetsWithScopedTheme.contains (scopedThemeName)) {
251
259
parsedStyleSheetsWithScopedTheme.emplace (
252
260
scopedThemeName,
@@ -259,7 +267,7 @@ void parser::Parser::rebuildUnistylesInDependencyMap(jsi::Runtime& rt, Dependenc
259
267
jsi::Value (rt, parsedStyleSheet)
260
268
);
261
269
}
262
-
270
+
263
271
this ->rebuildUnistyleWithScopedTheme (
264
272
rt,
265
273
parsedStyleSheet,
@@ -485,10 +493,9 @@ jsi::Function parser::Parser::createDynamicFunctionProxy(jsi::Runtime& rt, Unist
485
493
? std::nullopt
486
494
: std::optional<Variants>(helpers::variantsToPairs (rt, rawVariants.asObject (rt)));
487
495
488
- unistyleFn->parsedStyle = this ->parseFirstLevel (rt, unistyleFn, variants);
489
- unistyleFn->seal ();
496
+ jsi::Object style = jsi::Value (rt, this ->parseFirstLevel (rt, unistyleFn, variants)).asObject (rt);
490
497
491
- jsi::Object style = jsi::Value (rt, unistyleFn->parsedStyle . value ()). asObject (rt );
498
+ unistyleFn->seal ( );
492
499
493
500
// include dependencies for createUnistylesComponent
494
501
style.setProperty (rt, " __proto__" , generateUnistylesPrototype (rt, unistylesRuntime, unistyle, variants, helpers::functionArgumentsToArray (rt, args, count)));
0 commit comments