Fabric: Wiring FabricUIManager with JS*FabricUIManager bindings

Summary: Now FabricUIManager is all you (or I) need to deliver an event.

Reviewed By: fkgozali

Differential Revision: D8086627

fbshipit-source-id: 70d783bee291f4c5d19650ac0768a5d2bd778961
This commit is contained in:
Valentin Shergin 2018-05-24 18:23:08 -07:00 committed by Facebook Github Bot
parent b13add753b
commit 0be26092a5
2 changed files with 68 additions and 1 deletions

View File

@ -76,6 +76,12 @@ FabricUIManager::FabricUIManager(SharedComponentDescriptorRegistry componentDesc
componentDescriptorRegistry_ = componentDescriptorRegistry;
}
FabricUIManager::~FabricUIManager() {
if (eventHandler_) {
releaseEventTargetFunction_(eventHandler_);
}
}
void FabricUIManager::setDelegate(UIManagerDelegate *delegate) {
delegate_ = delegate;
}
@ -84,6 +90,39 @@ UIManagerDelegate *FabricUIManager::getDelegate() {
return delegate_;
}
void FabricUIManager::setCreateEventTargetFunction(std::function<CreateEventTargetFunction> createEventTargetFunction) {
createEventTargetFunction_ = createEventTargetFunction;
}
void FabricUIManager::setDispatchEventFunction(std::function<DispatchEventFunction> dispatchEventFunction) {
dispatchEventFunction_ = dispatchEventFunction;
}
void FabricUIManager::setReleaseEventTargetFunction(std::function<ReleaseEventTargetFunction> releaseEventTargetFunction) {
releaseEventTargetFunction_ = releaseEventTargetFunction;
}
void FabricUIManager::setReleaseEventHandlerFunction(std::function<ReleaseEventHandlerFunction> releaseEventHandlerFunction) {
releaseEventHandlerFunction_ = releaseEventHandlerFunction;
}
void *FabricUIManager::createEventTarget(void *instanceHandle) {
return createEventTargetFunction_(instanceHandle);
}
void FabricUIManager::dispatchEvent(void *eventTarget, const std::string &type, const folly::dynamic &payload) {
dispatchEventFunction_(
eventHandler_,
eventTarget,
const_cast<std::string &>(type),
const_cast<folly::dynamic &>(payload)
);
}
void FabricUIManager::releaseEventTarget(void *eventTarget) {
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 << ")";
@ -214,7 +253,7 @@ void FabricUIManager::completeRoot(int rootTag, const SharedShadowNodeUnsharedLi
void FabricUIManager::registerEventHandler(void *eventHandler) {
isLoggingEnabled && LOG(INFO) << "FabricUIManager::registerEventHandler(eventHandler)";
// TODO: Store eventHandler handle.
eventHandler_ = eventHandler;
}
} // namespace react

View File

@ -18,12 +18,18 @@
namespace facebook {
namespace react {
using CreateEventTargetFunction = void *(void *instanceHandle);
using DispatchEventFunction = void (void *eventHandler, void *eventTarget, std::string type, folly::dynamic payload);
using ReleaseEventTargetFunction = void (void *eventTarget);
using ReleaseEventHandlerFunction = void (void *eventHandler);
class FabricUIManager {
public:
#pragma mark - Native-facing Interface
FabricUIManager(SharedComponentDescriptorRegistry componentDescriptorRegistry);
~FabricUIManager();
/*
* Sets and gets the UIManager's delegate.
@ -33,6 +39,22 @@ public:
void setDelegate(UIManagerDelegate *delegate);
UIManagerDelegate *getDelegate();
#pragma mark - Callback Functions
/*
* Registers callback functions.
*/
void setCreateEventTargetFunction(std::function<CreateEventTargetFunction> createEventTargetFunction);
void setDispatchEventFunction(std::function<DispatchEventFunction> dispatchEventFunction);
void setReleaseEventTargetFunction(std::function<ReleaseEventTargetFunction> releaseEventTargetFunction);
void setReleaseEventHandlerFunction(std::function<ReleaseEventHandlerFunction> releaseEventHandlerFunction);
#pragma mark - Native-facing Interface
void *createEventTarget(void *instanceHandle);
void dispatchEvent(void *eventTarget, const std::string &type, const folly::dynamic &payload);
void releaseEventTarget(void *eventTarget);
#pragma mark - JavaScript/React-facing Interface
SharedShadowNode createNode(Tag reactTag, std::string viewName, Tag rootTag, folly::dynamic props, InstanceHandle instanceHandle);
@ -47,8 +69,14 @@ public:
void registerEventHandler(void *eventHandler);
private:
SharedComponentDescriptorRegistry componentDescriptorRegistry_;
UIManagerDelegate *delegate_;
void *eventHandler_;
std::function<CreateEventTargetFunction> createEventTargetFunction_;
std::function<DispatchEventFunction> dispatchEventFunction_;
std::function<ReleaseEventTargetFunction> releaseEventTargetFunction_;
std::function<ReleaseEventHandlerFunction> releaseEventHandlerFunction_;
};
} // namespace react