react-native-unistyles 3.0.0-alpha.1 → 3.0.0-alpha.11
Sign up to get free protection for your applications and to get access to all the features.
- package/Unistyles.podspec +33 -0
- package/cxx/common/Constants.h +1 -0
- package/cxx/common/Helpers.h +92 -0
- package/cxx/core/HostStyle.cpp +18 -12
- package/cxx/core/HostStyle.h +3 -0
- package/cxx/core/StyleSheet.h +0 -1
- package/cxx/core/StyleSheetRegistry.cpp +10 -13
- package/cxx/core/StyleSheetRegistry.h +4 -4
- package/cxx/core/Unistyle.h +7 -10
- package/cxx/core/UnistyleData.h +23 -0
- package/cxx/core/UnistyleWrapper.h +25 -7
- package/cxx/core/UnistylesCommitHook.cpp +8 -7
- package/cxx/core/UnistylesCommitHook.h +6 -1
- package/cxx/core/UnistylesCommitShadowNode.h +13 -0
- package/cxx/core/UnistylesMountHook.cpp +40 -0
- package/cxx/core/UnistylesMountHook.h +30 -0
- package/cxx/core/UnistylesRegistry.cpp +44 -75
- package/cxx/core/UnistylesRegistry.h +10 -11
- package/cxx/core/UnistylesState.cpp +4 -4
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +13 -6
- package/cxx/hybridObjects/HybridStyleSheet.cpp +35 -39
- package/cxx/hybridObjects/HybridStyleSheet.h +9 -6
- package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +34 -15
- package/cxx/hybridObjects/HybridUnistylesRuntime.h +2 -0
- package/cxx/parser/Parser.cpp +87 -165
- package/cxx/parser/Parser.h +8 -14
- package/cxx/shadowTree/ShadowLeafUpdate.h +1 -1
- package/cxx/shadowTree/ShadowTreeManager.cpp +3 -8
- package/ios/UnistylesModuleOnLoad.h +2 -0
- package/ios/UnistylesModuleOnLoad.mm +8 -1
- package/lib/commonjs/specs/NavigtionBar/index.js +1 -1
- package/lib/commonjs/specs/NavigtionBar/index.js.map +1 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js +3 -3
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/commonjs/specs/StatusBar/index.js +1 -1
- package/lib/commonjs/specs/StatusBar/index.js.map +1 -1
- package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
- package/lib/commonjs/specs/UnistylesRuntime/index.js +1 -1
- package/lib/commonjs/specs/UnistylesRuntime/index.js.map +1 -1
- package/lib/commonjs/specs/index.web.js +1 -1
- package/lib/commonjs/web/convert/boxShadow.js +77 -0
- package/lib/commonjs/web/convert/boxShadow.js.map +1 -0
- package/lib/commonjs/web/convert/breakpoint.js +25 -0
- package/lib/commonjs/web/convert/breakpoint.js.map +1 -0
- package/lib/commonjs/web/convert/index.js +76 -0
- package/lib/commonjs/web/convert/index.js.map +1 -0
- package/lib/commonjs/web/convert/module.d.js +2 -0
- package/lib/commonjs/web/convert/module.d.js.map +1 -0
- package/lib/commonjs/web/convert/shadow.js +68 -0
- package/lib/commonjs/web/convert/shadow.js.map +1 -0
- package/lib/commonjs/web/convert/style.js +89 -0
- package/lib/commonjs/web/convert/style.js.map +1 -0
- package/lib/commonjs/web/convert/textShadow.js +73 -0
- package/lib/commonjs/web/convert/textShadow.js.map +1 -0
- package/lib/commonjs/web/convert/transform.js +72 -0
- package/lib/commonjs/web/convert/transform.js.map +1 -0
- package/lib/commonjs/web/convert/types.js +9 -0
- package/lib/commonjs/web/convert/types.js.map +1 -0
- package/lib/commonjs/web/convert/utils.js +55 -0
- package/lib/commonjs/web/convert/utils.js.map +1 -0
- package/lib/commonjs/web/create.js +89 -0
- package/lib/commonjs/web/create.js.map +1 -0
- package/lib/commonjs/web/index.js +51 -0
- package/lib/commonjs/web/index.js.map +1 -0
- package/lib/commonjs/web/listener/index.js +13 -0
- package/lib/commonjs/web/listener/index.js.map +1 -0
- package/lib/commonjs/web/listener/listener.js +36 -0
- package/lib/commonjs/web/listener/listener.js.map +1 -0
- package/lib/commonjs/web/mock.js +37 -0
- package/lib/commonjs/web/mock.js.map +1 -0
- package/lib/commonjs/web/mq.js +23 -0
- package/lib/commonjs/web/mq.js.map +1 -0
- package/lib/commonjs/web/pseudo.js +11 -0
- package/lib/commonjs/web/pseudo.js.map +1 -0
- package/lib/commonjs/web/registry.js +37 -0
- package/lib/commonjs/web/registry.js.map +1 -0
- package/lib/commonjs/web/runtime.js +164 -0
- package/lib/commonjs/web/runtime.js.map +1 -0
- package/lib/commonjs/web/state.js +121 -0
- package/lib/commonjs/web/state.js.map +1 -0
- package/lib/commonjs/web/utils.js +78 -0
- package/lib/commonjs/web/utils.js.map +1 -0
- package/lib/commonjs/web/variants/getVariants.js +39 -0
- package/lib/commonjs/web/variants/getVariants.js.map +1 -0
- package/lib/commonjs/web/variants/index.js +28 -0
- package/lib/commonjs/web/variants/index.js.map +1 -0
- package/lib/commonjs/web/variants/useVariants.js +75 -0
- package/lib/commonjs/web/variants/useVariants.js.map +1 -0
- package/lib/module/specs/NavigtionBar/index.js +1 -1
- package/lib/module/specs/NavigtionBar/index.js.map +1 -1
- package/lib/module/specs/ShadowRegistry/index.js +3 -3
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/specs/StatusBar/index.js +1 -1
- package/lib/module/specs/StatusBar/index.js.map +1 -1
- package/lib/module/specs/StyleSheet/index.js.map +1 -1
- package/lib/module/specs/UnistylesRuntime/index.js +1 -1
- package/lib/module/specs/UnistylesRuntime/index.js.map +1 -1
- package/lib/module/specs/index.web.js +1 -1
- package/lib/module/specs/index.web.js.map +1 -1
- package/lib/module/web/convert/boxShadow.js +72 -0
- package/lib/module/web/convert/boxShadow.js.map +1 -0
- package/lib/module/web/convert/breakpoint.js +20 -0
- package/lib/module/web/convert/breakpoint.js.map +1 -0
- package/lib/module/web/convert/index.js +71 -0
- package/lib/module/web/convert/index.js.map +1 -0
- package/lib/module/web/convert/module.d.js +2 -0
- package/lib/module/web/convert/module.d.js.map +1 -0
- package/lib/module/web/convert/shadow.js +63 -0
- package/lib/module/web/convert/shadow.js.map +1 -0
- package/lib/module/web/convert/style.js +84 -0
- package/lib/module/web/convert/style.js.map +1 -0
- package/lib/module/web/convert/textShadow.js +68 -0
- package/lib/module/web/convert/textShadow.js.map +1 -0
- package/lib/module/web/convert/transform.js +67 -0
- package/lib/module/web/convert/transform.js.map +1 -0
- package/lib/module/web/convert/types.js +5 -0
- package/lib/module/web/convert/types.js.map +1 -0
- package/lib/module/web/convert/utils.js +43 -0
- package/lib/module/web/convert/utils.js.map +1 -0
- package/lib/module/web/create.js +84 -0
- package/lib/module/web/create.js.map +1 -0
- package/lib/module/web/index.js +24 -0
- package/lib/module/web/index.js.map +1 -0
- package/lib/module/web/listener/index.js +4 -0
- package/lib/module/web/listener/index.js.map +1 -0
- package/lib/module/web/listener/listener.js +31 -0
- package/lib/module/web/listener/listener.js.map +1 -0
- package/lib/module/web/mock.js +33 -0
- package/lib/module/web/mock.js.map +1 -0
- package/lib/module/web/mq.js +17 -0
- package/lib/module/web/mq.js.map +1 -0
- package/lib/module/web/pseudo.js +6 -0
- package/lib/module/web/pseudo.js.map +1 -0
- package/lib/module/web/registry.js +33 -0
- package/lib/module/web/registry.js.map +1 -0
- package/lib/module/web/runtime.js +160 -0
- package/lib/module/web/runtime.js.map +1 -0
- package/lib/module/web/state.js +117 -0
- package/lib/module/web/state.js.map +1 -0
- package/lib/module/web/utils.js +65 -0
- package/lib/module/web/utils.js.map +1 -0
- package/lib/module/web/variants/getVariants.js +34 -0
- package/lib/module/web/variants/getVariants.js.map +1 -0
- package/lib/module/web/variants/index.js +5 -0
- package/lib/module/web/variants/index.js.map +1 -0
- package/lib/module/web/variants/useVariants.js +70 -0
- package/lib/module/web/variants/useVariants.js.map +1 -0
- package/lib/typescript/example/App.d.ts.map +1 -1
- package/lib/typescript/example/Typography.d.ts +12 -0
- package/lib/typescript/example/Typography.d.ts.map +1 -0
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +2 -2
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/StyleSheet/index.d.ts +2 -1
- package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/index.web.d.ts +1 -1
- package/lib/typescript/src/specs/index.web.d.ts.map +1 -1
- package/lib/typescript/src/types/stylesheet.d.ts +1 -1
- package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/boxShadow.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/breakpoint.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/convert/index.d.ts +1 -1
- package/lib/typescript/src/web/convert/index.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/shadow.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/style.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/textShadow.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/transform.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/convert/types.d.ts +1 -1
- package/lib/typescript/src/web/convert/types.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/utils.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/create.d.ts +11 -11
- package/lib/typescript/{web → src/web}/create.d.ts.map +1 -1
- package/lib/typescript/{web → src/web}/index.d.ts +12 -12
- package/lib/typescript/{web → src/web}/index.d.ts.map +1 -1
- package/lib/typescript/src/web/listener/index.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/listener/listener.d.ts +1 -1
- package/lib/typescript/src/web/listener/listener.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/mock.d.ts +2 -2
- package/lib/typescript/src/web/mock.d.ts.map +1 -0
- package/lib/typescript/src/web/mq.d.ts.map +1 -0
- package/lib/typescript/src/web/pseudo.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/registry.d.ts +1 -1
- package/lib/typescript/src/web/registry.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/runtime.d.ts +6 -6
- package/lib/typescript/src/web/runtime.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/state.d.ts +4 -4
- package/lib/typescript/src/web/state.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/utils.d.ts +5 -3
- package/lib/typescript/src/web/utils.d.ts.map +1 -0
- package/lib/typescript/src/web/variants/getVariants.d.ts +3 -0
- package/lib/typescript/src/web/variants/getVariants.d.ts.map +1 -0
- package/lib/typescript/src/web/variants/index.d.ts +3 -0
- package/lib/typescript/src/web/variants/index.d.ts.map +1 -0
- package/lib/typescript/src/web/variants/useVariants.d.ts +3 -0
- package/lib/typescript/src/web/variants/useVariants.d.ts.map +1 -0
- package/package.json +2 -2
- package/plugin/__tests__/dependencies.spec.js +195 -107
- package/plugin/__tests__/ref.spec.js +537 -179
- package/plugin/__tests__/stylesheet.spec.js +174 -63
- package/plugin/index.js +68 -23
- package/plugin/ref.js +74 -12
- package/plugin/style.js +57 -24
- package/plugin/stylesheet.js +44 -1
- package/plugin/variants.js +33 -0
- package/src/specs/NavigtionBar/index.ts +1 -1
- package/src/specs/ShadowRegistry/index.ts +5 -5
- package/src/specs/StatusBar/index.ts +1 -1
- package/src/specs/StyleSheet/index.ts +3 -1
- package/src/specs/UnistylesRuntime/index.ts +1 -1
- package/src/specs/index.web.ts +1 -1
- package/src/types/stylesheet.ts +1 -1
- package/{web → src/web}/convert/breakpoint.ts +1 -1
- package/{web → src/web}/convert/index.ts +1 -1
- package/{web → src/web}/convert/types.ts +1 -1
- package/{web → src/web}/create.ts +36 -33
- package/{web → src/web}/listener/listener.ts +1 -1
- package/{web → src/web}/mock.ts +2 -2
- package/{web → src/web}/registry.ts +1 -1
- package/{web → src/web}/runtime.ts +4 -4
- package/{web → src/web}/state.ts +5 -5
- package/{web → src/web}/utils.ts +5 -5
- package/src/web/variants/getVariants.ts +42 -0
- package/src/web/variants/index.ts +2 -0
- package/{web → src/web/variants}/useVariants.ts +24 -44
- package/lib/typescript/web/convert/boxShadow.d.ts.map +0 -1
- package/lib/typescript/web/convert/breakpoint.d.ts.map +0 -1
- package/lib/typescript/web/convert/index.d.ts.map +0 -1
- package/lib/typescript/web/convert/shadow.d.ts.map +0 -1
- package/lib/typescript/web/convert/style.d.ts.map +0 -1
- package/lib/typescript/web/convert/textShadow.d.ts.map +0 -1
- package/lib/typescript/web/convert/transform.d.ts.map +0 -1
- package/lib/typescript/web/convert/types.d.ts.map +0 -1
- package/lib/typescript/web/convert/utils.d.ts.map +0 -1
- package/lib/typescript/web/listener/index.d.ts.map +0 -1
- package/lib/typescript/web/listener/listener.d.ts.map +0 -1
- package/lib/typescript/web/mock.d.ts.map +0 -1
- package/lib/typescript/web/mq.d.ts.map +0 -1
- package/lib/typescript/web/pseudo.d.ts.map +0 -1
- package/lib/typescript/web/registry.d.ts.map +0 -1
- package/lib/typescript/web/runtime.d.ts.map +0 -1
- package/lib/typescript/web/state.d.ts.map +0 -1
- package/lib/typescript/web/useVariants.d.ts +0 -3
- package/lib/typescript/web/useVariants.d.ts.map +0 -1
- package/lib/typescript/web/utils.d.ts.map +0 -1
- /package/lib/typescript/{web → src/web}/convert/boxShadow.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/breakpoint.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/shadow.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/style.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/textShadow.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/transform.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/utils.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/listener/index.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/mq.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/pseudo.d.ts +0 -0
- /package/{web → src/web}/convert/boxShadow.ts +0 -0
- /package/{web → src/web}/convert/module.d.ts +0 -0
- /package/{web → src/web}/convert/shadow.ts +0 -0
- /package/{web → src/web}/convert/style.ts +0 -0
- /package/{web → src/web}/convert/textShadow.ts +0 -0
- /package/{web → src/web}/convert/transform.ts +0 -0
- /package/{web → src/web}/convert/utils.ts +0 -0
- /package/{web → src/web}/index.ts +0 -0
- /package/{web → src/web}/listener/index.ts +0 -0
- /package/{web → src/web}/mq.ts +0 -0
- /package/{web → src/web}/pseudo.ts +0 -0
@@ -58,6 +58,8 @@ struct HybridUnistylesRuntime: public HybridUnistylesRuntimeSpec {
|
|
58
58
|
UnistylesCxxMiniRuntime getMiniRuntime() override;
|
59
59
|
jsi::Value getMiniRuntimeAsValue(jsi::Runtime& rt);
|
60
60
|
jsi::Runtime& getRuntime();
|
61
|
+
void includeDependenciesForColorSchemeChange(std::vector<UnistyleDependency>& deps);
|
62
|
+
void calculateNewThemeAndDependencies(std::vector<UnistyleDependency>& deps);
|
61
63
|
|
62
64
|
private:
|
63
65
|
jsi::Runtime* _rt;
|
package/cxx/parser/Parser.cpp
CHANGED
@@ -11,7 +11,7 @@ void parser::Parser::buildUnistyles(jsi::Runtime& rt, std::shared_ptr<StyleSheet
|
|
11
11
|
jsi::Object unwrappedStyleSheet = this->unwrapStyleSheet(rt, styleSheet);
|
12
12
|
|
13
13
|
helpers::enumerateJSIObject(rt, unwrappedStyleSheet, [&](const std::string& styleKey, jsi::Value& propertyValue){
|
14
|
-
helpers::assertThat(rt, propertyValue.isObject(), "
|
14
|
+
helpers::assertThat(rt, propertyValue.isObject(), "Unistyles: Style with name '" + styleKey + "' is not a function or object.");
|
15
15
|
|
16
16
|
jsi::Object styleValue = propertyValue.asObject(rt);
|
17
17
|
|
@@ -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
|
}
|
@@ -68,14 +70,14 @@ jsi::Object parser::Parser::unwrapStyleSheet(jsi::Runtime& rt, std::shared_ptr<S
|
|
68
70
|
void parser::Parser::parseUnistyles(jsi::Runtime& rt, std::shared_ptr<StyleSheet> styleSheet) {
|
69
71
|
for (const auto& [_, unistyle] : styleSheet->unistyles) {
|
70
72
|
if (unistyle->type == core::UnistyleType::Object) {
|
71
|
-
auto result = this->parseFirstLevel(rt, unistyle,
|
73
|
+
auto result = this->parseFirstLevel(rt, unistyle, std::nullopt);
|
72
74
|
|
73
75
|
unistyle->parsedStyle = std::move(result);
|
74
76
|
unistyle->seal();
|
75
77
|
}
|
76
78
|
|
77
79
|
if (unistyle->type == core::UnistyleType::DynamicFunction) {
|
78
|
-
auto hostFn = this->createDynamicFunctionProxy(rt, unistyle
|
80
|
+
auto hostFn = this->createDynamicFunctionProxy(rt, unistyle);
|
79
81
|
auto unistyleFn = std::dynamic_pointer_cast<UnistyleDynamicFunction>(unistyle);
|
80
82
|
|
81
83
|
// defer parsing dynamic functions
|
@@ -85,57 +87,60 @@ void parser::Parser::parseUnistyles(jsi::Runtime& rt, std::shared_ptr<StyleSheet
|
|
85
87
|
}
|
86
88
|
|
87
89
|
// rebuild all unistyles in StyleSheet that depends on variants
|
88
|
-
void parser::Parser::rebuildUnistylesWithVariants(jsi::Runtime& rt, std::shared_ptr<StyleSheet> styleSheet) {
|
90
|
+
void parser::Parser::rebuildUnistylesWithVariants(jsi::Runtime& rt, std::shared_ptr<StyleSheet> styleSheet, Variants& variants) {
|
89
91
|
for (const auto& [_, unistyle] : styleSheet->unistyles) {
|
90
92
|
if (!unistyle->dependsOn(UnistyleDependency::VARIANTS)) {
|
91
93
|
continue;
|
92
94
|
}
|
93
95
|
|
94
|
-
|
96
|
+
// todo skip dynamic functions
|
97
|
+
this->rebuildUnistyle(rt, styleSheet, unistyle, variants, std::nullopt);
|
95
98
|
}
|
96
99
|
}
|
97
100
|
|
98
101
|
// rebuild all unistyles that are affected by platform event
|
99
102
|
void parser::Parser::rebuildUnistylesInDependencyMap(jsi::Runtime& rt, DependencyMap& dependencyMap) {
|
100
|
-
for (
|
103
|
+
for (auto& [shadowNode, unistyles] : dependencyMap) {
|
104
|
+
auto styleSheet = unistyles.begin()->get()->unistyle->parent;
|
105
|
+
|
101
106
|
jsi::Object unwrappedStyleSheet = this->unwrapStyleSheet(rt, styleSheet);
|
102
107
|
|
103
|
-
for (
|
104
|
-
|
105
|
-
// StyleSheet might have styles that are not affected
|
106
|
-
if (!unwrappedStyleSheet.hasProperty(rt, unistyle->styleKey.c_str())) {
|
107
|
-
continue;
|
108
|
-
}
|
108
|
+
for (auto& unistyleData : unistyles) {
|
109
|
+
auto& unistyle = unistyleData->unistyle;
|
109
110
|
|
110
|
-
|
111
|
-
|
111
|
+
// StyleSheet might have styles that are not affected
|
112
|
+
if (!unwrappedStyleSheet.hasProperty(rt, unistyle->styleKey.c_str())) {
|
113
|
+
continue;
|
112
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);
|
113
119
|
}
|
114
120
|
}
|
115
121
|
}
|
116
122
|
|
117
123
|
// rebuild single unistyle
|
118
|
-
void parser::Parser::rebuildUnistyle(jsi::Runtime& rt, std::shared_ptr<StyleSheet> styleSheet, Unistyle::Shared unistyle) {
|
124
|
+
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) {
|
119
125
|
if (unistyle->type == core::UnistyleType::Object) {
|
120
|
-
auto result = this->parseFirstLevel(rt, unistyle,
|
126
|
+
auto result = this->parseFirstLevel(rt, unistyle, variants);
|
121
127
|
|
122
128
|
unistyle->parsedStyle = std::move(result);
|
123
129
|
}
|
124
130
|
|
125
131
|
// for functions we need to call memoized function
|
126
132
|
// with last know arguments and parse it with new theme and mini runtime
|
127
|
-
if (unistyle->type == core::UnistyleType::DynamicFunction) {
|
133
|
+
if (unistyle->type == core::UnistyleType::DynamicFunction && metadata.has_value()) {
|
128
134
|
auto unistyleFn = std::dynamic_pointer_cast<UnistyleDynamicFunction>(unistyle);
|
129
|
-
auto maybeMetadata = unistyleFn->dynamicFunctionMetadata;
|
130
|
-
|
131
|
-
helpers::assertThat(rt, maybeMetadata.has_value(), "Your dynamic function '" + unistyleFn->styleKey + "' has no metadata and can't be processed.");
|
132
135
|
|
133
136
|
// convert arguments to jsi::Value
|
134
|
-
auto
|
137
|
+
auto dynamicFunctionMetadata = metadata.value();
|
135
138
|
std::vector<jsi::Value> args{};
|
136
139
|
|
137
|
-
|
138
|
-
|
140
|
+
args.reserve(dynamicFunctionMetadata.size());
|
141
|
+
|
142
|
+
for (int i = 0; i < dynamicFunctionMetadata.size(); i++) {
|
143
|
+
folly::dynamic& arg = dynamicFunctionMetadata.at(i);
|
139
144
|
|
140
145
|
args.emplace_back(jsi::valueFromDynamic(rt, arg));
|
141
146
|
}
|
@@ -143,94 +148,33 @@ void parser::Parser::rebuildUnistyle(jsi::Runtime& rt, std::shared_ptr<StyleShee
|
|
143
148
|
const jsi::Value *argStart = args.data();
|
144
149
|
|
145
150
|
// call cached function with memoized arguments
|
146
|
-
auto functionResult = unistyleFn->
|
151
|
+
auto functionResult = unistyleFn->rawValue
|
152
|
+
.asFunction(rt)
|
153
|
+
.call(rt, argStart, dynamicFunctionMetadata.size())
|
154
|
+
.asObject(rt);
|
147
155
|
|
148
156
|
unistyleFn->unprocessedValue = std::move(functionResult);
|
149
|
-
unistyleFn->parsedStyle = this->parseFirstLevel(rt, unistyleFn,
|
157
|
+
unistyleFn->parsedStyle = this->parseFirstLevel(rt, unistyleFn, variants);
|
150
158
|
}
|
151
159
|
}
|
152
160
|
|
153
161
|
// convert dependency map to shadow tree updates
|
154
|
-
shadow::ShadowLeafUpdates parser::Parser::dependencyMapToShadowLeafUpdates(DependencyMap& dependencyMap) {
|
162
|
+
shadow::ShadowLeafUpdates parser::Parser::dependencyMapToShadowLeafUpdates(core::DependencyMap& dependencyMap) {
|
155
163
|
shadow::ShadowLeafUpdates updates;
|
156
164
|
auto& rt = this->_unistylesRuntime->getRuntime();
|
157
|
-
|
158
|
-
for (const auto& [
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
if (updates.contains(shadowNode)) {
|
164
|
-
updates[shadowNode].emplace_back(std::move(rawProps));
|
165
|
-
|
166
|
-
continue;
|
167
|
-
}
|
168
|
-
|
169
|
-
updates.emplace(shadowNode, std::vector<RawProps>{std::move(rawProps)});
|
170
|
-
}
|
171
|
-
}
|
165
|
+
|
166
|
+
for (const auto& [shadowNode, unistyles] : dependencyMap) {
|
167
|
+
auto rawProps = this->parseStylesToShadowTreeStyles(rt, unistyles);
|
168
|
+
|
169
|
+
updates.emplace(shadowNode, std::move(rawProps));
|
172
170
|
}
|
173
171
|
|
174
172
|
return updates;
|
175
173
|
}
|
176
174
|
|
177
|
-
// convert jsi::Value arguments to folly::dynamic
|
178
|
-
std::vector<folly::dynamic> parser::Parser::parseDynamicFunctionArguments(jsi::Runtime& rt, size_t count, const jsi::Value* arguments) {
|
179
|
-
std::vector<folly::dynamic> parsedArgument{};
|
180
|
-
|
181
|
-
for (size_t i = 0; i < count; i++) {
|
182
|
-
auto& arg = arguments[i];
|
183
|
-
|
184
|
-
if (arg.isBool()) {
|
185
|
-
parsedArgument.push_back(folly::dynamic(arg.asBool()));
|
186
|
-
|
187
|
-
continue;
|
188
|
-
}
|
189
|
-
|
190
|
-
if (arg.isNumber()) {
|
191
|
-
parsedArgument.push_back(folly::dynamic(arg.asNumber()));
|
192
|
-
|
193
|
-
continue;
|
194
|
-
}
|
195
|
-
|
196
|
-
if (arg.isString()) {
|
197
|
-
parsedArgument.push_back(folly::dynamic(arg.asString(rt).utf8(rt)));
|
198
|
-
|
199
|
-
continue;
|
200
|
-
}
|
201
|
-
|
202
|
-
if (arg.isUndefined()) {
|
203
|
-
parsedArgument.push_back(folly::dynamic());
|
204
|
-
|
205
|
-
continue;
|
206
|
-
}
|
207
|
-
|
208
|
-
if (arg.isNull()) {
|
209
|
-
parsedArgument.push_back(folly::dynamic(nullptr));
|
210
|
-
|
211
|
-
continue;
|
212
|
-
}
|
213
|
-
|
214
|
-
if (!arg.isObject()) {
|
215
|
-
continue;;
|
216
|
-
}
|
217
|
-
|
218
|
-
auto argObj = arg.asObject(rt);
|
219
|
-
|
220
|
-
// allow arrays and objects too
|
221
|
-
if (!argObj.isFunction(rt) && !argObj.isArrayBuffer(rt)) {
|
222
|
-
parsedArgument.push_back(jsi::dynamicFromValue(rt, arg));
|
223
|
-
|
224
|
-
continue;
|
225
|
-
}
|
226
|
-
}
|
227
|
-
|
228
|
-
return parsedArgument;
|
229
|
-
}
|
230
|
-
|
231
175
|
// first level of StyleSheet, we can expect here different properties than on second level
|
232
176
|
// eg. variants, compoundVariants, mq, breakpoints etc.
|
233
|
-
jsi::Object parser::Parser::parseFirstLevel(jsi::Runtime& rt, Unistyle::Shared unistyle, Variants
|
177
|
+
jsi::Object parser::Parser::parseFirstLevel(jsi::Runtime& rt, Unistyle::Shared unistyle, std::optional<Variants> variants) {
|
234
178
|
// for objects - we simply operate on them
|
235
179
|
// for functions we need to work on the unprocessed result (object)
|
236
180
|
auto& style = unistyle->type == core::UnistyleType::Object
|
@@ -312,20 +256,16 @@ jsi::Object parser::Parser::parseFirstLevel(jsi::Runtime& rt, Unistyle::Shared u
|
|
312
256
|
|
313
257
|
parsedStyle.setProperty(rt, jsi::PropNameID::forUtf8(rt, propertyName), this->parseSecondLevel(rt, unistyle, valueFromBreakpoint));
|
314
258
|
});
|
315
|
-
|
316
|
-
if (shouldParseVariants) {
|
317
|
-
unistyle->addDependency(UnistyleDependency::VARIANTS);
|
318
|
-
}
|
319
259
|
|
320
|
-
if (shouldParseVariants && !variants.empty()) {
|
260
|
+
if (shouldParseVariants && variants.has_value() && !variants.value().empty()) {
|
321
261
|
auto propertyValueObject = style.getProperty(rt, "variants").asObject(rt);
|
322
|
-
auto parsedVariant = this->parseVariants(rt, unistyle, propertyValueObject, variants);
|
262
|
+
auto parsedVariant = this->parseVariants(rt, unistyle, propertyValueObject, variants.value());
|
323
263
|
|
324
264
|
helpers::mergeJSIObjects(rt, parsedStyle, parsedVariant);
|
325
265
|
|
326
266
|
if (shouldParseCompoundVariants) {
|
327
267
|
auto compoundVariants = style.getProperty(rt, "compoundVariants").asObject(rt);
|
328
|
-
auto parsedCompoundVariants = this->parseCompoundVariants(rt, unistyle, compoundVariants, variants);
|
268
|
+
auto parsedCompoundVariants = this->parseCompoundVariants(rt, unistyle, compoundVariants, variants.value());
|
329
269
|
|
330
270
|
helpers::mergeJSIObjects(rt, parsedStyle, parsedCompoundVariants);
|
331
271
|
}
|
@@ -335,29 +275,32 @@ jsi::Object parser::Parser::parseFirstLevel(jsi::Runtime& rt, Unistyle::Shared u
|
|
335
275
|
}
|
336
276
|
|
337
277
|
// function replaces original user dynamic function with additional logic to memoize arguments
|
338
|
-
jsi::Function parser::Parser::createDynamicFunctionProxy(jsi::Runtime& rt, Unistyle::Shared unistyle
|
278
|
+
jsi::Function parser::Parser::createDynamicFunctionProxy(jsi::Runtime& rt, Unistyle::Shared unistyle) {
|
339
279
|
auto unistylesRuntime = this->_unistylesRuntime;
|
340
280
|
|
341
281
|
return jsi::Function::createFromHostFunction(
|
342
282
|
rt,
|
343
283
|
jsi::PropNameID::forUtf8(rt, unistyle->styleKey),
|
344
284
|
1,
|
345
|
-
[this, unistylesRuntime, unistyle
|
285
|
+
[this, unistylesRuntime, unistyle](jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
|
346
286
|
auto thisObject = thisVal.asObject(rt);
|
347
287
|
auto parser = parser::Parser(unistylesRuntime);
|
348
|
-
|
288
|
+
|
349
289
|
// call user function
|
350
290
|
auto result = unistyle->rawValue.asFunction(rt).call(rt, args, count);
|
351
291
|
|
352
292
|
// memoize metadata to call it later
|
353
293
|
auto unistyleFn = std::dynamic_pointer_cast<UnistyleDynamicFunction>(unistyle);
|
354
294
|
|
355
|
-
unistyleFn->dynamicFunctionMetadata = core::DynamicFunctionMetadata{
|
356
|
-
count,
|
357
|
-
this->parseDynamicFunctionArguments(rt, count, args)
|
358
|
-
};
|
359
|
-
|
360
295
|
unistyleFn->unprocessedValue = jsi::Value(rt, result).asObject(rt);
|
296
|
+
|
297
|
+
jsi::Value rawVariants = thisObject.hasProperty(rt, helpers::STYLE_VARIANTS.c_str())
|
298
|
+
? thisObject.getProperty(rt, helpers::STYLE_VARIANTS.c_str())
|
299
|
+
: jsi::Value::undefined();
|
300
|
+
std::optional<Variants> variants = rawVariants.isUndefined()
|
301
|
+
? std::nullopt
|
302
|
+
: std::optional<Variants>(helpers::variantsToPairs(rt, rawVariants.asObject(rt)));
|
303
|
+
|
361
304
|
unistyleFn->parsedStyle = this->parseFirstLevel(rt, unistyleFn, variants);
|
362
305
|
unistyleFn->seal();
|
363
306
|
|
@@ -367,9 +310,11 @@ jsi::Function parser::Parser::createDynamicFunctionProxy(jsi::Runtime& rt, Unist
|
|
367
310
|
|
368
311
|
// function convert babel generated dependencies to C++ dependencies
|
369
312
|
std::vector<UnistyleDependency> parser::Parser::parseDependencies(jsi::Runtime &rt, jsi::Object&& dependencies) {
|
370
|
-
helpers::assertThat(rt, dependencies.isArray(rt), "
|
313
|
+
helpers::assertThat(rt, dependencies.isArray(rt), "Unistyles: Babel transform is invalid - unexpected type for dependencies.");
|
371
314
|
|
372
|
-
std::vector<UnistyleDependency> parsedDependencies;
|
315
|
+
std::vector<UnistyleDependency> parsedDependencies{};
|
316
|
+
|
317
|
+
parsedDependencies.reserve(5);
|
373
318
|
|
374
319
|
helpers::iterateJSIArray(rt, dependencies.asArray(rt), [&](size_t i, jsi::Value& value){
|
375
320
|
auto dependency = static_cast<UnistyleDependency>(value.asNumber());
|
@@ -388,6 +333,8 @@ jsi::Value parser::Parser::parseTransforms(jsi::Runtime& rt, Unistyle::Shared un
|
|
388
333
|
|
389
334
|
std::vector<jsi::Value> parsedTransforms{};
|
390
335
|
|
336
|
+
parsedTransforms.reserve(2);
|
337
|
+
|
391
338
|
helpers::iterateJSIArray(rt, obj.asArray(rt), [&](size_t i, jsi::Value& value){
|
392
339
|
if (!value.isObject()) {
|
393
340
|
return;
|
@@ -434,7 +381,7 @@ jsi::Value parser::Parser::getValueFromBreakpoints(jsi::Runtime& rt, Unistyle::S
|
|
434
381
|
auto propertyName = propertyNames.getValueAtIndex(rt, i).asString(rt).utf8(rt);
|
435
382
|
auto propertyValue = obj.getProperty(rt, propertyName.c_str());
|
436
383
|
auto mq = core::UnistylesMQ{propertyName};
|
437
|
-
|
384
|
+
|
438
385
|
if (mq.isMQ()) {
|
439
386
|
unistyle->addDependency(UnistyleDependency::BREAKPOINTS);
|
440
387
|
}
|
@@ -447,11 +394,11 @@ jsi::Value parser::Parser::getValueFromBreakpoints(jsi::Runtime& rt, Unistyle::S
|
|
447
394
|
|
448
395
|
// check orientation breakpoints if user didn't register own breakpoint
|
449
396
|
bool hasOrientationBreakpoint = obj.hasProperty(rt, currentOrientation);
|
450
|
-
|
397
|
+
|
451
398
|
if (hasOrientationBreakpoint) {
|
452
399
|
unistyle->addDependency(UnistyleDependency::BREAKPOINTS);
|
453
400
|
}
|
454
|
-
|
401
|
+
|
455
402
|
if (!hasBreakpoints && hasOrientationBreakpoint) {
|
456
403
|
return obj.getProperty(rt, currentOrientation);
|
457
404
|
}
|
@@ -459,7 +406,7 @@ jsi::Value parser::Parser::getValueFromBreakpoints(jsi::Runtime& rt, Unistyle::S
|
|
459
406
|
if (!currentBreakpoint.has_value()) {
|
460
407
|
return jsi::Value::undefined();
|
461
408
|
}
|
462
|
-
|
409
|
+
|
463
410
|
unistyle->addDependency(UnistyleDependency::BREAKPOINTS);
|
464
411
|
|
465
412
|
// if you're still here it means that there is no
|
@@ -505,7 +452,7 @@ jsi::Object parser::Parser::parseVariants(jsi::Runtime& rt, Unistyle::Shared uni
|
|
505
452
|
: std::nullopt;
|
506
453
|
|
507
454
|
// we've got a match, but we need to check some condition
|
508
|
-
auto styles = this->getStylesForVariant(rt, groupValue.asObject(rt), selectedVariant);
|
455
|
+
auto styles = this->getStylesForVariant(rt, groupName, groupValue.asObject(rt), selectedVariant, variants);
|
509
456
|
|
510
457
|
// oops, invalid variant
|
511
458
|
if (styles.isUndefined() || !styles.isObject()) {
|
@@ -521,13 +468,19 @@ jsi::Object parser::Parser::parseVariants(jsi::Runtime& rt, Unistyle::Shared uni
|
|
521
468
|
}
|
522
469
|
|
523
470
|
// helpers function to support 'default' variants
|
524
|
-
jsi::Value parser::Parser::getStylesForVariant(jsi::Runtime& rt, jsi::Object&& groupValue, std::optional<std::string> selectedVariant) {
|
471
|
+
jsi::Value parser::Parser::getStylesForVariant(jsi::Runtime& rt, const std::string groupName, jsi::Object&& groupValue, std::optional<std::string> selectedVariant, Variants& variants) {
|
525
472
|
// if there is no value, let's try 'default'
|
526
473
|
auto selectedVariantKey = selectedVariant.has_value()
|
527
474
|
? selectedVariant.value().c_str()
|
528
475
|
: "default";
|
476
|
+
auto hasKey = groupValue.hasProperty(rt, selectedVariantKey);
|
477
|
+
|
478
|
+
if (hasKey && !selectedVariant.has_value()) {
|
479
|
+
// add 'default' selection to variants map
|
480
|
+
variants.emplace_back(groupName, selectedVariantKey);
|
481
|
+
}
|
529
482
|
|
530
|
-
if (
|
483
|
+
if (hasKey) {
|
531
484
|
return groupValue.getProperty(rt, selectedVariantKey);
|
532
485
|
}
|
533
486
|
|
@@ -567,22 +520,12 @@ bool parser::Parser::shouldApplyCompoundVariants(jsi::Runtime& rt, const Variant
|
|
567
520
|
return false;
|
568
521
|
}
|
569
522
|
|
570
|
-
jsi::Array propertyNames = compoundVariant.getPropertyNames(rt);
|
571
|
-
size_t length = propertyNames.size(rt);
|
572
|
-
size_t allConditions = compoundVariant.hasProperty(rt, "styles")
|
573
|
-
? length - 1
|
574
|
-
: length;
|
575
|
-
|
576
|
-
if (allConditions != variants.size()) {
|
577
|
-
return false;
|
578
|
-
}
|
579
|
-
|
580
523
|
for (auto it = variants.cbegin(); it != variants.cend(); ++it) {
|
581
524
|
auto variantKey = it->first;
|
582
525
|
auto variantValue = it->second;
|
583
526
|
|
584
527
|
if (!compoundVariant.hasProperty(rt, variantKey.c_str())) {
|
585
|
-
|
528
|
+
continue;
|
586
529
|
}
|
587
530
|
|
588
531
|
auto property = compoundVariant.getProperty(rt, variantKey.c_str());
|
@@ -666,41 +609,20 @@ jsi::Value parser::Parser::parseSecondLevel(jsi::Runtime &rt, Unistyle::Shared u
|
|
666
609
|
return parsedStyle;
|
667
610
|
}
|
668
611
|
|
669
|
-
//
|
670
|
-
|
671
|
-
Variants pairs{};
|
672
|
-
|
673
|
-
helpers::enumerateJSIObject(rt, variants, [&](const std::string& variantName, jsi::Value& variantValue){
|
674
|
-
if (variantValue.isUndefined() || variantValue.isNull()) {
|
675
|
-
return;
|
676
|
-
}
|
677
|
-
|
678
|
-
if (variantValue.isBool()) {
|
679
|
-
pairs.emplace_back(std::make_pair(variantName, variantValue.asBool() ? "true" : "false"));
|
680
|
-
|
681
|
-
return;
|
682
|
-
}
|
683
|
-
|
684
|
-
if (variantValue.isString()) {
|
685
|
-
pairs.emplace_back(std::make_pair(variantName, variantValue.asString(rt).utf8(rt)));
|
686
|
-
}
|
687
|
-
});
|
688
|
-
|
689
|
-
return pairs;
|
690
|
-
}
|
691
|
-
|
692
|
-
// convert jsi::Object to RawValue with int colors
|
693
|
-
RawProps parser::Parser::parseStylesToShadowTreeStyles(jsi::Runtime& rt, 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) {
|
694
614
|
jsi::Object convertedStyles = jsi::Object(rt);
|
695
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
|
+
}
|
696
622
|
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
}
|
701
|
-
|
702
|
-
convertedStyles.setProperty(rt, propertyName.c_str(), propertyValue);
|
703
|
-
});
|
623
|
+
convertedStyles.setProperty(rt, propertyName.c_str(), propertyValue);
|
624
|
+
});
|
625
|
+
}
|
704
626
|
|
705
627
|
return RawProps(rt, std::move(convertedStyles));
|
706
628
|
}
|
package/cxx/parser/Parser.h
CHANGED
@@ -17,36 +17,30 @@ using namespace facebook;
|
|
17
17
|
using namespace margelo::nitro::unistyles::core;
|
18
18
|
|
19
19
|
using Variants = std::vector<std::pair<std::string, std::string>>;
|
20
|
-
using DependencyMap = std::unordered_map<
|
21
|
-
std::shared_ptr<core::StyleSheet>,
|
22
|
-
std::unordered_map<const ShadowNodeFamily*, std::vector<core::Unistyle::Shared>>
|
23
|
-
>;
|
24
20
|
|
25
21
|
struct Parser {
|
26
22
|
Parser(std::shared_ptr<HybridUnistylesRuntime> unistylesRuntime): _unistylesRuntime{unistylesRuntime} {}
|
27
23
|
|
28
24
|
void buildUnistyles(jsi::Runtime& rt, std::shared_ptr<StyleSheet> styleSheet);
|
29
25
|
void parseUnistyles(jsi::Runtime& rt, std::shared_ptr<StyleSheet> styleSheet);
|
30
|
-
|
31
|
-
void
|
32
|
-
|
33
|
-
shadow::ShadowLeafUpdates dependencyMapToShadowLeafUpdates(DependencyMap& dependencyMap);
|
26
|
+
void rebuildUnistylesWithVariants(jsi::Runtime& rt, std::shared_ptr<StyleSheet> styleSheet, Variants& variants);
|
27
|
+
void rebuildUnistylesInDependencyMap(jsi::Runtime& rt, core::DependencyMap& dependencyMap);
|
28
|
+
shadow::ShadowLeafUpdates dependencyMapToShadowLeafUpdates(core::DependencyMap& dependencyMap);
|
34
29
|
|
35
30
|
private:
|
36
|
-
void rebuildUnistyle(jsi::Runtime& rt, std::shared_ptr<StyleSheet> styleSheet, Unistyle::Shared unistyle);
|
31
|
+
void rebuildUnistyle(jsi::Runtime& rt, std::shared_ptr<StyleSheet> styleSheet, Unistyle::Shared unistyle, const Variants& variants, std::optional<std::vector<folly::dynamic>>);
|
37
32
|
jsi::Object unwrapStyleSheet(jsi::Runtime& rt, std::shared_ptr<StyleSheet> styleSheet);
|
38
|
-
jsi::Object parseFirstLevel(jsi::Runtime& rt, Unistyle::Shared unistyle, Variants
|
33
|
+
jsi::Object parseFirstLevel(jsi::Runtime& rt, Unistyle::Shared unistyle, std::optional<Variants> variants);
|
39
34
|
jsi::Value parseSecondLevel(jsi::Runtime& rt, Unistyle::Shared unistyle, jsi::Value& nestedObject);
|
40
|
-
jsi::Function createDynamicFunctionProxy(jsi::Runtime& rt, Unistyle::Shared unistyle
|
41
|
-
std::vector<folly::dynamic> parseDynamicFunctionArguments(jsi::Runtime& rt, size_t count, const jsi::Value* arguments);
|
35
|
+
jsi::Function createDynamicFunctionProxy(jsi::Runtime& rt, Unistyle::Shared unistyle);
|
42
36
|
std::vector<UnistyleDependency> parseDependencies(jsi::Runtime &rt, jsi::Object&& dependencies);
|
43
37
|
jsi::Value parseTransforms(jsi::Runtime& rt, Unistyle::Shared unistyle, jsi::Object& obj);
|
44
38
|
jsi::Value getValueFromBreakpoints(jsi::Runtime& rt, Unistyle::Shared unistyle, jsi::Object& obj);
|
45
39
|
jsi::Object parseVariants(jsi::Runtime& rt, Unistyle::Shared unistyle, jsi::Object& obj, Variants& variants);
|
46
|
-
jsi::Value getStylesForVariant(jsi::Runtime& rt, jsi::Object&& groupValue, std::optional<std::string> selectedVariant);
|
40
|
+
jsi::Value getStylesForVariant(jsi::Runtime& rt, const std::string groupName, jsi::Object&& groupValue, std::optional<std::string> selectedVariant, Variants& variants);
|
47
41
|
jsi::Object parseCompoundVariants(jsi::Runtime& rt, Unistyle::Shared unistyle, jsi::Object& obj, Variants& variants);
|
48
42
|
bool shouldApplyCompoundVariants(jsi::Runtime& rt, const Variants& variants, jsi::Object& compoundVariant);
|
49
|
-
RawProps parseStylesToShadowTreeStyles(jsi::Runtime& rt,
|
43
|
+
RawProps parseStylesToShadowTreeStyles(jsi::Runtime& rt, const std::vector<std::shared_ptr<UnistyleData>>& unistyles);
|
50
44
|
bool isColor(const std::string& propertyName);
|
51
45
|
|
52
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*,
|
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
|
110
|
-
|
111
|
-
|
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({
|
@@ -3,6 +3,8 @@
|
|
3
3
|
#import <React/RCTEventEmitter.h>
|
4
4
|
#import <ReactCommon/RCTTurboModuleWithJSIBindings.h>
|
5
5
|
#import "TurboUnistyles/TurboUnistyles.h"
|
6
|
+
#import <React/RCTSurfacePresenter.h>
|
7
|
+
#import <React/RCTScheduler.h>
|
6
8
|
|
7
9
|
@interface UnistylesModule: RCTEventEmitter<NativeTurboUnistylesSpec>
|
8
10
|
@end
|
@@ -10,10 +10,16 @@ using namespace margelo::nitro;
|
|
10
10
|
|
11
11
|
RCT_EXPORT_MODULE(Unistyles)
|
12
12
|
|
13
|
+
__weak RCTSurfacePresenter* _surfacePresenter;
|
14
|
+
|
13
15
|
+ (BOOL)requiresMainQueueSetup {
|
14
16
|
return YES;
|
15
17
|
}
|
16
18
|
|
19
|
+
- (void)setSurfacePresenter:(id<RCTSurfacePresenterStub>)surfacePresenter {
|
20
|
+
_surfacePresenter = surfacePresenter;
|
21
|
+
}
|
22
|
+
|
17
23
|
- (void)installJSIBindingsWithRuntime:(jsi::Runtime&)rt {
|
18
24
|
// function is called on: first init and every live reload
|
19
25
|
// check if this is live reload, if so let's replace UnistylesRuntime with new runtime
|
@@ -31,7 +37,8 @@ RCT_EXPORT_MODULE(Unistyles)
|
|
31
37
|
- (void)createHybrids:(jsi::Runtime&)rt {
|
32
38
|
auto nativePlatform = Unistyles::NativePlatform::create();
|
33
39
|
auto unistylesRuntime = std::make_shared<HybridUnistylesRuntime>(nativePlatform, rt);
|
34
|
-
auto
|
40
|
+
auto uiManager = [_surfacePresenter scheduler].uiManager;
|
41
|
+
auto styleSheet = std::make_shared<HybridStyleSheet>(unistylesRuntime, uiManager);
|
35
42
|
|
36
43
|
HybridObjectRegistry::registerHybridObjectConstructor("UnistylesRuntime", [unistylesRuntime]() -> std::shared_ptr<HybridObject>{
|
37
44
|
return unistylesRuntime;
|
@@ -9,7 +9,7 @@ const attachNavigationBarJSMethods = hybridObject => {
|
|
9
9
|
const privateHybrid = hybridObject;
|
10
10
|
privateHybrid._setBackgroundColor = hybridObject.setBackgroundColor;
|
11
11
|
hybridObject.setBackgroundColor = color => {
|
12
|
-
const parsedColor = (0, _reactNative.processColor)(color);
|
12
|
+
const parsedColor = (0, _reactNative.processColor)(color) ?? 0;
|
13
13
|
privateHybrid._setBackgroundColor(parsedColor);
|
14
14
|
};
|
15
15
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_reactNative","require","attachNavigationBarJSMethods","hybridObject","privateHybrid","_setBackgroundColor","setBackgroundColor","color","parsedColor","processColor","exports"],"sourceRoot":"../../../../src","sources":["specs/NavigtionBar/index.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AASO,MAAMC,4BAA4B,GAAIC,YAAoC,IAAK;EAClF,MAAMC,aAAa,GAAGD,YAA6C;EAEnEC,aAAa,CAACC,mBAAmB,GAAGF,YAAY,CAACG,kBAAkB;EACnEH,YAAY,CAACG,kBAAkB,GAAIC,KAAc,IAAK;IAClD,MAAMC,WAAW,GAAG,IAAAC,yBAAY,EAACF,KAAK,CAAC;
|
1
|
+
{"version":3,"names":["_reactNative","require","attachNavigationBarJSMethods","hybridObject","privateHybrid","_setBackgroundColor","setBackgroundColor","color","parsedColor","processColor","exports"],"sourceRoot":"../../../../src","sources":["specs/NavigtionBar/index.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AASO,MAAMC,4BAA4B,GAAIC,YAAoC,IAAK;EAClF,MAAMC,aAAa,GAAGD,YAA6C;EAEnEC,aAAa,CAACC,mBAAmB,GAAGF,YAAY,CAACG,kBAAkB;EACnEH,YAAY,CAACG,kBAAkB,GAAIC,KAAc,IAAK;IAClD,MAAMC,WAAW,GAAG,IAAAC,yBAAY,EAACF,KAAK,CAAC,IAAI,CAAC;IAE5CH,aAAa,CAACC,mBAAmB,CAACG,WAAqB,CAAC;EAC5D,CAAC;AACL,CAAC;AAAAE,OAAA,CAAAR,4BAAA,GAAAA,4BAAA","ignoreList":[]}
|
@@ -14,11 +14,11 @@ const findShadowNodeForHandle = handle => {
|
|
14
14
|
}
|
15
15
|
return node;
|
16
16
|
};
|
17
|
-
HybridShadowRegistry.add = (handle, style) => {
|
18
|
-
if (!handle
|
17
|
+
HybridShadowRegistry.add = (handle, style, variants, args) => {
|
18
|
+
if (!handle) {
|
19
19
|
return;
|
20
20
|
}
|
21
|
-
HybridShadowRegistry.link(findShadowNodeForHandle(handle), style);
|
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","
|
1
|
+
{"version":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":[]}
|
@@ -25,7 +25,7 @@ const attachStatusBarJSMethods = hybridObject => {
|
|
25
25
|
};
|
26
26
|
privateHybrid._setBackgroundColor = hybridObject.setBackgroundColor;
|
27
27
|
hybridObject.setBackgroundColor = color => {
|
28
|
-
const parsedColor = (0, _reactNative.processColor)(color);
|
28
|
+
const parsedColor = (0, _reactNative.processColor)(color) ?? 0;
|
29
29
|
privateHybrid._setBackgroundColor(parsedColor);
|
30
30
|
};
|
31
31
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_types","attachStatusBarJSMethods","hybridObject","setStyle","style","animated","StatusBarStyle","Light","NativeStatusBar","setBarStyle","Dark","Default","privateHybrid","_setHidden","setHidden","isHidden","animation","_setBackgroundColor","setBackgroundColor","color","parsedColor","processColor","exports"],"sourceRoot":"../../../../src","sources":["specs/StatusBar/index.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAYO,MAAME,wBAAwB,GAAIC,YAAgC,IAAK;EAC1EA,YAAY,CAACC,QAAQ,GAAG,CAACC,KAAqB,EAAEC,QAAkB,KAAK;IACnE,QAAQD,KAAK;MACT,KAAKE,qBAAc,CAACC,KAAK;QACrB,OAAOC,sBAAe,CAACC,WAAW,CAAC,eAAe,EAAEJ,QAAQ,CAAC;MACjE,KAAKC,qBAAc,CAACI,IAAI;QACpB,OAAOF,sBAAe,CAACC,WAAW,CAAC,cAAc,EAAEJ,QAAQ,CAAC;MAChE,KAAKC,qBAAc,CAACK,OAAO;QACvB,OAAOH,sBAAe,CAACC,WAAW,CAAC,SAAS,EAAEJ,QAAQ,CAAC;IAC/D;EACJ,CAAC;EAED,MAAMO,aAAa,GAAGV,YAAyC;EAE/DU,aAAa,CAACC,UAAU,GAAGX,YAAY,CAACY,SAAS;EACjDZ,YAAY,CAACY,SAAS,GAAG,CAACC,QAAiB,EAAEC,SAAoC,KAAK;IAClFR,sBAAe,CAACM,SAAS,CAACC,QAAQ,EAAEC,SAAS,CAAC;IAC9CJ,aAAa,CAACC,UAAU,CAACE,QAAQ,CAAC;EACtC,CAAC;EAEDH,aAAa,CAACK,mBAAmB,GAAGf,YAAY,CAACgB,kBAAkB;EACnEhB,YAAY,CAACgB,kBAAkB,GAAIC,KAAc,IAAK;IAClD,MAAMC,WAAW,GAAG,IAAAC,yBAAY,EAACF,KAAK,CAAC;
|
1
|
+
{"version":3,"names":["_reactNative","require","_types","attachStatusBarJSMethods","hybridObject","setStyle","style","animated","StatusBarStyle","Light","NativeStatusBar","setBarStyle","Dark","Default","privateHybrid","_setHidden","setHidden","isHidden","animation","_setBackgroundColor","setBackgroundColor","color","parsedColor","processColor","exports"],"sourceRoot":"../../../../src","sources":["specs/StatusBar/index.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAYO,MAAME,wBAAwB,GAAIC,YAAgC,IAAK;EAC1EA,YAAY,CAACC,QAAQ,GAAG,CAACC,KAAqB,EAAEC,QAAkB,KAAK;IACnE,QAAQD,KAAK;MACT,KAAKE,qBAAc,CAACC,KAAK;QACrB,OAAOC,sBAAe,CAACC,WAAW,CAAC,eAAe,EAAEJ,QAAQ,CAAC;MACjE,KAAKC,qBAAc,CAACI,IAAI;QACpB,OAAOF,sBAAe,CAACC,WAAW,CAAC,cAAc,EAAEJ,QAAQ,CAAC;MAChE,KAAKC,qBAAc,CAACK,OAAO;QACvB,OAAOH,sBAAe,CAACC,WAAW,CAAC,SAAS,EAAEJ,QAAQ,CAAC;IAC/D;EACJ,CAAC;EAED,MAAMO,aAAa,GAAGV,YAAyC;EAE/DU,aAAa,CAACC,UAAU,GAAGX,YAAY,CAACY,SAAS;EACjDZ,YAAY,CAACY,SAAS,GAAG,CAACC,QAAiB,EAAEC,SAAoC,KAAK;IAClFR,sBAAe,CAACM,SAAS,CAACC,QAAQ,EAAEC,SAAS,CAAC;IAC9CJ,aAAa,CAACC,UAAU,CAACE,QAAQ,CAAC;EACtC,CAAC;EAEDH,aAAa,CAACK,mBAAmB,GAAGf,YAAY,CAACgB,kBAAkB;EACnEhB,YAAY,CAACgB,kBAAkB,GAAIC,KAAc,IAAK;IAClD,MAAMC,WAAW,GAAG,IAAAC,yBAAY,EAACF,KAAK,CAAC,IAAI,CAAC;IAE5CP,aAAa,CAACK,mBAAmB,CAACG,WAAqB,CAAC;EAC5D,CAAC;AACL,CAAC;AAAAE,OAAA,CAAArB,wBAAA,GAAAA,wBAAA","ignoreList":[]}
|