From b784adc7ae7dc9dd5f20fddadc23402e7f2efd70 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Mon, 27 Aug 2018 07:21:16 -0700 Subject: [PATCH] Fabric: `FabricUIManager::dispatchEventToEmptyTarget` got coupled with `dispatchEventToTarget` Summary: @public Instead of having two methods it's easier to have just one which can be abstracted as `EventPipe`. Reviewed By: mdvacca Differential Revision: D8886231 fbshipit-source-id: af9fd92dc4afa1219a11acce0aa021a85c94d232 --- ReactCommon/fabric/events/primitives.h | 14 +++++++-- .../fabric/uimanager/FabricUIManager.cpp | 29 ++++++++++--------- .../fabric/uimanager/FabricUIManager.h | 1 - 3 files changed, 27 insertions(+), 17 deletions(-) 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;