react-native-unistyles 3.0.0-alpha.11 → 3.0.0-alpha.12
Sign up to get free protection for your applications and to get access to all the features.
- package/cxx/core/HostStyle.h +1 -1
- package/cxx/core/UnistylesCommitHook.cpp +3 -4
- package/cxx/core/UnistylesCommitHook.h +3 -2
- package/cxx/core/UnistylesMountHook.cpp +3 -4
- package/cxx/core/UnistylesMountHook.h +3 -2
- package/cxx/core/UnistylesRegistry.cpp +19 -14
- package/cxx/core/UnistylesRegistry.h +3 -3
- package/cxx/core/UnistylesState.cpp +1 -1
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +2 -2
- package/cxx/hybridObjects/HybridStyleSheet.cpp +6 -0
- package/cxx/hybridObjects/HybridStyleSheet.h +3 -3
- package/cxx/parser/Parser.cpp +3 -1
- package/package.json +1 -1
package/cxx/core/HostStyle.h
CHANGED
@@ -22,7 +22,7 @@ struct JSI_EXPORT HostStyle : public jsi::HostObject {
|
|
22
22
|
private:
|
23
23
|
std::shared_ptr<StyleSheet> _styleSheet;
|
24
24
|
std::shared_ptr<HybridUnistylesRuntime> _unistylesRuntime;
|
25
|
-
std::vector<std::pair<std::string, std::string>> _variants{};
|
25
|
+
std::vector<std::pair<std::string, std::string>> _variants{};
|
26
26
|
};
|
27
27
|
|
28
28
|
}
|
@@ -35,7 +35,7 @@ RootShadowNode::Unshared core::UnistylesCommitHook::shadowTreeWillCommit(
|
|
35
35
|
auto affectedNodes = shadow::ShadowTreeManager::findAffectedNodes(*rootNode, shadowLeafUpdates);
|
36
36
|
|
37
37
|
return std::static_pointer_cast<RootShadowNode>(shadow::ShadowTreeManager::cloneShadowTree(
|
38
|
-
this->
|
38
|
+
*this->_rt,
|
39
39
|
*rootNode,
|
40
40
|
shadowLeafUpdates,
|
41
41
|
affectedNodes
|
@@ -44,11 +44,10 @@ RootShadowNode::Unshared core::UnistylesCommitHook::shadowTreeWillCommit(
|
|
44
44
|
|
45
45
|
shadow::ShadowLeafUpdates core::UnistylesCommitHook::getUnistylesUpdates() {
|
46
46
|
auto& registry = core::UnistylesRegistry::get();
|
47
|
-
auto& rt = this->_unistylesRuntime->getRuntime();
|
48
47
|
auto parser = parser::Parser(this->_unistylesRuntime);
|
49
|
-
auto dependencyMap = registry.buildDependencyMap(
|
48
|
+
auto dependencyMap = registry.buildDependencyMap(*this->_rt);
|
50
49
|
|
51
|
-
parser.rebuildUnistylesInDependencyMap(
|
50
|
+
parser.rebuildUnistylesInDependencyMap(*this->_rt, dependencyMap);
|
52
51
|
|
53
52
|
return parser.dependencyMapToShadowLeafUpdates(dependencyMap);
|
54
53
|
}
|
@@ -11,8 +11,8 @@ namespace margelo::nitro::unistyles::core {
|
|
11
11
|
using namespace facebook::react;
|
12
12
|
|
13
13
|
struct UnistylesCommitHook : public UIManagerCommitHook {
|
14
|
-
UnistylesCommitHook(std::shared_ptr<UIManager> uiManager, std::shared_ptr<HybridUnistylesRuntime> unistylesRuntime)
|
15
|
-
: _unistylesRuntime{unistylesRuntime}, _uiManager{uiManager} {
|
14
|
+
UnistylesCommitHook(std::shared_ptr<UIManager> uiManager, std::shared_ptr<HybridUnistylesRuntime> unistylesRuntime, jsi::Runtime& rt)
|
15
|
+
: _unistylesRuntime{unistylesRuntime}, _uiManager{uiManager}, _rt{&rt} {
|
16
16
|
_uiManager->registerCommitHook(*this);
|
17
17
|
}
|
18
18
|
|
@@ -27,6 +27,7 @@ struct UnistylesCommitHook : public UIManagerCommitHook {
|
|
27
27
|
private:
|
28
28
|
std::shared_ptr<HybridUnistylesRuntime> _unistylesRuntime;
|
29
29
|
std::shared_ptr<UIManager> _uiManager;
|
30
|
+
jsi::Runtime* _rt;
|
30
31
|
};
|
31
32
|
|
32
33
|
}
|
@@ -25,16 +25,15 @@ void core::UnistylesMountHook::shadowTreeDidMount(RootShadowNode::Shared const &
|
|
25
25
|
return;
|
26
26
|
}
|
27
27
|
|
28
|
-
shadow::ShadowTreeManager::updateShadowTree(this->
|
28
|
+
shadow::ShadowTreeManager::updateShadowTree(*this->_rt, shadowLeafUpdates);
|
29
29
|
}
|
30
30
|
|
31
31
|
shadow::ShadowLeafUpdates core::UnistylesMountHook::getUnistylesUpdates() {
|
32
32
|
auto& registry = core::UnistylesRegistry::get();
|
33
|
-
auto& rt = this->_unistylesRuntime->getRuntime();
|
34
33
|
auto parser = parser::Parser(this->_unistylesRuntime);
|
35
|
-
auto dependencyMap = registry.buildDependencyMap(
|
34
|
+
auto dependencyMap = registry.buildDependencyMap(*this->_rt);
|
36
35
|
|
37
|
-
parser.rebuildUnistylesInDependencyMap(
|
36
|
+
parser.rebuildUnistylesInDependencyMap(*this->_rt, dependencyMap);
|
38
37
|
|
39
38
|
return parser.dependencyMapToShadowLeafUpdates(dependencyMap);
|
40
39
|
}
|
@@ -11,8 +11,8 @@ namespace margelo::nitro::unistyles::core {
|
|
11
11
|
using namespace facebook::react;
|
12
12
|
|
13
13
|
struct UnistylesMountHook : public UIManagerMountHook {
|
14
|
-
UnistylesMountHook(std::shared_ptr<UIManager> uiManager, std::shared_ptr<HybridUnistylesRuntime> unistylesRuntime)
|
15
|
-
: _unistylesRuntime{unistylesRuntime}, _uiManager{uiManager} {
|
14
|
+
UnistylesMountHook(std::shared_ptr<UIManager> uiManager, std::shared_ptr<HybridUnistylesRuntime> unistylesRuntime, jsi::Runtime& rt)
|
15
|
+
: _unistylesRuntime{unistylesRuntime}, _uiManager{uiManager}, _rt{&rt} {
|
16
16
|
_uiManager->registerMountHook(*this);
|
17
17
|
}
|
18
18
|
|
@@ -23,6 +23,7 @@ struct UnistylesMountHook : public UIManagerMountHook {
|
|
23
23
|
shadow::ShadowLeafUpdates getUnistylesUpdates();
|
24
24
|
|
25
25
|
private:
|
26
|
+
jsi::Runtime* _rt;
|
26
27
|
std::shared_ptr<HybridUnistylesRuntime> _unistylesRuntime;
|
27
28
|
std::shared_ptr<UIManager> _uiManager;
|
28
29
|
};
|
@@ -72,26 +72,31 @@ void core::UnistylesRegistry::updateTheme(jsi::Runtime& rt, std::string& themeNa
|
|
72
72
|
}
|
73
73
|
|
74
74
|
void core::UnistylesRegistry::linkShadowNodeWithUnistyle(
|
75
|
+
jsi::Runtime& rt,
|
75
76
|
const ShadowNodeFamily* shadowNodeFamily,
|
76
77
|
const core::Unistyle::Shared unistyle,
|
77
78
|
Variants& variants,
|
78
79
|
std::vector<folly::dynamic>& arguments
|
79
80
|
) {
|
80
|
-
if (!this->_shadowRegistry.contains(shadowNodeFamily)) {
|
81
|
-
this->_shadowRegistry[shadowNodeFamily] = {};
|
81
|
+
if (!this->_shadowRegistry[&rt].contains(shadowNodeFamily)) {
|
82
|
+
this->_shadowRegistry[&rt][shadowNodeFamily] = {};
|
82
83
|
}
|
83
84
|
|
84
|
-
this->_shadowRegistry[shadowNodeFamily].emplace_back(std::make_shared<UnistyleData>(unistyle, variants, arguments));
|
85
|
+
this->_shadowRegistry[&rt][shadowNodeFamily].emplace_back(std::make_shared<UnistyleData>(unistyle, variants, arguments));
|
85
86
|
}
|
86
87
|
|
87
|
-
void core::UnistylesRegistry::unlinkShadowNodeWithUnistyle(
|
88
|
-
|
88
|
+
void core::UnistylesRegistry::unlinkShadowNodeWithUnistyle(
|
89
|
+
jsi::Runtime& rt,
|
90
|
+
const ShadowNodeFamily* shadowNodeFamily,
|
91
|
+
const core::Unistyle::Shared unistyle
|
92
|
+
) {
|
93
|
+
auto& unistylesVec = this->_shadowRegistry[&rt][shadowNodeFamily];
|
89
94
|
auto it = std::find_if(unistylesVec.begin(), unistylesVec.end(), [unistyle](std::shared_ptr<UnistyleData> unistyleData){
|
90
95
|
return unistyleData->unistyle == unistyle;
|
91
96
|
});
|
92
97
|
|
93
98
|
if (it != unistylesVec.end()) {
|
94
|
-
this->_shadowRegistry[shadowNodeFamily].erase(it);
|
99
|
+
this->_shadowRegistry[&rt][shadowNodeFamily].erase(it);
|
95
100
|
}
|
96
101
|
}
|
97
102
|
|
@@ -104,8 +109,8 @@ std::shared_ptr<core::StyleSheet> core::UnistylesRegistry::addStyleSheet(jsi::Ru
|
|
104
109
|
core::DependencyMap core::UnistylesRegistry::buildDependencyMap(jsi::Runtime& rt, std::vector<UnistyleDependency>& deps) {
|
105
110
|
DependencyMap dependencyMap;
|
106
111
|
std::set<UnistyleDependency> uniqueDependencies(deps.begin(), deps.end());
|
107
|
-
|
108
|
-
for (const auto& [family, unistyles] : this->_shadowRegistry) {
|
112
|
+
|
113
|
+
for (const auto& [family, unistyles] : this->_shadowRegistry[&rt]) {
|
109
114
|
for (const auto& unistyleData : unistyles) {
|
110
115
|
bool hasAnyOfDependencies = std::any_of(
|
111
116
|
unistyleData->unistyle->dependencies.begin(),
|
@@ -114,28 +119,28 @@ core::DependencyMap core::UnistylesRegistry::buildDependencyMap(jsi::Runtime& rt
|
|
114
119
|
return std::find(uniqueDependencies.begin(), uniqueDependencies.end(), dep) != uniqueDependencies.end();
|
115
120
|
}
|
116
121
|
);
|
117
|
-
|
122
|
+
|
118
123
|
if (!hasAnyOfDependencies) {
|
119
124
|
continue;
|
120
125
|
}
|
121
|
-
|
126
|
+
|
122
127
|
// we need to take in count all unistyles from the shadowNode
|
123
128
|
// as user might be using spreads and not all of them may have dependencies
|
124
129
|
for (const auto& unistyleData : unistyles) {
|
125
130
|
dependencyMap[family].emplace_back(unistyleData);
|
126
131
|
}
|
127
|
-
|
132
|
+
|
128
133
|
break;
|
129
134
|
}
|
130
135
|
}
|
131
|
-
|
136
|
+
|
132
137
|
return dependencyMap;
|
133
138
|
}
|
134
139
|
|
135
140
|
core::DependencyMap core::UnistylesRegistry::buildDependencyMap(jsi::Runtime& rt) {
|
136
141
|
DependencyMap dependencyMap;
|
137
|
-
|
138
|
-
for (const auto& [family, unistyles] : this->_shadowRegistry) {
|
142
|
+
|
143
|
+
for (const auto& [family, unistyles] : this->_shadowRegistry[&rt]) {
|
139
144
|
for (const auto& unistyleData : unistyles) {
|
140
145
|
dependencyMap[family].emplace_back(unistyleData);
|
141
146
|
}
|
@@ -35,8 +35,8 @@ struct UnistylesRegistry: public StyleSheetRegistry {
|
|
35
35
|
|
36
36
|
UnistylesState& getState(jsi::Runtime& rt);
|
37
37
|
void createState(jsi::Runtime& rt);
|
38
|
-
void linkShadowNodeWithUnistyle(const ShadowNodeFamily*, const core::Unistyle::Shared, Variants& variants, std::vector<folly::dynamic>&);
|
39
|
-
void unlinkShadowNodeWithUnistyle(const ShadowNodeFamily*, const core::Unistyle::Shared);
|
38
|
+
void linkShadowNodeWithUnistyle(jsi::Runtime& rt, const ShadowNodeFamily*, const core::Unistyle::Shared, Variants& variants, std::vector<folly::dynamic>&);
|
39
|
+
void unlinkShadowNodeWithUnistyle(jsi::Runtime& rt, const ShadowNodeFamily*, const core::Unistyle::Shared);
|
40
40
|
std::shared_ptr<core::StyleSheet> addStyleSheet(jsi::Runtime& rt, int tag, core::StyleSheetType type, jsi::Object&& rawValue);
|
41
41
|
DependencyMap buildDependencyMap(jsi::Runtime& rt, std::vector<UnistyleDependency>& deps);
|
42
42
|
DependencyMap buildDependencyMap(jsi::Runtime& rt);
|
@@ -46,7 +46,7 @@ private:
|
|
46
46
|
|
47
47
|
std::unordered_map<jsi::Runtime*, UnistylesState> _states{};
|
48
48
|
std::unordered_map<jsi::Runtime*, std::unordered_map<int, std::shared_ptr<core::StyleSheet>>> _styleSheetRegistry{};
|
49
|
-
std::unordered_map<const ShadowNodeFamily*, std::vector<std::shared_ptr<UnistyleData
|
49
|
+
std::unordered_map<jsi::Runtime*, std::unordered_map<const ShadowNodeFamily*, std::vector<std::shared_ptr<UnistyleData>>>> _shadowRegistry{};
|
50
50
|
};
|
51
51
|
|
52
52
|
UnistylesRegistry& UnistylesRegistry::get() {
|
@@ -91,5 +91,5 @@ int core::UnistylesState::parseColor(jsi::Value& maybeColor) {
|
|
91
91
|
// we must convert it to uint32_t first, otherwise color will be broken
|
92
92
|
uint32_t color = this->_processColorFn.get()->call(*_rt, maybeColor.asString(*_rt)).asNumber();
|
93
93
|
|
94
|
-
return color;
|
94
|
+
return color ? color : 0;
|
95
95
|
}
|
@@ -14,7 +14,7 @@ jsi::Value HybridShadowRegistry::link(jsi::Runtime &rt, const jsi::Value &thisVa
|
|
14
14
|
|
15
15
|
auto& registry = core::UnistylesRegistry::get();
|
16
16
|
|
17
|
-
registry.linkShadowNodeWithUnistyle(&shadowNodeWrapper->getFamily(), unistyleWrapper, variants, arguments);
|
17
|
+
registry.linkShadowNodeWithUnistyle(rt, &shadowNodeWrapper->getFamily(), unistyleWrapper, variants, arguments);
|
18
18
|
|
19
19
|
return jsi::Value::undefined();
|
20
20
|
}
|
@@ -27,7 +27,7 @@ jsi::Value HybridShadowRegistry::unlink(jsi::Runtime &rt, const jsi::Value &this
|
|
27
27
|
|
28
28
|
auto& registry = core::UnistylesRegistry::get();
|
29
29
|
|
30
|
-
registry.unlinkShadowNodeWithUnistyle(&shadowNodeWrapper->getFamily(), unistyleWrapper);
|
30
|
+
registry.unlinkShadowNodeWithUnistyle(rt, &shadowNodeWrapper->getFamily(), unistyleWrapper);
|
31
31
|
|
32
32
|
return jsi::Value::undefined();
|
33
33
|
}
|
@@ -72,6 +72,7 @@ jsi::Value HybridStyleSheet::configure(jsi::Runtime &rt, const jsi::Value &thisV
|
|
72
72
|
|
73
73
|
verifyAndSelectTheme(rt);
|
74
74
|
loadExternalMethods(thisVal, rt);
|
75
|
+
registerHooks(rt);
|
75
76
|
|
76
77
|
return jsi::Value::undefined();
|
77
78
|
}
|
@@ -239,3 +240,8 @@ void HybridStyleSheet::onPlatformDependenciesChange(std::vector<UnistyleDependen
|
|
239
240
|
|
240
241
|
shadow::ShadowTreeManager::updateShadowTree(rt, shadowLeafUpdates);
|
241
242
|
}
|
243
|
+
|
244
|
+
void HybridStyleSheet::registerHooks(jsi::Runtime& rt) {
|
245
|
+
this->_unistylesCommitHook = std::make_shared<core::UnistylesCommitHook>(this->_uiManager, this->_unistylesRuntime, rt);
|
246
|
+
this->_unistylesMountHook = std::make_shared<core::UnistylesMountHook>(this->_uiManager, this->_unistylesRuntime, rt);
|
247
|
+
}
|
@@ -18,9 +18,7 @@ using namespace facebook::react;
|
|
18
18
|
|
19
19
|
struct HybridStyleSheet: public HybridUnistylesStyleSheetSpec {
|
20
20
|
HybridStyleSheet(std::shared_ptr<HybridUnistylesRuntime> unistylesRuntime, std::shared_ptr<UIManager> uiManager)
|
21
|
-
: HybridObject(TAG), _unistylesRuntime{unistylesRuntime} {
|
22
|
-
this->_unistylesCommitHook = std::make_shared<core::UnistylesCommitHook>(uiManager, unistylesRuntime);
|
23
|
-
this->_unistylesMountHook = std::make_shared<core::UnistylesMountHook>(uiManager, unistylesRuntime);
|
21
|
+
: HybridObject(TAG), _unistylesRuntime{unistylesRuntime}, _uiManager{uiManager} {
|
24
22
|
this->_unistylesRuntime->registerPlatformListener(
|
25
23
|
std::bind(&HybridStyleSheet::onPlatformDependenciesChange, this, std::placeholders::_1)
|
26
24
|
);
|
@@ -54,11 +52,13 @@ private:
|
|
54
52
|
void verifyAndSelectTheme(jsi::Runtime &rt);
|
55
53
|
void setThemeFromColorScheme(jsi::Runtime& rt);
|
56
54
|
void loadExternalMethods(const jsi::Value& thisValue, jsi::Runtime& rt);
|
55
|
+
void registerHooks(jsi::Runtime& rt);
|
57
56
|
void onPlatformDependenciesChange(std::vector<UnistyleDependency> dependencies);
|
58
57
|
|
59
58
|
double __unid = -1;
|
60
59
|
std::shared_ptr<HybridUnistylesRuntime> _unistylesRuntime;
|
61
60
|
std::shared_ptr<core::UnistylesCommitHook> _unistylesCommitHook;
|
62
61
|
std::shared_ptr<core::UnistylesMountHook> _unistylesMountHook;
|
62
|
+
std::shared_ptr<UIManager> _uiManager;
|
63
63
|
};
|
64
64
|
|
package/cxx/parser/Parser.cpp
CHANGED
@@ -531,7 +531,9 @@ bool parser::Parser::shouldApplyCompoundVariants(jsi::Runtime& rt, const Variant
|
|
531
531
|
auto property = compoundVariant.getProperty(rt, variantKey.c_str());
|
532
532
|
auto propertyName = property.isBool()
|
533
533
|
? (property.asBool() ? "true" : "false")
|
534
|
-
: property.
|
534
|
+
: property.isString()
|
535
|
+
? property.asString(rt).utf8(rt)
|
536
|
+
: "";
|
535
537
|
|
536
538
|
if (propertyName != variantValue) {
|
537
539
|
return false;
|