diff --git a/React/CxxBridge/RCTCxxBridge.mm b/React/CxxBridge/RCTCxxBridge.mm index b445991fb..42c3fdbf5 100644 --- a/React/CxxBridge/RCTCxxBridge.mm +++ b/React/CxxBridge/RCTCxxBridge.mm @@ -188,6 +188,11 @@ struct RCTInstanceCallback : public InstanceCallback { return (JSGlobalContextRef)(_reactInstance ? _reactInstance->getJavaScriptContext() : nullptr); } +- (std::shared_ptr)jsMessageThread +{ + return _jsMessageThread; +} + - (BOOL)isInspectable { return _reactInstance ? _reactInstance->isInspectable() : NO; diff --git a/ReactCommon/fabric/core/events/EventDispatcher.h b/ReactCommon/fabric/core/events/EventDispatcher.h index 930a547f4..d241f3a29 100644 --- a/ReactCommon/fabric/core/events/EventDispatcher.h +++ b/ReactCommon/fabric/core/events/EventDispatcher.h @@ -30,8 +30,6 @@ public: virtual EventTarget createEventTarget(const InstanceHandle &instanceHandle) const = 0; - virtual void releaseEventTarget(const EventTarget &eventTarget) const = 0; - /* * Dispatches "raw" event using some event-delivery infrastructure. */ diff --git a/ReactCommon/fabric/core/events/EventEmitter.cpp b/ReactCommon/fabric/core/events/EventEmitter.cpp index b4b3b8db3..ec42f0f1d 100644 --- a/ReactCommon/fabric/core/events/EventEmitter.cpp +++ b/ReactCommon/fabric/core/events/EventEmitter.cpp @@ -17,9 +17,7 @@ EventEmitter::EventEmitter(const InstanceHandle &instanceHandle, const Tag &tag, tag_(tag), eventDispatcher_(eventDispatcher) {} -EventEmitter::~EventEmitter() { - releaseEventTargetIfNeeded(); -} +EventEmitter::~EventEmitter() {} void EventEmitter::dispatchEvent( const std::string &type, @@ -31,7 +29,7 @@ void EventEmitter::dispatchEvent( return; } - createEventTargetIfNeeded(); + EventTarget eventTarget = createEventTarget(); // Mixing `target` into `payload`. assert(payload.isObject()); @@ -39,31 +37,13 @@ void EventEmitter::dispatchEvent( extendedPayload.merge_patch(payload); // TODO(T29610783): Reconsider using dynamic dispatch here. - eventDispatcher->dispatchEvent(eventTarget_, type, extendedPayload, priority); + eventDispatcher->dispatchEvent(eventTarget, type, extendedPayload, priority); } -void EventEmitter::createEventTargetIfNeeded() const { - std::lock_guard lock(mutex_); - - if (eventTarget_) { - return; - } - +EventTarget EventEmitter::createEventTarget() const { auto &&eventDispatcher = eventDispatcher_.lock(); assert(eventDispatcher); - eventTarget_ = eventDispatcher->createEventTarget(instanceHandle_); -} - -void EventEmitter::releaseEventTargetIfNeeded() const { - std::lock_guard lock(mutex_); - - if (!eventTarget_) { - return; - } - - auto &&eventDispatcher = eventDispatcher_.lock(); - assert(eventDispatcher); - eventDispatcher->releaseEventTarget(eventTarget_); + return eventDispatcher->createEventTarget(instanceHandle_); } } // namespace react diff --git a/ReactCommon/fabric/core/events/EventEmitter.h b/ReactCommon/fabric/core/events/EventEmitter.h index eb05bd1c6..f63c59d73 100644 --- a/ReactCommon/fabric/core/events/EventEmitter.h +++ b/ReactCommon/fabric/core/events/EventEmitter.h @@ -48,14 +48,11 @@ protected: private: - void createEventTargetIfNeeded() const; - void releaseEventTargetIfNeeded() const; + EventTarget createEventTarget() const; InstanceHandle instanceHandle_; Tag tag_; std::weak_ptr eventDispatcher_; - mutable EventTarget eventTarget_ {nullptr}; - mutable std::mutex mutex_; }; } // namespace react diff --git a/ReactCommon/fabric/uimanager/FabricUIManager.cpp b/ReactCommon/fabric/uimanager/FabricUIManager.cpp index 30df1137c..1c8f96b3d 100644 --- a/ReactCommon/fabric/uimanager/FabricUIManager.cpp +++ b/ReactCommon/fabric/uimanager/FabricUIManager.cpp @@ -98,10 +98,6 @@ void FabricUIManager::setDispatchEventFunction(std::function releaseEventTargetFunction) { - releaseEventTargetFunction_ = releaseEventTargetFunction; -} - void FabricUIManager::setReleaseEventHandlerFunction(std::function releaseEventHandlerFunction) { releaseEventHandlerFunction_ = releaseEventHandlerFunction; } @@ -119,10 +115,6 @@ void FabricUIManager::dispatchEvent(const EventTarget &eventTarget, const std::s ); } -void FabricUIManager::releaseEventTarget(const EventTarget &eventTarget) const { - releaseEventTargetFunction_(eventTarget); -} - SharedShadowNode FabricUIManager::createNode(int tag, std::string viewName, int rootTag, folly::dynamic props, InstanceHandle instanceHandle) { isLoggingEnabled && LOG(INFO) << "FabricUIManager::createNode(tag: " << tag << ", name: " << viewName << ", rootTag: " << rootTag << ", props: " << props << ")"; diff --git a/ReactCommon/fabric/uimanager/FabricUIManager.h b/ReactCommon/fabric/uimanager/FabricUIManager.h index ca0987a08..bd16f0294 100644 --- a/ReactCommon/fabric/uimanager/FabricUIManager.h +++ b/ReactCommon/fabric/uimanager/FabricUIManager.h @@ -20,7 +20,6 @@ namespace react { using CreateEventTargetFunction = EventTarget (InstanceHandle instanceHandle); using DispatchEventFunction = void (EventHandler eventHandler, EventTarget eventTarget, std::string type, folly::dynamic payload); -using ReleaseEventTargetFunction = void (EventTarget eventTarget); using ReleaseEventHandlerFunction = void (EventHandler eventHandler); class FabricUIManager { @@ -46,14 +45,12 @@ public: */ void setCreateEventTargetFunction(std::function createEventTargetFunction); void setDispatchEventFunction(std::function dispatchEventFunction); - void setReleaseEventTargetFunction(std::function releaseEventTargetFunction); void setReleaseEventHandlerFunction(std::function releaseEventHandlerFunction); #pragma mark - Native-facing Interface EventTarget createEventTarget(const InstanceHandle &instanceHandle) const; void dispatchEvent(const EventTarget &eventTarget, const std::string &type, const folly::dynamic &payload) const; - void releaseEventTarget(const EventTarget &eventTarget) const; #pragma mark - JavaScript/React-facing Interface @@ -75,7 +72,6 @@ private: EventHandler eventHandler_; std::function createEventTargetFunction_; std::function dispatchEventFunction_; - std::function releaseEventTargetFunction_; std::function releaseEventHandlerFunction_; }; diff --git a/ReactCommon/fabric/uimanager/SchedulerEventDispatcher.cpp b/ReactCommon/fabric/uimanager/SchedulerEventDispatcher.cpp index 5cd608667..0dce7c6b0 100644 --- a/ReactCommon/fabric/uimanager/SchedulerEventDispatcher.cpp +++ b/ReactCommon/fabric/uimanager/SchedulerEventDispatcher.cpp @@ -30,16 +30,13 @@ EventTarget SchedulerEventDispatcher::createEventTarget(const InstanceHandle &in return uiManager_->createEventTarget(instanceHandle); } -void SchedulerEventDispatcher::releaseEventTarget(const EventTarget &eventTarget) const { - uiManager_->releaseEventTarget(eventTarget); -} - void SchedulerEventDispatcher::dispatchEvent( const EventTarget &eventTarget, const std::string &type, const folly::dynamic &payload, const EventPriority &priority ) const { + // TODO: Schedule the event based on priority. uiManager_->dispatchEvent(eventTarget, normalizeEventType(type), payload); } diff --git a/ReactCommon/fabric/uimanager/SchedulerEventDispatcher.h b/ReactCommon/fabric/uimanager/SchedulerEventDispatcher.h index d7f6e190c..313d3b2ee 100644 --- a/ReactCommon/fabric/uimanager/SchedulerEventDispatcher.h +++ b/ReactCommon/fabric/uimanager/SchedulerEventDispatcher.h @@ -33,8 +33,6 @@ public: EventTarget createEventTarget(const InstanceHandle &instanceHandle) const override; - void releaseEventTarget(const EventTarget &eventTarget) const override; - void dispatchEvent( const EventTarget &eventTarget, const std::string &type,