1 // Copyright 2022-present 650 Industries. All rights reserved.
2
3 #include "ExpoViewProps.h"
4 #include <react/renderer/core/propsConversions.h>
5
6 namespace react = facebook::react;
7
8 namespace expo {
9
10 /**
11 Borrows the props map from the source props and applies the update given in the raw props.
12 */
propsMapFromProps(const ExpoViewProps & sourceProps,const react::RawProps & rawProps)13 std::unordered_map<std::string, folly::dynamic> propsMapFromProps(const ExpoViewProps &sourceProps, const react::RawProps &rawProps) {
14 // Move the contents of the source props map – the source props instance will not be used anymore.
15 std::unordered_map<std::string, folly::dynamic> propsMap = std::move(sourceProps.propsMap);
16
17 // Iterate over values in the raw props object.
18 // Note that it contains only updated props.
19 rawProps.iterateOverValues([&propsMap](react::RawPropsPropNameHash hash, const char *name, const react::RawValue &value) {
20 std::string propName(name);
21 propsMap[propName] = (folly::dynamic)value;
22 });
23
24 return propsMap;
25 }
26
ExpoViewProps(const react::PropsParserContext & context,const ExpoViewProps & sourceProps,const react::RawProps & rawProps)27 ExpoViewProps::ExpoViewProps(const react::PropsParserContext &context,
28 const ExpoViewProps &sourceProps,
29 const react::RawProps &rawProps)
30 : ViewProps(context, sourceProps, rawProps),
31 propsMap(propsMapFromProps(sourceProps, rawProps)) {}
32
33 } // namespace expo
34