diff --git a/ReactCommon/fabric/core/primitives/RawValue.h b/ReactCommon/fabric/core/primitives/RawValue.h index 2fd2821e98a..e5366cc902f 100644 --- a/ReactCommon/fabric/core/primitives/RawValue.h +++ b/ReactCommon/fabric/core/primitives/RawValue.h @@ -250,6 +250,19 @@ class RawValue { return result; } + template + static std::vector> castValue( + const folly::dynamic &dynamic, + std::vector> *type) noexcept { + assert(dynamic.isArray()); + auto result = std::vector>{}; + result.reserve(dynamic.size()); + for (const auto &item : dynamic) { + result.push_back(castValue(item, (std::vector *)nullptr)); + } + return result; + } + template static better::map castValue( const folly::dynamic &dynamic, diff --git a/ReactCommon/fabric/core/propsConversions.h b/ReactCommon/fabric/core/propsConversions.h index 1835a3dfb4f..a564b306c3b 100644 --- a/ReactCommon/fabric/core/propsConversions.h +++ b/ReactCommon/fabric/core/propsConversions.h @@ -46,6 +46,31 @@ void fromRawValue(RawValue const &rawValue, std::vector &result) { result.push_back(itemResult); } +template +void fromRawValue( + RawValue const &rawValue, + std::vector> &result) { + if (rawValue.hasType>>()) { + auto items = (std::vector>)rawValue; + auto length = items.size(); + result.clear(); + result.reserve(length); + for (int i = 0; i < length; i++) { + T itemResult; + fromRawValue(items.at(i), itemResult); + result.push_back(itemResult); + } + return; + } + + // The case where `value` is not an array. + result.clear(); + result.reserve(1); + T itemResult; + fromRawValue(rawValue, itemResult); + result.push_back(itemResult); +} + template T convertRawProp( RawProps const &rawProps,