diff --git a/ReactCommon/fabric/core/shadownode/propsConversions.h b/ReactCommon/fabric/core/shadownode/propsConversions.h index 290a3fa17..b03bdc138 100644 --- a/ReactCommon/fabric/core/shadownode/propsConversions.h +++ b/ReactCommon/fabric/core/shadownode/propsConversions.h @@ -69,5 +69,22 @@ inline T convertRawProp(const RawProps &rawProps, const std::string &name, const } } +template +inline static folly::Optional convertRawProp(const RawProps &rawProps, const std::string &name, const folly::Optional &defaultValue) { + auto &&iterator = rawProps.find(name); + if (iterator != rawProps.end()) { + auto &&value = iterator->second; + if (value.isNull()) { + return defaultValue; + } else { + T result; + fromDynamic(value, result); + return result; + } + } else { + return defaultValue; + } +} + } // namespace react } // namespace facebook diff --git a/ReactCommon/fabric/debug/debugStringConvertibleUtils.h b/ReactCommon/fabric/debug/debugStringConvertibleUtils.h index e95620858..22eca9acf 100644 --- a/ReactCommon/fabric/debug/debugStringConvertibleUtils.h +++ b/ReactCommon/fabric/debug/debugStringConvertibleUtils.h @@ -28,6 +28,14 @@ inline SharedDebugStringConvertible debugStringConvertibleItem(std::string name, return std::make_shared(name, toString(value)); } +template +inline SharedDebugStringConvertible debugStringConvertibleItem(std::string name, folly::Optional value, T defaultValue = {}) { + if (!value.has_value()) { + return nullptr; + } + return debugStringConvertibleItem(name, value.value_or(defaultValue), defaultValue); +} + SharedDebugStringConvertibleList operator+(const SharedDebugStringConvertibleList &lhs, const SharedDebugStringConvertibleList &rhs); SharedDebugStringConvertible debugStringConvertibleItem(std::string name, DebugStringConvertible value, std::string defaultValue = "");