1 #pragma once
2 
3 #include "ErrorHandler.h"
4 #include "LayoutAnimationType.h"
5 #include "Shareables.h"
6 
7 #include <jsi/jsi.h>
8 #include <stdio.h>
9 #include <functional>
10 #include <memory>
11 #include <mutex>
12 #include <string>
13 #include <unordered_map>
14 #include <vector>
15 
16 namespace reanimated {
17 
18 using namespace facebook;
19 
20 class LayoutAnimationsManager {
21  public:
22   void configureAnimation(
23       int tag,
24       LayoutAnimationType type,
25       const std::string &sharedTransitionTag,
26       std::shared_ptr<Shareable> config);
27   bool hasLayoutAnimation(int tag, LayoutAnimationType type);
28   void startLayoutAnimation(
29       jsi::Runtime &rt,
30       int tag,
31       LayoutAnimationType type,
32       const jsi::Object &values);
33   void clearLayoutAnimationConfig(int tag);
34   void cancelLayoutAnimation(
35       jsi::Runtime &rt,
36       int tag,
37       LayoutAnimationType type,
38       bool cancelled /* = true */,
39       bool removeView /* = true */);
40   int findPrecedingViewTagForTransition(int tag);
41 
42  private:
43   std::unordered_map<int, std::shared_ptr<Shareable>> &getConfigsForType(
44       LayoutAnimationType type);
45 
46   std::unordered_map<int, std::shared_ptr<Shareable>> enteringAnimations_;
47   std::unordered_map<int, std::shared_ptr<Shareable>> exitingAnimations_;
48   std::unordered_map<int, std::shared_ptr<Shareable>> layoutAnimations_;
49   std::unordered_map<int, std::shared_ptr<Shareable>>
50       sharedTransitionAnimations_;
51   std::unordered_map<std::string, std::vector<int>> sharedTransitionGroups_;
52   std::unordered_map<int, std::string> viewTagToSharedTag_;
53   mutable std::mutex
54       animationsMutex_; // Protects `enteringAnimations_`, `exitingAnimations_`,
55                         // `layoutAnimations_` and `viewSharedValues_`.
56 };
57 
58 } // namespace reanimated
59