1 #pragma once 2 3 #include <jsi/jsi.h> 4 #include <map> 5 #include <memory> 6 #include <mutex> 7 #include <vector> 8 #include "JSIStoreValueUser.h" 9 #include "LayoutAnimationsProxy.h" 10 #include "MutableValueSetterProxy.h" 11 #include "RuntimeManager.h" 12 #include "SharedParent.h" 13 14 using namespace facebook; 15 16 namespace reanimated { 17 18 class MutableValue : public jsi::HostObject, 19 public std::enable_shared_from_this<MutableValue>, 20 public StoreUser { 21 private: 22 friend MutableValueSetterProxy; 23 friend LayoutAnimationsProxy; 24 25 private: 26 RuntimeManager *runtimeManager; 27 std::mutex readWriteMutex; 28 std::shared_ptr<ShareableValue> value; 29 std::weak_ptr<jsi::Value> animation; 30 std::map<unsigned long, std::function<void()>> listeners; 31 32 public: 33 void setValue(jsi::Runtime &rt, const jsi::Value &newValue); 34 jsi::Value getValue(jsi::Runtime &rt); 35 36 public: 37 MutableValue( 38 jsi::Runtime &rt, 39 const jsi::Value &initial, 40 RuntimeManager *runtimeManager, 41 std::shared_ptr<Scheduler> s); 42 43 public: 44 void 45 set(jsi::Runtime &rt, const jsi::PropNameID &name, const jsi::Value &value); 46 jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &name); 47 std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt); 48 unsigned long addListener( 49 unsigned long listenerId, 50 std::function<void()> listener); 51 void removeListener(unsigned long listenerId); 52 }; 53 54 } // namespace reanimated 55