react-native-unistyles 3.0.0-alpha.1 → 3.0.0-alpha.10
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 +0 -6
- package/cxx/core/UnistyleData.h +23 -0
- package/cxx/core/UnistyleWrapper.h +6 -6
- 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 +42 -56
- package/cxx/core/UnistylesRegistry.h +10 -8
- package/cxx/core/UnistylesState.cpp +4 -4
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +8 -1
- 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 +65 -137
- package/cxx/parser/Parser.h +8 -14
- 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 +2 -2
- 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 +2 -2
- 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 +181 -103
- package/plugin/__tests__/ref.spec.js +335 -156
- package/plugin/__tests__/stylesheet.spec.js +148 -55
- package/plugin/index.js +31 -21
- package/plugin/ref.js +43 -11
- package/plugin/style.js +13 -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 +4 -4
- 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
@@ -0,0 +1,33 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
4
|
+
|
5
|
+
Pod::Spec.new do |s|
|
6
|
+
s.name = "Unistyles"
|
7
|
+
s.version = package["version"]
|
8
|
+
s.summary = package["description"]
|
9
|
+
s.homepage = package["homepage"]
|
10
|
+
s.license = package["license"]
|
11
|
+
s.authors = package["author"]
|
12
|
+
|
13
|
+
s.platforms = { :ios => min_ios_version_supported }
|
14
|
+
s.source = { :git => package["repository"], :tag => "#{s.version}" }
|
15
|
+
|
16
|
+
s.source_files = [
|
17
|
+
"ios/**/*.{swift,h,mm}",
|
18
|
+
"cxx/**/*.{h,cpp,hpp}"
|
19
|
+
]
|
20
|
+
s.pod_target_xcconfig = {
|
21
|
+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
|
22
|
+
"GCC_PREPROCESSOR_DEFINITIONS" => "$(inherited) FOLLY_NO_CONFIG FOLLY_CFG_NO_COROUTINES"
|
23
|
+
}
|
24
|
+
|
25
|
+
s.public_header_files = [
|
26
|
+
"ios/Unistyles.h"
|
27
|
+
]
|
28
|
+
|
29
|
+
load 'nitrogen/generated/ios/Unistyles+autolinking.rb'
|
30
|
+
add_nitrogen_files(s)
|
31
|
+
|
32
|
+
install_modules_dependencies(s)
|
33
|
+
end
|
package/cxx/common/Constants.h
CHANGED
@@ -5,6 +5,7 @@ namespace margelo::nitro::unistyles::helpers {
|
|
5
5
|
static const std::string UNISTYLES_ID = "__unid";
|
6
6
|
static const std::string ADD_VARIANTS_FN = "useVariants";
|
7
7
|
static const std::string STYLE_DEPENDENCIES = "uni__dependencies";
|
8
|
+
static const std::string STYLE_VARIANTS = "uni__variants";
|
8
9
|
static const std::string WEB_STYLE_KEY = "_web";
|
9
10
|
|
10
11
|
}
|
package/cxx/common/Helpers.h
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
#pragma once
|
2
2
|
|
3
3
|
#include <jsi/jsi.h>
|
4
|
+
#include <jsi/JSIDynamic.h>
|
5
|
+
#include <folly/dynamic.h>
|
4
6
|
#include <unordered_set>
|
5
7
|
|
6
8
|
using namespace facebook;
|
7
9
|
|
8
10
|
namespace margelo::nitro::unistyles::helpers {
|
9
11
|
|
12
|
+
using Variants = std::vector<std::pair<std::string, std::string>>;
|
13
|
+
|
10
14
|
inline void assertThat(jsi::Runtime& rt, bool condition, const std::string& message) {
|
11
15
|
if (!condition) {
|
12
16
|
throw jsi::JSError(rt, message);
|
@@ -90,4 +94,92 @@ inline bool isPlatformColor(jsi::Runtime& rt, jsi::Object& maybePlatformColor) {
|
|
90
94
|
return maybePlatformColor.hasProperty(rt, "resource_paths") && maybePlatformColor.getProperty(rt, "resource_paths").isObject();
|
91
95
|
}
|
92
96
|
|
97
|
+
inline Variants variantsToPairs(jsi::Runtime& rt, jsi::Object&& variants) {
|
98
|
+
Variants pairs{};
|
99
|
+
|
100
|
+
helpers::enumerateJSIObject(rt, variants, [&](const std::string& variantName, jsi::Value& variantValue){
|
101
|
+
if (variantValue.isUndefined() || variantValue.isNull()) {
|
102
|
+
return;
|
103
|
+
}
|
104
|
+
|
105
|
+
if (variantValue.isBool()) {
|
106
|
+
pairs.emplace_back(std::make_pair(variantName, variantValue.asBool() ? "true" : "false"));
|
107
|
+
|
108
|
+
return;
|
109
|
+
}
|
110
|
+
|
111
|
+
if (variantValue.isString()) {
|
112
|
+
pairs.emplace_back(std::make_pair(variantName, variantValue.asString(rt).utf8(rt)));
|
113
|
+
}
|
114
|
+
});
|
115
|
+
|
116
|
+
return pairs;
|
117
|
+
}
|
118
|
+
|
119
|
+
inline jsi::Object variantsToValue(jsi::Runtime& rt, Variants& variants) {
|
120
|
+
jsi::Object rawVariants = jsi::Object(rt);
|
121
|
+
|
122
|
+
std::for_each(variants.begin(), variants.end(), [&](std::pair<std::string, std::string>& pair){
|
123
|
+
rawVariants.setProperty(rt, pair.first.c_str(), jsi::String::createFromUtf8(rt, pair.second));
|
124
|
+
});
|
125
|
+
|
126
|
+
return rawVariants;
|
127
|
+
}
|
128
|
+
|
129
|
+
inline std::vector<folly::dynamic> parseDynamicFunctionArguments(jsi::Runtime& rt, jsi::Array& arguments) {
|
130
|
+
std::vector<folly::dynamic> parsedArgument{};
|
131
|
+
size_t count = arguments.size(rt);
|
132
|
+
|
133
|
+
parsedArgument.reserve(count);
|
134
|
+
|
135
|
+
for (size_t i = 0; i < count; i++) {
|
136
|
+
jsi::Value arg = arguments.getValueAtIndex(rt, i);
|
137
|
+
|
138
|
+
if (arg.isBool()) {
|
139
|
+
parsedArgument.push_back(folly::dynamic(arg.asBool()));
|
140
|
+
|
141
|
+
continue;
|
142
|
+
}
|
143
|
+
|
144
|
+
if (arg.isNumber()) {
|
145
|
+
parsedArgument.push_back(folly::dynamic(arg.asNumber()));
|
146
|
+
|
147
|
+
continue;
|
148
|
+
}
|
149
|
+
|
150
|
+
if (arg.isString()) {
|
151
|
+
parsedArgument.push_back(folly::dynamic(arg.asString(rt).utf8(rt)));
|
152
|
+
|
153
|
+
continue;
|
154
|
+
}
|
155
|
+
|
156
|
+
if (arg.isUndefined()) {
|
157
|
+
parsedArgument.push_back(folly::dynamic());
|
158
|
+
|
159
|
+
continue;
|
160
|
+
}
|
161
|
+
|
162
|
+
if (arg.isNull()) {
|
163
|
+
parsedArgument.push_back(folly::dynamic(nullptr));
|
164
|
+
|
165
|
+
continue;
|
166
|
+
}
|
167
|
+
|
168
|
+
if (!arg.isObject()) {
|
169
|
+
continue;;
|
170
|
+
}
|
171
|
+
|
172
|
+
auto argObj = arg.asObject(rt);
|
173
|
+
|
174
|
+
// allow arrays and objects too
|
175
|
+
if (!argObj.isFunction(rt) && !argObj.isArrayBuffer(rt)) {
|
176
|
+
parsedArgument.push_back(jsi::dynamicFromValue(rt, arg));
|
177
|
+
|
178
|
+
continue;
|
179
|
+
}
|
180
|
+
}
|
181
|
+
|
182
|
+
return parsedArgument;
|
183
|
+
}
|
184
|
+
|
93
185
|
}
|
package/cxx/core/HostStyle.cpp
CHANGED
@@ -7,10 +7,12 @@ using namespace facebook;
|
|
7
7
|
std::vector<jsi::PropNameID> HostStyle::getPropertyNames(jsi::Runtime& rt) {
|
8
8
|
auto propertyNames = std::vector<jsi::PropNameID> {};
|
9
9
|
|
10
|
+
propertyNames.reserve(8);
|
11
|
+
|
10
12
|
for (const auto& pair : this->_styleSheet->unistyles) {
|
11
13
|
propertyNames.emplace_back(jsi::PropNameID::forUtf8(rt, pair.first));
|
12
14
|
}
|
13
|
-
|
15
|
+
|
14
16
|
return propertyNames;
|
15
17
|
}
|
16
18
|
|
@@ -20,7 +22,7 @@ jsi::Value HostStyle::get(jsi::Runtime& rt, const jsi::PropNameID& propNameId) {
|
|
20
22
|
if (propertyName == helpers::UNISTYLES_ID) {
|
21
23
|
return jsi::Value(this->_styleSheet->tag);
|
22
24
|
}
|
23
|
-
|
25
|
+
|
24
26
|
if (propertyName == helpers::ADD_VARIANTS_FN) {
|
25
27
|
return this->createAddVariantsProxyFunction(rt);
|
26
28
|
}
|
@@ -29,6 +31,10 @@ jsi::Value HostStyle::get(jsi::Runtime& rt, const jsi::PropNameID& propNameId) {
|
|
29
31
|
return valueFromUnistyle(rt, this->_styleSheet->unistyles[propertyName]);
|
30
32
|
}
|
31
33
|
|
34
|
+
if (propertyName == helpers::STYLE_VARIANTS) {
|
35
|
+
return helpers::variantsToValue(rt, this->_variants);
|
36
|
+
}
|
37
|
+
|
32
38
|
return jsi::Value::undefined();
|
33
39
|
}
|
34
40
|
|
@@ -36,20 +42,20 @@ jsi::Function HostStyle::createAddVariantsProxyFunction(jsi::Runtime& rt) {
|
|
36
42
|
auto useVariantsFnName = jsi::PropNameID::forUtf8(rt, helpers::ADD_VARIANTS_FN);
|
37
43
|
|
38
44
|
return jsi::Function::createFromHostFunction(rt, useVariantsFnName, 1, [&](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *arguments, size_t count){
|
39
|
-
helpers::assertThat(rt, count == 1, "useVariants expected to be called with one argument.");
|
40
|
-
helpers::assertThat(rt, arguments[0].isObject(), "useVariants expected to be called with object.");
|
45
|
+
helpers::assertThat(rt, count == 1, "Unistyles: useVariants expected to be called with one argument.");
|
46
|
+
helpers::assertThat(rt, arguments[0].isObject(), "Unistyles: useVariants expected to be called with object.");
|
41
47
|
|
42
48
|
auto parser = parser::Parser(this->_unistylesRuntime);
|
43
|
-
auto pairs =
|
44
|
-
|
45
|
-
if (pairs == this->
|
49
|
+
auto pairs = helpers::variantsToPairs(rt, arguments[0].asObject(rt));
|
50
|
+
|
51
|
+
if (pairs == this->_variants) {
|
46
52
|
return jsi::Value::undefined();
|
47
53
|
}
|
48
|
-
|
49
|
-
this->
|
50
|
-
|
51
|
-
parser.rebuildUnistylesWithVariants(rt, this->_styleSheet);
|
52
|
-
|
54
|
+
|
55
|
+
this->_variants = pairs;
|
56
|
+
|
57
|
+
parser.rebuildUnistylesWithVariants(rt, this->_styleSheet, this->_variants);
|
58
|
+
|
53
59
|
return jsi::Value::undefined();
|
54
60
|
});
|
55
61
|
}
|
package/cxx/core/HostStyle.h
CHANGED
@@ -8,6 +8,8 @@
|
|
8
8
|
|
9
9
|
namespace margelo::nitro::unistyles::core {
|
10
10
|
|
11
|
+
using Variants = std::vector<std::pair<std::string, std::string>>;
|
12
|
+
|
11
13
|
struct JSI_EXPORT HostStyle : public jsi::HostObject {
|
12
14
|
HostStyle(std::shared_ptr<StyleSheet> styleSheet, std::shared_ptr<HybridUnistylesRuntime> unistylesRuntime)
|
13
15
|
: _styleSheet{styleSheet}, _unistylesRuntime{unistylesRuntime} {};
|
@@ -20,6 +22,7 @@ struct JSI_EXPORT HostStyle : public jsi::HostObject {
|
|
20
22
|
private:
|
21
23
|
std::shared_ptr<StyleSheet> _styleSheet;
|
22
24
|
std::shared_ptr<HybridUnistylesRuntime> _unistylesRuntime;
|
25
|
+
std::vector<std::pair<std::string, std::string>> _variants{};
|
23
26
|
};
|
24
27
|
|
25
28
|
}
|
package/cxx/core/StyleSheet.h
CHANGED
@@ -4,20 +4,18 @@
|
|
4
4
|
using namespace margelo::nitro::unistyles::core;
|
5
5
|
using namespace facebook;
|
6
6
|
|
7
|
-
std::shared_ptr<StyleSheet> StyleSheetRegistry::addStyleSheetFromValue(jsi::Runtime& rt, jsi::Object rawStyleSheet) {
|
8
|
-
static unsigned int tag = 0;
|
9
|
-
|
7
|
+
std::shared_ptr<StyleSheet> StyleSheetRegistry::addStyleSheetFromValue(jsi::Runtime& rt, jsi::Object rawStyleSheet, int unid) {
|
10
8
|
if (rawStyleSheet.isFunction(rt)) {
|
11
|
-
return this->addFromFunction(rt,
|
9
|
+
return this->addFromFunction(rt, unid, rawStyleSheet.asFunction(rt));
|
12
10
|
}
|
13
11
|
|
14
|
-
return this->addFromObject(rt,
|
12
|
+
return this->addFromObject(rt, unid, std::move(rawStyleSheet));
|
15
13
|
}
|
16
14
|
|
17
|
-
std::shared_ptr<StyleSheet> StyleSheetRegistry::addFromFunction(jsi::Runtime& rt,
|
15
|
+
std::shared_ptr<StyleSheet> StyleSheetRegistry::addFromFunction(jsi::Runtime& rt, int unid, jsi::Function styleSheetFn) {
|
18
16
|
auto numberOfArgs = styleSheetFn.getProperty(rt, "length").getNumber();
|
19
17
|
|
20
|
-
helpers::assertThat(rt, numberOfArgs <= 2, "expected up to 2 arguments.");
|
18
|
+
helpers::assertThat(rt, numberOfArgs <= 2, "StyleSheet.create expected up to 2 arguments.");
|
21
19
|
|
22
20
|
auto& registry = UnistylesRegistry::get();
|
23
21
|
|
@@ -25,21 +23,20 @@ std::shared_ptr<StyleSheet> StyleSheetRegistry::addFromFunction(jsi::Runtime& rt
|
|
25
23
|
if (numberOfArgs == 0) {
|
26
24
|
auto staticStyleSheet = styleSheetFn.call(rt).asObject(rt);
|
27
25
|
|
28
|
-
return registry.addStyleSheet(
|
26
|
+
return registry.addStyleSheet(rt, unid, core::StyleSheetType::Static, std::move(staticStyleSheet));
|
29
27
|
}
|
30
28
|
|
31
29
|
// stylesheet depends only on theme
|
32
30
|
if (numberOfArgs == 1) {
|
33
|
-
return registry.addStyleSheet(
|
31
|
+
return registry.addStyleSheet(rt, unid, core::StyleSheetType::Themable, std::move(styleSheetFn));
|
34
32
|
}
|
35
33
|
|
36
34
|
// stylesheet depends on theme and mini runtime
|
37
|
-
return registry.addStyleSheet(
|
35
|
+
return registry.addStyleSheet(rt, unid, core::StyleSheetType::ThemableWithMiniRuntime, std::move(styleSheetFn));
|
38
36
|
}
|
39
37
|
|
40
|
-
std::shared_ptr<StyleSheet> StyleSheetRegistry::addFromObject(jsi::Runtime& rt,
|
38
|
+
std::shared_ptr<StyleSheet> StyleSheetRegistry::addFromObject(jsi::Runtime& rt, int tag, jsi::Object rawStyleSheet) {
|
41
39
|
auto& registry = UnistylesRegistry::get();
|
42
40
|
|
43
|
-
return registry.addStyleSheet(tag, core::StyleSheetType::Static, std::move(rawStyleSheet));
|
41
|
+
return registry.addStyleSheet(rt, tag, core::StyleSheetType::Static, std::move(rawStyleSheet));
|
44
42
|
}
|
45
|
-
|
@@ -16,11 +16,11 @@ struct StyleSheetRegistry {
|
|
16
16
|
StyleSheetRegistry(const StyleSheetRegistry&) = delete;
|
17
17
|
StyleSheetRegistry(StyleSheetRegistry&&) = delete;
|
18
18
|
|
19
|
-
virtual std::shared_ptr<StyleSheet> addStyleSheetFromValue(jsi::Runtime& rt, jsi::Object rawStyleSheet);
|
20
|
-
|
19
|
+
virtual std::shared_ptr<StyleSheet> addStyleSheetFromValue(jsi::Runtime& rt, jsi::Object rawStyleSheet, int unid);
|
20
|
+
|
21
21
|
private:
|
22
|
-
virtual std::shared_ptr<StyleSheet> addFromFunction(jsi::Runtime& rt,
|
23
|
-
virtual std::shared_ptr<StyleSheet> addFromObject(jsi::Runtime& rt,
|
22
|
+
virtual std::shared_ptr<StyleSheet> addFromFunction(jsi::Runtime& rt, int unid, jsi::Function styleSheetFn);
|
23
|
+
virtual std::shared_ptr<StyleSheet> addFromObject(jsi::Runtime& rt, int unid, jsi::Object rawStyleSheet);
|
24
24
|
};
|
25
25
|
|
26
26
|
}
|
package/cxx/core/Unistyle.h
CHANGED
@@ -14,11 +14,6 @@ enum class UnistyleType {
|
|
14
14
|
DynamicFunction
|
15
15
|
};
|
16
16
|
|
17
|
-
struct DynamicFunctionMetadata {
|
18
|
-
size_t count;
|
19
|
-
std::vector<folly::dynamic> arguments;
|
20
|
-
};
|
21
|
-
|
22
17
|
struct Unistyle {
|
23
18
|
using Shared = std::shared_ptr<Unistyle>;
|
24
19
|
|
@@ -75,7 +70,6 @@ struct UnistyleDynamicFunction: public Unistyle {
|
|
75
70
|
|
76
71
|
std::optional<jsi::Object> unprocessedValue;
|
77
72
|
std::optional<jsi::Function> proxiedFunction = std::nullopt;
|
78
|
-
std::optional<DynamicFunctionMetadata> dynamicFunctionMetadata = std::nullopt;
|
79
73
|
};
|
80
74
|
|
81
75
|
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <jsi/jsi.h>
|
4
|
+
#include "Unistyle.h"
|
5
|
+
|
6
|
+
namespace margelo::nitro::unistyles::core {
|
7
|
+
|
8
|
+
using Variants = std::vector<std::pair<std::string, std::string>>;
|
9
|
+
|
10
|
+
struct UnistyleData {
|
11
|
+
UnistyleData(Unistyle::Shared unistyle, const Variants& variants, std::vector<folly::dynamic>& arguments)
|
12
|
+
: unistyle{unistyle}, variants(std::move(variants)), dynamicFunctionMetadata{std::move(arguments)} {}
|
13
|
+
|
14
|
+
UnistyleData(const UnistyleData&) = delete;
|
15
|
+
UnistyleData(UnistyleData&& other): unistyle{other.unistyle}, variants(std::move(other.variants)) {}
|
16
|
+
|
17
|
+
core::Unistyle::Shared unistyle;
|
18
|
+
core::Variants variants;
|
19
|
+
std::optional<jsi::Object> parsedStyle = std::nullopt;
|
20
|
+
std::optional<std::vector<folly::dynamic>> dynamicFunctionMetadata = std::nullopt;
|
21
|
+
};
|
22
|
+
|
23
|
+
}
|
@@ -26,24 +26,24 @@ inline static Unistyle::Shared unistyleFromValue(jsi::Runtime& rt, const jsi::Va
|
|
26
26
|
|
27
27
|
inline static jsi::Value valueFromUnistyle(jsi::Runtime& rt, Unistyle::Shared unistyle) {
|
28
28
|
auto wrappedUnistyle = std::make_shared<UnistyleWrapper>(unistyle);
|
29
|
-
|
29
|
+
|
30
30
|
if (unistyle->type == UnistyleType::Object) {
|
31
31
|
jsi::Object obj = jsi::Object(rt);
|
32
|
-
|
32
|
+
|
33
33
|
obj.setNativeState(rt, std::move(wrappedUnistyle));
|
34
34
|
helpers::defineHiddenProperty(rt, obj, helpers::UNISTYLES_ID.c_str(), unistyle->styleKey);
|
35
|
-
|
35
|
+
|
36
36
|
helpers::mergeJSIObjects(rt, obj, unistyle->parsedStyle.value());
|
37
|
-
|
37
|
+
|
38
38
|
return obj;
|
39
39
|
}
|
40
|
-
|
40
|
+
|
41
41
|
auto unistyleFn = std::dynamic_pointer_cast<UnistyleDynamicFunction>(unistyle);
|
42
42
|
auto hostFn = jsi::Value(rt, unistyleFn->proxiedFunction.value()).asObject(rt).asFunction(rt);
|
43
43
|
|
44
44
|
hostFn.setNativeState(rt, std::move(wrappedUnistyle));
|
45
45
|
hostFn.setProperty(rt, helpers::UNISTYLES_ID.c_str(), unistyleFn->styleKey);
|
46
|
-
|
46
|
+
|
47
47
|
return std::move(hostFn);
|
48
48
|
}
|
49
49
|
|
@@ -3,12 +3,9 @@
|
|
3
3
|
using namespace margelo::nitro::unistyles;
|
4
4
|
using namespace facebook::react;
|
5
5
|
|
6
|
-
core::UnistylesCommitHook
|
7
|
-
|
8
|
-
|
9
|
-
};
|
10
|
-
|
11
|
-
core::UnistylesCommitHook::~UnistylesCommitHook() noexcept {}
|
6
|
+
core::UnistylesCommitHook::~UnistylesCommitHook() noexcept {
|
7
|
+
_uiManager->unregisterCommitHook(*this);
|
8
|
+
}
|
12
9
|
|
13
10
|
void core::UnistylesCommitHook::commitHookWasRegistered(const UIManager &uiManager) noexcept {}
|
14
11
|
void core::UnistylesCommitHook::commitHookWasUnregistered(const UIManager &uiManager) noexcept {}
|
@@ -24,6 +21,7 @@ RootShadowNode::Unshared core::UnistylesCommitHook::shadowTreeWillCommit(
|
|
24
21
|
// skip only unistyles commits
|
25
22
|
if (unistylesRootNode->hasUnistylesCommitTrait()) {
|
26
23
|
unistylesRootNode->removeUnistylesCommitTrait();
|
24
|
+
unistylesRootNode->addUnistylesMountTrait();
|
27
25
|
|
28
26
|
return newRootShadowNode;
|
29
27
|
}
|
@@ -46,8 +44,11 @@ RootShadowNode::Unshared core::UnistylesCommitHook::shadowTreeWillCommit(
|
|
46
44
|
|
47
45
|
shadow::ShadowLeafUpdates core::UnistylesCommitHook::getUnistylesUpdates() {
|
48
46
|
auto& registry = core::UnistylesRegistry::get();
|
47
|
+
auto& rt = this->_unistylesRuntime->getRuntime();
|
49
48
|
auto parser = parser::Parser(this->_unistylesRuntime);
|
50
|
-
auto dependencyMap = registry.buildDependencyMap();
|
49
|
+
auto dependencyMap = registry.buildDependencyMap(rt);
|
50
|
+
|
51
|
+
parser.rebuildUnistylesInDependencyMap(rt, dependencyMap);
|
51
52
|
|
52
53
|
return parser.dependencyMapToShadowLeafUpdates(dependencyMap);
|
53
54
|
}
|
@@ -11,7 +11,11 @@ namespace margelo::nitro::unistyles::core {
|
|
11
11
|
using namespace facebook::react;
|
12
12
|
|
13
13
|
struct UnistylesCommitHook : public UIManagerCommitHook {
|
14
|
-
UnistylesCommitHook(UIManager
|
14
|
+
UnistylesCommitHook(std::shared_ptr<UIManager> uiManager, std::shared_ptr<HybridUnistylesRuntime> unistylesRuntime)
|
15
|
+
: _unistylesRuntime{unistylesRuntime}, _uiManager{uiManager} {
|
16
|
+
_uiManager->registerCommitHook(*this);
|
17
|
+
}
|
18
|
+
|
15
19
|
~UnistylesCommitHook() noexcept override;
|
16
20
|
|
17
21
|
void commitHookWasRegistered(const UIManager &uiManager) noexcept override;
|
@@ -22,6 +26,7 @@ struct UnistylesCommitHook : public UIManagerCommitHook {
|
|
22
26
|
|
23
27
|
private:
|
24
28
|
std::shared_ptr<HybridUnistylesRuntime> _unistylesRuntime;
|
29
|
+
std::shared_ptr<UIManager> _uiManager;
|
25
30
|
};
|
26
31
|
|
27
32
|
}
|
@@ -8,6 +8,7 @@ namespace margelo::nitro::unistyles::core {
|
|
8
8
|
// React Native uses 0-10
|
9
9
|
// Reanimated uses 27-28
|
10
10
|
constexpr shadow::ShadowNodeTraits::Trait UnistylesCommitTrait{1 << 30};
|
11
|
+
constexpr shadow::ShadowNodeTraits::Trait UnistylesMountTrait{1 << 31};
|
11
12
|
|
12
13
|
struct UnistylesCommitShadowNode: public shadow::ShadowNode {
|
13
14
|
inline void addUnistylesCommitTrait() {
|
@@ -21,6 +22,18 @@ struct UnistylesCommitShadowNode: public shadow::ShadowNode {
|
|
21
22
|
inline bool hasUnistylesCommitTrait() {
|
22
23
|
return traits_.check(UnistylesCommitTrait);
|
23
24
|
}
|
25
|
+
|
26
|
+
inline void addUnistylesMountTrait() {
|
27
|
+
traits_.set(UnistylesMountTrait);
|
28
|
+
}
|
29
|
+
|
30
|
+
inline void removeUnistylesMountTrait() {
|
31
|
+
traits_.unset(UnistylesMountTrait);
|
32
|
+
}
|
33
|
+
|
34
|
+
inline bool hasUnistylesMountTrait() {
|
35
|
+
return traits_.check(UnistylesMountTrait);
|
36
|
+
}
|
24
37
|
};
|
25
38
|
|
26
39
|
}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#include "UnistylesMountHook.h"
|
2
|
+
#include "ShadowTreeManager.h"
|
3
|
+
|
4
|
+
using namespace margelo::nitro::unistyles;
|
5
|
+
using namespace facebook::react;
|
6
|
+
|
7
|
+
core::UnistylesMountHook::~UnistylesMountHook() noexcept {
|
8
|
+
_uiManager->unregisterMountHook(*this);
|
9
|
+
}
|
10
|
+
|
11
|
+
void core::UnistylesMountHook::shadowTreeDidMount(RootShadowNode::Shared const &rootShadowNode, double mountTime) noexcept {
|
12
|
+
auto rootNode = std::const_pointer_cast<RootShadowNode>(rootShadowNode);
|
13
|
+
auto unistylesRootNode = std::reinterpret_pointer_cast<core::UnistylesCommitShadowNode>(rootNode);
|
14
|
+
|
15
|
+
// skip only unistyles commits
|
16
|
+
if (unistylesRootNode->hasUnistylesMountTrait()) {
|
17
|
+
unistylesRootNode->removeUnistylesMountTrait();
|
18
|
+
|
19
|
+
return;
|
20
|
+
}
|
21
|
+
|
22
|
+
auto shadowLeafUpdates = this->getUnistylesUpdates();
|
23
|
+
|
24
|
+
if (shadowLeafUpdates.size() == 0) {
|
25
|
+
return;
|
26
|
+
}
|
27
|
+
|
28
|
+
shadow::ShadowTreeManager::updateShadowTree(this->_unistylesRuntime->getRuntime(), shadowLeafUpdates);
|
29
|
+
}
|
30
|
+
|
31
|
+
shadow::ShadowLeafUpdates core::UnistylesMountHook::getUnistylesUpdates() {
|
32
|
+
auto& registry = core::UnistylesRegistry::get();
|
33
|
+
auto& rt = this->_unistylesRuntime->getRuntime();
|
34
|
+
auto parser = parser::Parser(this->_unistylesRuntime);
|
35
|
+
auto dependencyMap = registry.buildDependencyMap(rt);
|
36
|
+
|
37
|
+
parser.rebuildUnistylesInDependencyMap(rt, dependencyMap);
|
38
|
+
|
39
|
+
return parser.dependencyMapToShadowLeafUpdates(dependencyMap);
|
40
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <react/renderer/uimanager/UIManager.h>
|
4
|
+
#include <react/renderer/uimanager/UIManagerMountHook.h>
|
5
|
+
#include "HybridUnistylesRuntime.h"
|
6
|
+
#include "Parser.h"
|
7
|
+
#include "ShadowTreeManager.h"
|
8
|
+
|
9
|
+
namespace margelo::nitro::unistyles::core {
|
10
|
+
|
11
|
+
using namespace facebook::react;
|
12
|
+
|
13
|
+
struct UnistylesMountHook : public UIManagerMountHook {
|
14
|
+
UnistylesMountHook(std::shared_ptr<UIManager> uiManager, std::shared_ptr<HybridUnistylesRuntime> unistylesRuntime)
|
15
|
+
: _unistylesRuntime{unistylesRuntime}, _uiManager{uiManager} {
|
16
|
+
_uiManager->registerMountHook(*this);
|
17
|
+
}
|
18
|
+
|
19
|
+
~UnistylesMountHook() noexcept override;
|
20
|
+
|
21
|
+
void shadowTreeDidMount(RootShadowNode::Shared const &rootShadowNode, double mountTime) noexcept override;
|
22
|
+
|
23
|
+
shadow::ShadowLeafUpdates getUnistylesUpdates();
|
24
|
+
|
25
|
+
private:
|
26
|
+
std::shared_ptr<HybridUnistylesRuntime> _unistylesRuntime;
|
27
|
+
std::shared_ptr<UIManager> _uiManager;
|
28
|
+
};
|
29
|
+
|
30
|
+
}
|