diff --git a/ReactCommon/fabric/events/primitives.h b/ReactCommon/fabric/events/primitives.h index 5dc5cb5d6..3f447a073 100644 --- a/ReactCommon/fabric/events/primitives.h +++ b/ReactCommon/fabric/events/primitives.h @@ -7,10 +7,12 @@ #pragma once +#include + namespace facebook { namespace react { -enum class EventPriority { +enum class EventPriority: int { SynchronousUnbatched, SynchronousBatched, AsynchronousUnbatched, @@ -19,7 +21,7 @@ enum class EventPriority { Sync = SynchronousUnbatched, Work = SynchronousBatched, Interactive = AsynchronousUnbatched, - Deferred = AsynchronousBatched, + Deferred = AsynchronousBatched }; /* `InstanceHandler`, `EventTarget`, and `EventHandler` are all opaque @@ -32,5 +34,13 @@ enum class EventPriority { using EventTarget = struct EventTargetDummyStruct {} *; using EventHandler = struct EventHandlerDummyStruct {} *; +/* + * EmptyEventTarget is used when some event cannot be dispatched to an original + * event target but still has to be dispatched to preserve consistency of event flow. + */ +static const EventTarget EmptyEventTarget = nullptr; + +using EventPipe = std::function; + } // namespace react } // namespace facebook diff --git a/ReactCommon/fabric/uimanager/FabricUIManager.cpp b/ReactCommon/fabric/uimanager/FabricUIManager.cpp index 11f6b362d..62499d4ae 100644 --- a/ReactCommon/fabric/uimanager/FabricUIManager.cpp +++ b/ReactCommon/fabric/uimanager/FabricUIManager.cpp @@ -114,21 +114,22 @@ void FabricUIManager::setReleaseEventTargetFunction(std::function(type), - const_cast(payload) - ); -} - void FabricUIManager::dispatchEventToTarget(const EventTarget &eventTarget, const std::string &type, const folly::dynamic &payload) const { - dispatchEventToTargetFunction_( - eventHandler_, - eventTarget, - const_cast(type), - const_cast(payload) - ); + if (eventTarget != EmptyEventTarget) { + dispatchEventToTargetFunction_( + eventHandler_, + eventTarget, + const_cast(type), + const_cast(payload) + ); + } + else { + dispatchEventToEmptyTargetFunction_( + eventHandler_, + const_cast(type), + const_cast(payload) + ); + } } void FabricUIManager::releaseEventTarget(const EventTarget &eventTarget) const { diff --git a/ReactCommon/fabric/uimanager/FabricUIManager.h b/ReactCommon/fabric/uimanager/FabricUIManager.h index e33501e31..8bb0eff72 100644 --- a/ReactCommon/fabric/uimanager/FabricUIManager.h +++ b/ReactCommon/fabric/uimanager/FabricUIManager.h @@ -51,7 +51,6 @@ public: #pragma mark - Native-facing Interface - void dispatchEventToEmptyTarget(const std::string &type, const folly::dynamic &payload) const; void dispatchEventToTarget(const EventTarget &eventTarget, const std::string &type, const folly::dynamic &payload) const; void releaseEventTarget(const EventTarget &eventTarget) const;