#pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace reanimated { using namespace facebook; using namespace css; using UpdatesBatch = std::vector, folly::dynamic>>; class ReanimatedModuleProxy : public ReanimatedModuleProxySpec, public std::enable_shared_from_this { public: ReanimatedModuleProxy( const std::shared_ptr &workletsModuleProxy, jsi::Runtime &rnRuntime, const std::shared_ptr &jsCallInvoker, const PlatformDepMethodsHolder &platformDepMethodsHolder, const bool isReducedMotion); // We need this init method to initialize callbacks with // weak_from_this() which is available only after the object // is fully constructed. void init(const PlatformDepMethodsHolder &platformDepMethodsHolder); ~ReanimatedModuleProxy(); jsi::Value registerEventHandler( jsi::Runtime &rt, const jsi::Value &worklet, const jsi::Value &eventName, const jsi::Value &emitterReactTag) override; void unregisterEventHandler( jsi::Runtime &rt, const jsi::Value ®istrationId) override; jsi::Value getViewProp( jsi::Runtime &rt, const jsi::Value &shadowNodeWrapper, const jsi::Value &propName, const jsi::Value &callback) override; jsi::Value getStaticFeatureFlag(jsi::Runtime &rt, const jsi::Value &name) override; jsi::Value setDynamicFeatureFlag( jsi::Runtime &rt, const jsi::Value &name, const jsi::Value &value) override; jsi::Value configureLayoutAnimationBatch( jsi::Runtime &rt, const jsi::Value &layoutAnimationsBatch) override; void setShouldAnimateExiting( jsi::Runtime &rt, const jsi::Value &viewTag, const jsi::Value &shouldAnimate) override; void onRender(double timestampMs); bool isAnyHandlerWaitingForEvent( const std::string &eventName, const int emitterReactTag); void maybeRequestRender(); bool handleEvent( const std::string &eventName, const int emitterReactTag, const jsi::Value &payload, double currentTime); inline std::shared_ptr getJSLogger() const { return jsLogger_; } bool handleRawEvent(const RawEvent &rawEvent, double currentTime); void maybeRunCSSLoop(); double getCssTimestamp(); void performOperations(); void performNonLayoutOperations(); void setViewStyle( jsi::Runtime &rt, const jsi::Value &viewTag, const jsi::Value &viewStyle) override; void markNodeAsRemovable( jsi::Runtime &rt, const jsi::Value &shadowNodeWrapper) override; void unmarkNodeAsRemovable(jsi::Runtime &rt, const jsi::Value &viewTag) override; void registerCSSKeyframes( jsi::Runtime &rt, const jsi::Value &animationName, const jsi::Value &viewName, const jsi::Value &keyframesConfig) override; void unregisterCSSKeyframes( jsi::Runtime &rt, const jsi::Value &animationName, const jsi::Value &viewName) override; void applyCSSAnimations( jsi::Runtime &rt, const jsi::Value &shadowNodeWrapper, const jsi::Value &animationUpdates) override; void unregisterCSSAnimations(const jsi::Value &viewTag) override; void registerCSSTransition( jsi::Runtime &rt, const jsi::Value &shadowNodeWrapper, const jsi::Value &transitionConfig) override; void updateCSSTransition( jsi::Runtime &rt, const jsi::Value &viewTag, const jsi::Value &configUpdates) override; void unregisterCSSTransition(jsi::Runtime &rt, const jsi::Value &viewTag) override; void cssLoopCallback(const double /*timestampMs*/); void dispatchCommand( jsi::Runtime &rt, const jsi::Value &shadowNodeValue, const jsi::Value &commandNameValue, const jsi::Value &argsValue); jsi::String obtainProp( jsi::Runtime &rt, const jsi::Value &shadowNodeWrapper, const jsi::Value &propName); jsi::Value measure(jsi::Runtime &rt, const jsi::Value &shadowNodeValue); void initializeFabric(const std::shared_ptr &uiManager); void initializeLayoutAnimationsProxy(); std::string obtainPropFromShadowNode( jsi::Runtime &rt, const std::string &propName, const std::shared_ptr &shadowNode); jsi::Value registerSensor( jsi::Runtime &rt, const jsi::Value &sensorType, const jsi::Value &interval, const jsi::Value &iosReferenceFrame, const jsi::Value &sensorDataContainer) override; void unregisterSensor(jsi::Runtime &rt, const jsi::Value &sensorId) override; void cleanupSensors(); jsi::Value subscribeForKeyboardEvents( jsi::Runtime &rt, const jsi::Value &keyboardEventContainer, const jsi::Value &isStatusBarTranslucent, const jsi::Value &isNavigationBarTranslucent) override; void unsubscribeFromKeyboardEvents( jsi::Runtime &rt, const jsi::Value &listenerId) override; inline LayoutAnimationsManager &layoutAnimationsManager() { return *layoutAnimationsManager_; } [[nodiscard]] inline bool isReducedMotion() const { return isReducedMotion_; } [[nodiscard]] inline std::shared_ptr getWorkletsModuleProxy() const { return workletsModuleProxy_; } void requestFlushRegistry(); std::function createRegistriesLeakCheck(); private: void commitUpdates(jsi::Runtime &rt, const UpdatesBatch &updatesBatch); void applySynchronousUpdates( UpdatesBatch &updatesBatch, bool allowPartialUpdates = false); const bool isReducedMotion_; bool shouldFlushRegistry_ = false; std::shared_ptr workletsModuleProxy_; std::unique_ptr eventHandlerRegistry_; const RequestRenderFunction requestRender_; std::vector> frameCallbacks_; volatile bool renderRequested_{false}; std::function onRenderCallback_; AnimatedSensorModule animatedSensorModule_; const std::shared_ptr jsLogger_; std::shared_ptr layoutAnimationsManager_; GetAnimationTimestampFunction getAnimationTimestamp_; bool cssLoopRunning_{false}; bool shouldUpdateCssAnimations_{true}; double currentCssTimestamp_{0}; const std::shared_ptr animatedPropsRegistry_; const std::shared_ptr staticPropsRegistry_; const std::shared_ptr updatesRegistryManager_; const std::shared_ptr viewStylesRepository_; const std::shared_ptr cssAnimationKeyframesRegistry_; const std::shared_ptr cssAnimationsRegistry_; const std::shared_ptr cssTransitionsRegistry_; const SynchronouslyUpdateUIPropsFunction synchronouslyUpdateUIPropsFunction_; std::shared_ptr uiManager_; std::shared_ptr layoutAnimationsProxy_; std::shared_ptr commitHook_; std::shared_ptr mountHook_; std::set layoutAnimationFlushRequests_; bool layoutAnimationRenderRequested_; const KeyboardEventSubscribeFunction subscribeForKeyboardEventsFunction_; const KeyboardEventUnsubscribeFunction unsubscribeFromKeyboardEventsFunction_; #ifndef NDEBUG worklets::SingleInstanceChecker singleInstanceChecker_; #endif // NDEBUG }; } // namespace reanimated