From b3b72bbdcfe296a369e06f5564f7aa398842a520 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Tue, 29 May 2018 14:54:52 -0700 Subject: [PATCH] Fabric: Using types `EventTarget`, `EventHandler` & co. instead of `void *` everywhere Summary: Nothing actually changed besides type names... which actually helps me found an issue in FabricUIManager! Now there is no a single `void *` in Fabric/C++ and JavaScript bindings. Yay! Reviewed By: fkgozali Differential Revision: D8191420 fbshipit-source-id: b1eb60b6bc34dd25ab200aab854ffbd7ccf5b15d --- .../fabric/core/events/EventPrimitives.h | 14 +++++++++----- .../fabric/core/primitives/ReactPrimitives.h | 2 +- .../fabric/uimanager/FabricUIManager.cpp | 14 +++++++------- ReactCommon/fabric/uimanager/FabricUIManager.h | 18 +++++++++--------- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/ReactCommon/fabric/core/events/EventPrimitives.h b/ReactCommon/fabric/core/events/EventPrimitives.h index 46b715796..5dc5cb5d6 100644 --- a/ReactCommon/fabric/core/events/EventPrimitives.h +++ b/ReactCommon/fabric/core/events/EventPrimitives.h @@ -22,11 +22,15 @@ enum class EventPriority { Deferred = AsynchronousBatched, }; -// `InstanceHandler`, `EventTarget`, and `EventHandler` are all opaque -// raw pointers. We use `struct {} *` trick to differentiate them in compiler's -// eyes to ensure type safety. -using EventTarget = struct {} *; -using EventHandler = struct {} *; +/* `InstanceHandler`, `EventTarget`, and `EventHandler` are all opaque + * raw pointers. We use `struct {} *` trick to differentiate them in compiler's + * eyes to ensure type safety. + * These structs must have names (and the names must be exported) + * to allow consistent template (e.g. `std::function`) instantiating + * across different modules. + */ +using EventTarget = struct EventTargetDummyStruct {} *; +using EventHandler = struct EventHandlerDummyStruct {} *; } // namespace react } // namespace facebook diff --git a/ReactCommon/fabric/core/primitives/ReactPrimitives.h b/ReactCommon/fabric/core/primitives/ReactPrimitives.h index 0b5004ab2..c81f0ac93 100644 --- a/ReactCommon/fabric/core/primitives/ReactPrimitives.h +++ b/ReactCommon/fabric/core/primitives/ReactPrimitives.h @@ -19,7 +19,7 @@ namespace react { * `Tag` and `InstanceHandle` are used to address React Native components. */ using Tag = int32_t; -using InstanceHandle = void *; +using InstanceHandle = struct InstanceHandleDummyStruct {} *; /* * `RawProps` represents untyped map with props comes from JavaScript side. diff --git a/ReactCommon/fabric/uimanager/FabricUIManager.cpp b/ReactCommon/fabric/uimanager/FabricUIManager.cpp index 94b630c74..7bedbfc8e 100644 --- a/ReactCommon/fabric/uimanager/FabricUIManager.cpp +++ b/ReactCommon/fabric/uimanager/FabricUIManager.cpp @@ -78,7 +78,7 @@ FabricUIManager::FabricUIManager(SharedComponentDescriptorRegistry componentDesc FabricUIManager::~FabricUIManager() { if (eventHandler_) { - releaseEventTargetFunction_(eventHandler_); + releaseEventHandlerFunction_(eventHandler_); } } @@ -106,11 +106,11 @@ void FabricUIManager::setReleaseEventHandlerFunction(std::function createEventTargetFunction_; std::function dispatchEventFunction_; std::function releaseEventTargetFunction_;