react-native-unistyles 3.0.0-alpha.15 → 3.0.0-alpha.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cxx/core/UnistylesState.cpp +10 -4
- package/cxx/core/UnistylesState.h +1 -0
- package/cxx/parser/Parser.cpp +7 -2
- package/ios/Unistyles.h +1 -0
- package/package.json +1 -1
@@ -88,8 +88,14 @@ int core::UnistylesState::parseColor(jsi::Value& maybeColor) {
|
|
88
88
|
return 0;
|
89
89
|
}
|
90
90
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
91
|
+
auto colorString = maybeColor.asString(*_rt);
|
92
|
+
|
93
|
+
if (!this->_colorCache.contains(colorString.utf8(*_rt).c_str())) {
|
94
|
+
// we must convert it to uint32_t first, otherwise color will be broken
|
95
|
+
uint32_t color = this->_processColorFn.get()->call(*_rt, colorString).asNumber();
|
96
|
+
|
97
|
+
this->_colorCache[colorString.utf8(*_rt).c_str()] = color ? color : 0;
|
98
|
+
}
|
99
|
+
|
100
|
+
return this->_colorCache[colorString.utf8(*_rt).c_str()];
|
95
101
|
}
|
@@ -43,6 +43,7 @@ private:
|
|
43
43
|
std::vector<std::string> _registeredThemeNames{};
|
44
44
|
std::optional<std::string> _currentThemeName = std::nullopt;
|
45
45
|
std::shared_ptr<jsi::Function> _processColorFn;
|
46
|
+
std::unordered_map<std::string, uint32_t> _colorCache{};
|
46
47
|
|
47
48
|
friend class UnistylesRegistry;
|
48
49
|
};
|
package/cxx/parser/Parser.cpp
CHANGED
@@ -479,8 +479,8 @@ jsi::Value parser::Parser::getStylesForVariant(jsi::Runtime& rt, const std::stri
|
|
479
479
|
: "default";
|
480
480
|
auto hasKey = groupValue.hasProperty(rt, selectedVariantKey);
|
481
481
|
|
482
|
-
if (hasKey
|
483
|
-
// add 'default' selection to variants map
|
482
|
+
if (!hasKey || !selectedVariant.has_value()) {
|
483
|
+
// for no key, add 'default' selection to variants map
|
484
484
|
variants.emplace_back(groupName, selectedVariantKey);
|
485
485
|
}
|
486
486
|
|
@@ -621,6 +621,11 @@ RawProps parser::Parser::parseStylesToShadowTreeStyles(jsi::Runtime& rt, const s
|
|
621
621
|
auto& state = core::UnistylesRegistry::get().getState(rt);
|
622
622
|
|
623
623
|
for (const auto& unistyleData : unistyles) {
|
624
|
+
if (!unistyleData->parsedStyle.has_value()) {
|
625
|
+
// todo this something happens with large dataset, debug it
|
626
|
+
continue;
|
627
|
+
}
|
628
|
+
|
624
629
|
helpers::enumerateJSIObject(rt, unistyleData->parsedStyle.value(), [&](const std::string& propertyName, jsi::Value& propertyValue){
|
625
630
|
if (this->isColor(propertyName)) {
|
626
631
|
return convertedStyles.setProperty(rt, propertyName.c_str(), jsi::Value(state.parseColor(propertyValue)));
|
package/ios/Unistyles.h
CHANGED