react-native-unistyles 3.0.0-alpha.10 → 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/Unistyle.h +7 -4
- package/cxx/core/UnistyleWrapper.h +19 -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 +24 -36
- package/cxx/core/UnistylesRegistry.h +4 -7
- package/cxx/core/UnistylesState.cpp +1 -1
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +9 -9
- package/cxx/hybridObjects/HybridStyleSheet.cpp +6 -0
- package/cxx/hybridObjects/HybridStyleSheet.h +3 -3
- package/cxx/parser/Parser.cpp +36 -40
- package/cxx/parser/Parser.h +1 -1
- package/cxx/shadowTree/ShadowLeafUpdate.h +1 -1
- package/cxx/shadowTree/ShadowTreeManager.cpp +3 -8
- package/lib/commonjs/specs/ShadowRegistry/index.js +1 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/specs/ShadowRegistry/index.js +1 -1
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +1 -1
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/plugin/__tests__/dependencies.spec.js +15 -5
- package/plugin/__tests__/ref.spec.js +209 -30
- package/plugin/__tests__/stylesheet.spec.js +27 -9
- package/plugin/index.js +38 -3
- package/plugin/ref.js +41 -11
- package/plugin/style.js +45 -1
- package/src/specs/ShadowRegistry/index.ts +2 -2
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
|
}
|
package/cxx/core/Unistyle.h
CHANGED
@@ -7,6 +7,8 @@
|
|
7
7
|
|
8
8
|
namespace margelo::nitro::unistyles::core {
|
9
9
|
|
10
|
+
class StyleSheet;
|
11
|
+
|
10
12
|
using namespace facebook;
|
11
13
|
|
12
14
|
enum class UnistyleType {
|
@@ -17,8 +19,8 @@ enum class UnistyleType {
|
|
17
19
|
struct Unistyle {
|
18
20
|
using Shared = std::shared_ptr<Unistyle>;
|
19
21
|
|
20
|
-
Unistyle(UnistyleType type, std::string styleKey, jsi::Object& rawObject)
|
21
|
-
: styleKey{styleKey}, type{type}, rawValue{std::move(rawObject)} {}
|
22
|
+
Unistyle(UnistyleType type, std::string styleKey, jsi::Object& rawObject, std::shared_ptr<StyleSheet> styleSheet)
|
23
|
+
: styleKey{styleKey}, type{type}, rawValue{std::move(rawObject)}, parent{styleSheet} {}
|
22
24
|
virtual ~Unistyle() = default;
|
23
25
|
|
24
26
|
Unistyle(const Unistyle&) = delete;
|
@@ -29,6 +31,7 @@ struct Unistyle {
|
|
29
31
|
jsi::Object rawValue;
|
30
32
|
std::optional<jsi::Object> parsedStyle;
|
31
33
|
std::vector<UnistyleDependency> dependencies{};
|
34
|
+
std::shared_ptr<StyleSheet> parent;
|
32
35
|
|
33
36
|
inline void addDependency(UnistyleDependency dependency) {
|
34
37
|
// we can't add dependencies if unistyle is sealed
|
@@ -62,8 +65,8 @@ struct UnistyleDynamicFunction: public Unistyle {
|
|
62
65
|
// unprocessedValue <- object generated after calling proxy and user's original function
|
63
66
|
// parsedStyle <- parsed with Unistyle's parser
|
64
67
|
|
65
|
-
UnistyleDynamicFunction(UnistyleType type, std::string styleKey, jsi::Object& rawObject)
|
66
|
-
: Unistyle(type, styleKey, rawObject) {}
|
68
|
+
UnistyleDynamicFunction(UnistyleType type, std::string styleKey, jsi::Object& rawObject, std::shared_ptr<StyleSheet> styleSheet)
|
69
|
+
: Unistyle(type, styleKey, rawObject, styleSheet) {}
|
67
70
|
|
68
71
|
UnistyleDynamicFunction(const UnistyleDynamicFunction&) = delete;
|
69
72
|
UnistyleDynamicFunction(UnistyleDynamicFunction&& other) = delete;
|
@@ -21,7 +21,25 @@ inline static Unistyle::Shared unistyleFromValue(jsi::Runtime& rt, const jsi::Va
|
|
21
21
|
return nullptr;
|
22
22
|
}
|
23
23
|
|
24
|
-
|
24
|
+
auto obj = value.getObject(rt);
|
25
|
+
|
26
|
+
if (!obj.hasNativeState(rt)) {
|
27
|
+
throw jsi::JSError(rt, R"(Unistyles: Style is not bound!
|
28
|
+
|
29
|
+
Potential reasons:
|
30
|
+
- You likely used the spread operator on a Unistyle style outside of a JSX component
|
31
|
+
- You're mixing React Native's StyleSheet styles with Unistyles styles
|
32
|
+
|
33
|
+
If you need to merge styles, do it within the style prop of your JSX component:
|
34
|
+
|
35
|
+
style={{...styles.container, ...styles.otherProp}} or style={[styles.container, styles.otherProp]}
|
36
|
+
|
37
|
+
Copying a Unistyle style outside of a JSX element will remove its internal C++ state, leading to unexpected behavior.
|
38
|
+
|
39
|
+
If you're mixing React Native and Unistyle StyleSheet styles, move your static styles into Unistyles to avoid conflicts.)");
|
40
|
+
}
|
41
|
+
|
42
|
+
return obj.getNativeState<UnistyleWrapper>(rt)->unistyle;
|
25
43
|
}
|
26
44
|
|
27
45
|
inline static jsi::Value valueFromUnistyle(jsi::Runtime& rt, Unistyle::Shared unistyle) {
|
@@ -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
|
|
@@ -105,13 +110,11 @@ core::DependencyMap core::UnistylesRegistry::buildDependencyMap(jsi::Runtime& rt
|
|
105
110
|
DependencyMap dependencyMap;
|
106
111
|
std::set<UnistyleDependency> uniqueDependencies(deps.begin(), deps.end());
|
107
112
|
|
108
|
-
for (const auto& [
|
109
|
-
for (const auto&
|
110
|
-
// check if in the given stylesheet we have unistyle
|
111
|
-
// that depends on something affected
|
113
|
+
for (const auto& [family, unistyles] : this->_shadowRegistry[&rt]) {
|
114
|
+
for (const auto& unistyleData : unistyles) {
|
112
115
|
bool hasAnyOfDependencies = std::any_of(
|
113
|
-
unistyle->dependencies.begin(),
|
114
|
-
unistyle->dependencies.end(),
|
116
|
+
unistyleData->unistyle->dependencies.begin(),
|
117
|
+
unistyleData->unistyle->dependencies.end(),
|
115
118
|
[&uniqueDependencies](UnistyleDependency dep) {
|
116
119
|
return std::find(uniqueDependencies.begin(), uniqueDependencies.end(), dep) != uniqueDependencies.end();
|
117
120
|
}
|
@@ -121,18 +124,13 @@ core::DependencyMap core::UnistylesRegistry::buildDependencyMap(jsi::Runtime& rt
|
|
121
124
|
continue;
|
122
125
|
}
|
123
126
|
|
124
|
-
//
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
for (const auto& unistyleData : unistyles) {
|
129
|
-
if (unistyle != unistyleData->unistyle) {
|
130
|
-
continue;
|
131
|
-
}
|
132
|
-
|
133
|
-
dependencyMap[styleSheet][family].emplace_back(unistyleData);
|
134
|
-
}
|
127
|
+
// we need to take in count all unistyles from the shadowNode
|
128
|
+
// as user might be using spreads and not all of them may have dependencies
|
129
|
+
for (const auto& unistyleData : unistyles) {
|
130
|
+
dependencyMap[family].emplace_back(unistyleData);
|
135
131
|
}
|
132
|
+
|
133
|
+
break;
|
136
134
|
}
|
137
135
|
}
|
138
136
|
|
@@ -142,19 +140,9 @@ core::DependencyMap core::UnistylesRegistry::buildDependencyMap(jsi::Runtime& rt
|
|
142
140
|
core::DependencyMap core::UnistylesRegistry::buildDependencyMap(jsi::Runtime& rt) {
|
143
141
|
DependencyMap dependencyMap;
|
144
142
|
|
145
|
-
for (const auto& [
|
146
|
-
for (const auto&
|
147
|
-
|
148
|
-
const auto& [family, unistyles] = pair;
|
149
|
-
|
150
|
-
for (const auto& unistyleData : unistyles) {
|
151
|
-
if (unistyle != unistyleData->unistyle) {
|
152
|
-
continue;
|
153
|
-
}
|
154
|
-
|
155
|
-
dependencyMap[styleSheet][family].emplace_back(unistyleData);
|
156
|
-
}
|
157
|
-
}
|
143
|
+
for (const auto& [family, unistyles] : this->_shadowRegistry[&rt]) {
|
144
|
+
for (const auto& unistyleData : unistyles) {
|
145
|
+
dependencyMap[family].emplace_back(unistyleData);
|
158
146
|
}
|
159
147
|
}
|
160
148
|
|
@@ -19,10 +19,7 @@ struct UnistylesState;
|
|
19
19
|
using namespace facebook;
|
20
20
|
using namespace facebook::react;
|
21
21
|
|
22
|
-
using DependencyMap = std::unordered_map<
|
23
|
-
std::shared_ptr<core::StyleSheet>,
|
24
|
-
std::unordered_map<const ShadowNodeFamily*, std::vector<std::shared_ptr<UnistyleData>>>
|
25
|
-
>;
|
22
|
+
using DependencyMap = std::unordered_map<const ShadowNodeFamily*, std::vector<std::shared_ptr<UnistyleData>>>;
|
26
23
|
|
27
24
|
struct UnistylesRegistry: public StyleSheetRegistry {
|
28
25
|
static UnistylesRegistry& get();
|
@@ -38,8 +35,8 @@ struct UnistylesRegistry: public StyleSheetRegistry {
|
|
38
35
|
|
39
36
|
UnistylesState& getState(jsi::Runtime& rt);
|
40
37
|
void createState(jsi::Runtime& rt);
|
41
|
-
void linkShadowNodeWithUnistyle(const ShadowNodeFamily*, const core::Unistyle::Shared, Variants& variants, std::vector<folly::dynamic>&);
|
42
|
-
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);
|
43
40
|
std::shared_ptr<core::StyleSheet> addStyleSheet(jsi::Runtime& rt, int tag, core::StyleSheetType type, jsi::Object&& rawValue);
|
44
41
|
DependencyMap buildDependencyMap(jsi::Runtime& rt, std::vector<UnistyleDependency>& deps);
|
45
42
|
DependencyMap buildDependencyMap(jsi::Runtime& rt);
|
@@ -49,7 +46,7 @@ private:
|
|
49
46
|
|
50
47
|
std::unordered_map<jsi::Runtime*, UnistylesState> _states{};
|
51
48
|
std::unordered_map<jsi::Runtime*, std::unordered_map<int, std::shared_ptr<core::StyleSheet>>> _styleSheetRegistry{};
|
52
|
-
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{};
|
53
50
|
};
|
54
51
|
|
55
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
|
}
|
@@ -5,29 +5,29 @@ using namespace facebook::react;
|
|
5
5
|
|
6
6
|
jsi::Value HybridShadowRegistry::link(jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) {
|
7
7
|
helpers::assertThat(rt, count == 4, "Unistyles: Invalid babel transform 'ShadowRegistry link' expected 4 arguments.");
|
8
|
-
|
8
|
+
|
9
9
|
ShadowNode::Shared shadowNodeWrapper = shadowNodeFromValue(rt, args[0]);
|
10
10
|
core::Unistyle::Shared unistyleWrapper = core::unistyleFromValue(rt, args[1]);
|
11
11
|
core::Variants variants = helpers::variantsToPairs(rt, args[2].asObject(rt));
|
12
12
|
auto rawArguments = args[3].asObject(rt).asArray(rt);
|
13
13
|
std::vector<folly::dynamic> arguments = helpers::parseDynamicFunctionArguments(rt, rawArguments);
|
14
|
-
|
14
|
+
|
15
15
|
auto& registry = core::UnistylesRegistry::get();
|
16
|
-
|
17
|
-
registry.linkShadowNodeWithUnistyle(&shadowNodeWrapper->getFamily(), unistyleWrapper, variants, arguments);
|
18
|
-
|
16
|
+
|
17
|
+
registry.linkShadowNodeWithUnistyle(rt, &shadowNodeWrapper->getFamily(), unistyleWrapper, variants, arguments);
|
18
|
+
|
19
19
|
return jsi::Value::undefined();
|
20
20
|
}
|
21
21
|
|
22
22
|
jsi::Value HybridShadowRegistry::unlink(jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) {
|
23
23
|
helpers::assertThat(rt, count == 2, "Unistyles: Invalid babel transform 'ShadowRegistry unlink' expected 2 arguments.");
|
24
|
-
|
24
|
+
|
25
25
|
ShadowNode::Shared shadowNodeWrapper = shadowNodeFromValue(rt, args[0]);
|
26
26
|
core::Unistyle::Shared unistyleWrapper = core::unistyleFromValue(rt, args[1]);
|
27
|
-
|
27
|
+
|
28
28
|
auto& registry = core::UnistylesRegistry::get();
|
29
29
|
|
30
|
-
registry.unlinkShadowNodeWithUnistyle(&shadowNodeWrapper->getFamily(), unistyleWrapper);
|
31
|
-
|
30
|
+
registry.unlinkShadowNodeWithUnistyle(rt, &shadowNodeWrapper->getFamily(), unistyleWrapper);
|
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
@@ -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
|
}
|
@@ -98,22 +100,22 @@ void parser::Parser::rebuildUnistylesWithVariants(jsi::Runtime& rt, std::shared_
|
|
98
100
|
|
99
101
|
// rebuild all unistyles that are affected by platform event
|
100
102
|
void parser::Parser::rebuildUnistylesInDependencyMap(jsi::Runtime& rt, DependencyMap& dependencyMap) {
|
101
|
-
for (auto& [
|
103
|
+
for (auto& [shadowNode, unistyles] : dependencyMap) {
|
104
|
+
auto styleSheet = unistyles.begin()->get()->unistyle->parent;
|
105
|
+
|
102
106
|
jsi::Object unwrappedStyleSheet = this->unwrapStyleSheet(rt, styleSheet);
|
103
107
|
|
104
|
-
for (auto&
|
105
|
-
|
106
|
-
auto& unistyle = unistyleData->unistyle;
|
108
|
+
for (auto& unistyleData : unistyles) {
|
109
|
+
auto& unistyle = unistyleData->unistyle;
|
107
110
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
}
|
112
|
-
|
113
|
-
unistyle->rawValue = unwrappedStyleSheet.getProperty(rt, unistyle->styleKey.c_str()).asObject(rt);
|
114
|
-
this->rebuildUnistyle(rt, styleSheet, unistyle, unistyleData->variants, unistyleData->dynamicFunctionMetadata);
|
115
|
-
unistyleData->parsedStyle = jsi::Value(rt, unistyle->parsedStyle.value()).asObject(rt);
|
111
|
+
// StyleSheet might have styles that are not affected
|
112
|
+
if (!unwrappedStyleSheet.hasProperty(rt, unistyle->styleKey.c_str())) {
|
113
|
+
continue;
|
116
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);
|
117
119
|
}
|
118
120
|
}
|
119
121
|
}
|
@@ -148,7 +150,7 @@ void parser::Parser::rebuildUnistyle(jsi::Runtime& rt, std::shared_ptr<StyleShee
|
|
148
150
|
// call cached function with memoized arguments
|
149
151
|
auto functionResult = unistyleFn->rawValue
|
150
152
|
.asFunction(rt)
|
151
|
-
.
|
153
|
+
.call(rt, argStart, dynamicFunctionMetadata.size())
|
152
154
|
.asObject(rt);
|
153
155
|
|
154
156
|
unistyleFn->unprocessedValue = std::move(functionResult);
|
@@ -160,21 +162,11 @@ void parser::Parser::rebuildUnistyle(jsi::Runtime& rt, std::shared_ptr<StyleShee
|
|
160
162
|
shadow::ShadowLeafUpdates parser::Parser::dependencyMapToShadowLeafUpdates(core::DependencyMap& dependencyMap) {
|
161
163
|
shadow::ShadowLeafUpdates updates;
|
162
164
|
auto& rt = this->_unistylesRuntime->getRuntime();
|
163
|
-
|
164
|
-
for (const auto& [
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
if (updates.contains(shadowNode)) {
|
170
|
-
updates[shadowNode].emplace_back(std::move(rawProps));
|
171
|
-
|
172
|
-
continue;
|
173
|
-
}
|
174
|
-
|
175
|
-
updates.emplace(shadowNode, std::vector<RawProps>{std::move(rawProps)});
|
176
|
-
}
|
177
|
-
}
|
165
|
+
|
166
|
+
for (const auto& [shadowNode, unistyles] : dependencyMap) {
|
167
|
+
auto rawProps = this->parseStylesToShadowTreeStyles(rt, unistyles);
|
168
|
+
|
169
|
+
updates.emplace(shadowNode, std::move(rawProps));
|
178
170
|
}
|
179
171
|
|
180
172
|
return updates;
|
@@ -539,7 +531,9 @@ bool parser::Parser::shouldApplyCompoundVariants(jsi::Runtime& rt, const Variant
|
|
539
531
|
auto property = compoundVariant.getProperty(rt, variantKey.c_str());
|
540
532
|
auto propertyName = property.isBool()
|
541
533
|
? (property.asBool() ? "true" : "false")
|
542
|
-
: property.
|
534
|
+
: property.isString()
|
535
|
+
? property.asString(rt).utf8(rt)
|
536
|
+
: "";
|
543
537
|
|
544
538
|
if (propertyName != variantValue) {
|
545
539
|
return false;
|
@@ -617,18 +611,20 @@ jsi::Value parser::Parser::parseSecondLevel(jsi::Runtime &rt, Unistyle::Shared u
|
|
617
611
|
return parsedStyle;
|
618
612
|
}
|
619
613
|
|
620
|
-
// convert
|
621
|
-
RawProps parser::Parser::parseStylesToShadowTreeStyles(jsi::Runtime& rt, const
|
614
|
+
// convert unistyles to RawValue with int colors
|
615
|
+
RawProps parser::Parser::parseStylesToShadowTreeStyles(jsi::Runtime& rt, const std::vector<std::shared_ptr<UnistyleData>>& unistyles) {
|
622
616
|
jsi::Object convertedStyles = jsi::Object(rt);
|
623
617
|
auto& state = core::UnistylesRegistry::get().getState(rt);
|
618
|
+
|
619
|
+
for (const auto& unistyleData : unistyles) {
|
620
|
+
helpers::enumerateJSIObject(rt, unistyleData->parsedStyle.value(), [&](const std::string& propertyName, jsi::Value& propertyValue){
|
621
|
+
if (this->isColor(propertyName)) {
|
622
|
+
return convertedStyles.setProperty(rt, propertyName.c_str(), jsi::Value(state.parseColor(propertyValue)));
|
623
|
+
}
|
624
624
|
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
}
|
629
|
-
|
630
|
-
convertedStyles.setProperty(rt, propertyName.c_str(), propertyValue);
|
631
|
-
});
|
625
|
+
convertedStyles.setProperty(rt, propertyName.c_str(), propertyValue);
|
626
|
+
});
|
627
|
+
}
|
632
628
|
|
633
629
|
return RawProps(rt, std::move(convertedStyles));
|
634
630
|
}
|
package/cxx/parser/Parser.h
CHANGED
@@ -40,7 +40,7 @@ private:
|
|
40
40
|
jsi::Value getStylesForVariant(jsi::Runtime& rt, const std::string groupName, jsi::Object&& groupValue, std::optional<std::string> selectedVariant, Variants& variants);
|
41
41
|
jsi::Object parseCompoundVariants(jsi::Runtime& rt, Unistyle::Shared unistyle, jsi::Object& obj, Variants& variants);
|
42
42
|
bool shouldApplyCompoundVariants(jsi::Runtime& rt, const Variants& variants, jsi::Object& compoundVariant);
|
43
|
-
RawProps parseStylesToShadowTreeStyles(jsi::Runtime& rt, const
|
43
|
+
RawProps parseStylesToShadowTreeStyles(jsi::Runtime& rt, const std::vector<std::shared_ptr<UnistyleData>>& unistyles);
|
44
44
|
bool isColor(const std::string& propertyName);
|
45
45
|
|
46
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({
|
@@ -15,7 +15,7 @@ const findShadowNodeForHandle = handle => {
|
|
15
15
|
return node;
|
16
16
|
};
|
17
17
|
HybridShadowRegistry.add = (handle, style, variants, args) => {
|
18
|
-
if (!handle
|
18
|
+
if (!handle) {
|
19
19
|
return;
|
20
20
|
}
|
21
21
|
HybridShadowRegistry.link(findShadowNodeForHandle(handle), style, variants ?? {}, args ?? []);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_reactNativeNitroModules","require","HybridShadowRegistry","NitroModules","createHybridObject","findShadowNodeForHandle","handle","node","__internalInstanceHandle","stateNode","getScrollResponder","getNativeScrollRef","Error","add","style","variants","args","
|
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":[]}
|
@@ -11,7 +11,7 @@ const findShadowNodeForHandle = handle => {
|
|
11
11
|
return node;
|
12
12
|
};
|
13
13
|
HybridShadowRegistry.add = (handle, style, variants, args) => {
|
14
|
-
if (!handle
|
14
|
+
if (!handle) {
|
15
15
|
return;
|
16
16
|
}
|
17
17
|
HybridShadowRegistry.link(findShadowNodeForHandle(handle), style, variants ?? {}, args ?? []);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["NitroModules","HybridShadowRegistry","createHybridObject","findShadowNodeForHandle","handle","node","__internalInstanceHandle","stateNode","getScrollResponder","getNativeScrollRef","Error","add","style","variants","args","
|
1
|
+
{"version":3,"names":["NitroModules","HybridShadowRegistry","createHybridObject","findShadowNodeForHandle","handle","node","__internalInstanceHandle","stateNode","getScrollResponder","getNativeScrollRef","Error","add","style","variants","args","link","remove","__unid","unlink","UnistylesShadowRegistry"],"sourceRoot":"../../../../src","sources":["specs/ShadowRegistry/index.ts"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;AAazD,MAAMC,oBAAoB,GAAGD,YAAY,CAACE,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;AAEDJ,oBAAoB,CAACU,GAAG,GAAG,CAACP,MAAM,EAAEQ,KAAK,EAAEC,QAAQ,EAAEC,IAAI,KAAK;EAC1D,IAAI,CAACV,MAAM,EAAE;IACT;EACJ;EAEAH,oBAAoB,CAACc,IAAI,CAACZ,uBAAuB,CAACC,MAAM,CAAC,EAAEQ,KAAK,EAAEC,QAAQ,IAAI,CAAC,CAAC,EAAEC,IAAI,IAAI,EAAE,CAAC;AACjG,CAAC;AAEDb,oBAAoB,CAACe,MAAM,GAAG,CAACZ,MAAM,EAAEQ,KAAK,KAAK;EAC7C,IAAI,CAACR,MAAM,IAAI,CAACQ,KAAK,EAAEK,MAAM,EAAE;IAC3B;EACJ;EAEAhB,oBAAoB,CAACiB,MAAM,CAACf,uBAAuB,CAACC,MAAM,CAAC,EAAEQ,KAAK,CAAC;AACvE,CAAC;AAQD,OAAO,MAAMO,uBAAuB,GAAGlB,oBAA4D","ignoreList":[]}
|
@@ -3,7 +3,7 @@ import type { ShadowNode, Unistyle, ViewHandle } from './types';
|
|
3
3
|
interface ShadowRegistry extends UnistylesShadowRegistrySpec {
|
4
4
|
add(handle?: ViewHandle, style?: Unistyle, variants?: Record<string, string | boolean>, args?: Array<any>): void;
|
5
5
|
remove(handle?: ViewHandle, style?: Unistyle): void;
|
6
|
-
link(node: ShadowNode, style
|
6
|
+
link(node: ShadowNode, style?: Unistyle, variants?: Record<string, string | boolean>, args?: Array<any>): void;
|
7
7
|
unlink(node: ShadowNode, style: Unistyle): void;
|
8
8
|
}
|
9
9
|
type PrivateMethods = 'add' | 'remove' | 'link' | 'unlink';
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/specs/ShadowRegistry/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,IAAI,2BAA2B,EAAE,MAAM,wBAAwB,CAAA;AACpG,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAE/D,UAAU,cAAe,SAAQ,2BAA2B;IAExD,GAAG,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IACjH,MAAM,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;IAEpD,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/specs/ShadowRegistry/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,IAAI,2BAA2B,EAAE,MAAM,wBAAwB,CAAA;AACpG,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAE/D,UAAU,cAAe,SAAQ,2BAA2B;IAExD,GAAG,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IACjH,MAAM,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;IAEpD,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IAC/G,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAA;CAClD;AAiCD,KAAK,cAAc,GACb,KAAK,GACL,QAAQ,GACR,MAAM,GACN,QAAQ,CAAA;AAEd,eAAO,MAAM,uBAAuB,EAA2B,IAAI,CAAC,cAAc,EAAE,cAAc,CAAC,CAAA"}
|