1 #pragma once
2 
3 #include <jsi/jsi.h>
4 #include <memory>
5 #include <mutex>
6 #include <string>
7 #include <unordered_map>
8 #include <vector>
9 #include "AnimatedSensorModule.h"
10 #include "HostFunctionHandler.h"
11 #include "JSIStoreValueUser.h"
12 #include "LayoutAnimationsProxy.h"
13 #include "RuntimeManager.h"
14 #include "Scheduler.h"
15 #include "SharedParent.h"
16 #include "ValueWrapper.h"
17 #include "WorkletsCache.h"
18 
19 using namespace facebook;
20 
21 namespace reanimated {
22 
23 class ShareableValue : public std::enable_shared_from_this<ShareableValue>,
24                        public StoreUser {
25   friend WorkletsCache;
26   friend FrozenObject;
27   friend LayoutAnimationsProxy;
28   friend NativeReanimatedModule;
29   friend AnimatedSensorModule;
30   friend void extractMutables(
31       jsi::Runtime &rt,
32       std::shared_ptr<ShareableValue> sv,
33       std::vector<std::shared_ptr<MutableValue>> &res);
34 
35  private:
36   RuntimeManager *runtimeManager;
37   std::unique_ptr<ValueWrapper> valueContainer;
38   std::unique_ptr<jsi::Value> hostValue;
39   std::weak_ptr<jsi::Value> remoteValue;
40   bool containsHostFunction = false;
41 
ShareableValue(RuntimeManager * runtimeManager,std::shared_ptr<Scheduler> s)42   ShareableValue(RuntimeManager *runtimeManager, std::shared_ptr<Scheduler> s)
43       : StoreUser(s, *runtimeManager), runtimeManager(runtimeManager) {}
44 
45   jsi::Value toJSValue(jsi::Runtime &rt);
46   jsi::Object createHost(
47       jsi::Runtime &rt,
48       std::shared_ptr<jsi::HostObject> host);
49   void adapt(jsi::Runtime &rt, const jsi::Value &value, ValueType objectType);
50   void adaptCache(jsi::Runtime &rt, const jsi::Value &value);
51   std::string demangleExceptionName(std::string toDemangle);
52 
53  public:
54   ValueType type = ValueType::UndefinedType;
55   static std::shared_ptr<ShareableValue> adapt(
56       jsi::Runtime &rt,
57       const jsi::Value &value,
58       RuntimeManager *runtimeManager,
59       ValueType objectType = ValueType::UndefinedType);
60   jsi::Value getValue(jsi::Runtime &rt);
61 };
62 
63 } // namespace reanimated
64