1 #pragma once
2 #ifdef RCT_NEW_ARCH_ENABLED
3 
4 #include <react/renderer/core/ShadowNode.h>
5 #include <memory>
6 #include <unordered_map>
7 #include <utility>
8 
9 using namespace facebook::react;
10 
11 namespace reanimated {
12 
13 class NewestShadowNodesRegistry {
14  public:
15   std::lock_guard<std::mutex> createLock() const;
16   // returns a lock you need to hold when calling any of the methods below
17 
18   void set(ShadowNode::Shared shadowNode, Tag parentTag);
19   // updates ShadowNode and sets parent tag, to be called from Reanimated
20 
21   bool has(const ShadowNode::Shared &shadowNode) const;
22   // checks if ShadowNode exists in the registry
23 
24   ShadowNode::Shared get(Tag tag) const;
25   // returns the most recent version of ShadowNode or nullptr if not found
26 
27   void update(ShadowNode::Shared shadowNode);
28   // updates ShadowNode that already exists in registry, to be called from RN
29 
30   void remove(Tag tag);
31   // removes ShadowNode from map along with its ancestors
32 
33  private:
34   std::unordered_map<Tag, std::pair<ShadowNode::Shared, Tag>> map_;
35   // tag -> (most recent clone of shadow node, parent tag)
36   mutable std::mutex mutex_; // Protects `map_`.
37 };
38 
39 } // namespace reanimated
40 
41 #endif // RCT_NEW_ARCH_ENABLED
42