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