1*023bc8eaSKudo Chien #pragma once 2*023bc8eaSKudo Chien 3*023bc8eaSKudo Chien #include <unistd.h> 4*023bc8eaSKudo Chien #include <memory> 5*023bc8eaSKudo Chien #include <string> 6*023bc8eaSKudo Chien #include <vector> 7*023bc8eaSKudo Chien 8*023bc8eaSKudo Chien #include "AnimatedSensorModule.h" 9*023bc8eaSKudo Chien #include "ErrorHandler.h" 10*023bc8eaSKudo Chien #include "LayoutAnimationsProxy.h" 11*023bc8eaSKudo Chien #include "NativeReanimatedModuleSpec.h" 12*023bc8eaSKudo Chien #include "PlatformDepMethodsHolder.h" 13*023bc8eaSKudo Chien #include "RuntimeDecorator.h" 14*023bc8eaSKudo Chien #include "RuntimeManager.h" 15*023bc8eaSKudo Chien #include "Scheduler.h" 16*023bc8eaSKudo Chien #include "SingleInstanceChecker.h" 17*023bc8eaSKudo Chien 18*023bc8eaSKudo Chien namespace reanimated { 19*023bc8eaSKudo Chien 20*023bc8eaSKudo Chien using FrameCallback = std::function<void(double)>; 21*023bc8eaSKudo Chien 22*023bc8eaSKudo Chien class ShareableValue; 23*023bc8eaSKudo Chien class MutableValue; 24*023bc8eaSKudo Chien class MapperRegistry; 25*023bc8eaSKudo Chien class EventHandlerRegistry; 26*023bc8eaSKudo Chien 27*023bc8eaSKudo Chien class NativeReanimatedModule : public NativeReanimatedModuleSpec, 28*023bc8eaSKudo Chien public RuntimeManager { 29*023bc8eaSKudo Chien friend ShareableValue; 30*023bc8eaSKudo Chien friend MutableValue; 31*023bc8eaSKudo Chien 32*023bc8eaSKudo Chien public: 33*023bc8eaSKudo Chien NativeReanimatedModule( 34*023bc8eaSKudo Chien std::shared_ptr<CallInvoker> jsInvoker, 35*023bc8eaSKudo Chien std::shared_ptr<Scheduler> scheduler, 36*023bc8eaSKudo Chien std::shared_ptr<jsi::Runtime> rt, 37*023bc8eaSKudo Chien std::shared_ptr<ErrorHandler> errorHandler, 38*023bc8eaSKudo Chien std::function<jsi::Value(jsi::Runtime &, const int, const jsi::String &)> 39*023bc8eaSKudo Chien propObtainer, 40*023bc8eaSKudo Chien std::shared_ptr<LayoutAnimationsProxy> layoutAnimationsProxy, 41*023bc8eaSKudo Chien PlatformDepMethodsHolder platformDepMethodsHolder); 42*023bc8eaSKudo Chien 43*023bc8eaSKudo Chien void installCoreFunctions(jsi::Runtime &rt, const jsi::Value &valueSetter) 44*023bc8eaSKudo Chien override; 45*023bc8eaSKudo Chien 46*023bc8eaSKudo Chien jsi::Value makeShareable(jsi::Runtime &rt, const jsi::Value &value) override; 47*023bc8eaSKudo Chien jsi::Value makeMutable(jsi::Runtime &rt, const jsi::Value &value) override; 48*023bc8eaSKudo Chien jsi::Value makeRemote(jsi::Runtime &rt, const jsi::Value &value) override; 49*023bc8eaSKudo Chien 50*023bc8eaSKudo Chien jsi::Value startMapper( 51*023bc8eaSKudo Chien jsi::Runtime &rt, 52*023bc8eaSKudo Chien const jsi::Value &worklet, 53*023bc8eaSKudo Chien const jsi::Value &inputs, 54*023bc8eaSKudo Chien const jsi::Value &outputs, 55*023bc8eaSKudo Chien const jsi::Value &updater, 56*023bc8eaSKudo Chien const jsi::Value &viewDescriptors) override; 57*023bc8eaSKudo Chien void stopMapper(jsi::Runtime &rt, const jsi::Value &mapperId) override; 58*023bc8eaSKudo Chien 59*023bc8eaSKudo Chien jsi::Value registerEventHandler( 60*023bc8eaSKudo Chien jsi::Runtime &rt, 61*023bc8eaSKudo Chien const jsi::Value &eventHash, 62*023bc8eaSKudo Chien const jsi::Value &worklet) override; 63*023bc8eaSKudo Chien void unregisterEventHandler( 64*023bc8eaSKudo Chien jsi::Runtime &rt, 65*023bc8eaSKudo Chien const jsi::Value ®istrationId) override; 66*023bc8eaSKudo Chien 67*023bc8eaSKudo Chien jsi::Value getViewProp( 68*023bc8eaSKudo Chien jsi::Runtime &rt, 69*023bc8eaSKudo Chien const jsi::Value &viewTag, 70*023bc8eaSKudo Chien const jsi::Value &propName, 71*023bc8eaSKudo Chien const jsi::Value &callback) override; 72*023bc8eaSKudo Chien 73*023bc8eaSKudo Chien jsi::Value enableLayoutAnimations(jsi::Runtime &rt, const jsi::Value &config) 74*023bc8eaSKudo Chien override; 75*023bc8eaSKudo Chien jsi::Value configureProps( 76*023bc8eaSKudo Chien jsi::Runtime &rt, 77*023bc8eaSKudo Chien const jsi::Value &uiProps, 78*023bc8eaSKudo Chien const jsi::Value &nativeProps) override; 79*023bc8eaSKudo Chien 80*023bc8eaSKudo Chien void onRender(double timestampMs); 81*023bc8eaSKudo Chien void onEvent(std::string eventName, std::string eventAsString); 82*023bc8eaSKudo Chien bool isAnyHandlerWaitingForEvent(std::string eventName); 83*023bc8eaSKudo Chien 84*023bc8eaSKudo Chien void maybeRequestRender(); 85*023bc8eaSKudo Chien UpdaterFunction updaterFunction; 86*023bc8eaSKudo Chien 87*023bc8eaSKudo Chien jsi::Value registerSensor( 88*023bc8eaSKudo Chien jsi::Runtime &rt, 89*023bc8eaSKudo Chien const jsi::Value &sensorType, 90*023bc8eaSKudo Chien const jsi::Value &interval, 91*023bc8eaSKudo Chien const jsi::Value &sensorDataContainer) override; 92*023bc8eaSKudo Chien void unregisterSensor(jsi::Runtime &rt, const jsi::Value &sensorId) override; 93*023bc8eaSKudo Chien jsi::Value subscribeForKeyboardEvents( 94*023bc8eaSKudo Chien jsi::Runtime &rt, 95*023bc8eaSKudo Chien const jsi::Value &keyboardEventContainer) override; 96*023bc8eaSKudo Chien void unsubscribeFromKeyboardEvents( 97*023bc8eaSKudo Chien jsi::Runtime &rt, 98*023bc8eaSKudo Chien const jsi::Value &listenerId) override; 99*023bc8eaSKudo Chien 100*023bc8eaSKudo Chien private: 101*023bc8eaSKudo Chien std::shared_ptr<MapperRegistry> mapperRegistry; 102*023bc8eaSKudo Chien std::shared_ptr<EventHandlerRegistry> eventHandlerRegistry; 103*023bc8eaSKudo Chien std::function<void(FrameCallback &, jsi::Runtime &)> requestRender; 104*023bc8eaSKudo Chien std::shared_ptr<jsi::Value> dummyEvent; 105*023bc8eaSKudo Chien std::vector<FrameCallback> frameCallbacks; 106*023bc8eaSKudo Chien bool renderRequested = false; 107*023bc8eaSKudo Chien std::function<jsi::Value(jsi::Runtime &, const int, const jsi::String &)> 108*023bc8eaSKudo Chien propObtainer; 109*023bc8eaSKudo Chien std::function<void(double)> onRenderCallback; 110*023bc8eaSKudo Chien std::shared_ptr<LayoutAnimationsProxy> layoutAnimationsProxy; 111*023bc8eaSKudo Chien AnimatedSensorModule animatedSensorModule; 112*023bc8eaSKudo Chien ConfigurePropsFunction configurePropsPlatformFunction; 113*023bc8eaSKudo Chien KeyboardEventSubscribeFunction subscribeForKeyboardEventsFunction; 114*023bc8eaSKudo Chien KeyboardEventUnsubscribeFunction unsubscribeFromKeyboardEventsFunction; 115*023bc8eaSKudo Chien 116*023bc8eaSKudo Chien #ifdef DEBUG 117*023bc8eaSKudo Chien SingleInstanceChecker<NativeReanimatedModule> singleInstanceChecker_; 118*023bc8eaSKudo Chien #endif 119*023bc8eaSKudo Chien }; 120*023bc8eaSKudo Chien 121*023bc8eaSKudo Chien } // namespace reanimated 122