react-native-unistyles 3.0.0-alpha.15 → 3.0.0-alpha.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -88,8 +88,14 @@ int core::UnistylesState::parseColor(jsi::Value& maybeColor) {
88
88
  return 0;
89
89
  }
90
90
 
91
- // we must convert it to uint32_t first, otherwise color will be broken
92
- uint32_t color = this->_processColorFn.get()->call(*_rt, maybeColor.asString(*_rt)).asNumber();
93
-
94
- return color ? color : 0;
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
  };
@@ -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 && !selectedVariant.has_value()) {
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
@@ -1,3 +1,4 @@
1
1
  #pragma once
2
2
 
3
+ #import "jsi/jsi.h"
3
4
  #import <React/RCTUtils.h>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "3.0.0-alpha.15",
3
+ "version": "3.0.0-alpha.17",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "jest",