mirror of
https://github.com/status-im/react-native.git
synced 2025-01-28 02:04:55 +00:00
a089df3f8b
Summary: Previously, we used special JSI bindings method to release an event handler (`JSIReleaseFabricEventHandler`). Now we expose this ownership model as a regular `std::shared_ptr`, so when the owner got deallocated, the event handler will be released automatically. Why not use `unique_ptr`? `unique_ptr` is faster (and simpler) indeed, but it does not provide `type erasure` functionality that we need; to use `unique_ptr` we would have to make JSI an explicit Fabric dependency (we will probably end up with it eventually, but I this particular case is not a good reason for that). All interactions with `eventHandler_` are done in a non-owning manner, so it's as performant as unique_ptr anyway. (Please ignore all changes in JSCFabricUIManager.h/cpp files, we will delete them soon.) Reviewed By: mdvacca Differential Revision: D9756732 fbshipit-source-id: bffdee0c724dc95855ced7c35e7c13cf1554796e
79 lines
3.2 KiB
C++
79 lines
3.2 KiB
C++
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <memory>
|
|
|
|
#include <folly/dynamic.h>
|
|
|
|
#include <fabric/core/ShadowNode.h>
|
|
#include <fabric/uimanager/ComponentDescriptorRegistry.h>
|
|
#include <fabric/uimanager/UIManagerDelegate.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
using DispatchEventToEmptyTargetFunction = void (const EventHandler &eventHandler, std::string type, folly::dynamic payload);
|
|
using DispatchEventToTargetFunction = void (const EventHandler &eventHandler, EventTarget eventTarget, std::string type, folly::dynamic payload);
|
|
using ReleaseEventTargetFunction = void (EventTarget eventTarget);
|
|
|
|
class FabricUIManager {
|
|
public:
|
|
|
|
#pragma mark - Native-facing Interface
|
|
|
|
void setComponentDescriptorRegistry(const SharedComponentDescriptorRegistry &componentDescriptorRegistry);
|
|
|
|
/*
|
|
* Sets and gets the UIManager's delegate.
|
|
* The delegate is stored as a raw pointer, so the owner must null
|
|
* the pointer before being destroyed.
|
|
*/
|
|
void setDelegate(UIManagerDelegate *delegate);
|
|
UIManagerDelegate *getDelegate();
|
|
|
|
#pragma mark - Callback Functions
|
|
|
|
/*
|
|
* Registers callback functions.
|
|
*/
|
|
void setDispatchEventToEmptyTargetFunction(std::function<DispatchEventToEmptyTargetFunction> dispatchEventFunction);
|
|
void setDispatchEventToTargetFunction(std::function<DispatchEventToTargetFunction> dispatchEventFunction);
|
|
void setReleaseEventTargetFunction(std::function<ReleaseEventTargetFunction> releaseEventTargetFunction);
|
|
|
|
#pragma mark - Native-facing Interface
|
|
|
|
void dispatchEventToTarget(const EventTarget &eventTarget, const std::string &type, const folly::dynamic &payload) const;
|
|
void releaseEventTarget(const EventTarget &eventTarget) const;
|
|
|
|
#pragma mark - JavaScript/React-facing Interface
|
|
|
|
SharedShadowNode createNode(Tag reactTag, std::string viewName, Tag rootTag, folly::dynamic props, EventTarget eventTarget);
|
|
SharedShadowNode cloneNode(const SharedShadowNode &node);
|
|
SharedShadowNode cloneNodeWithNewChildren(const SharedShadowNode &node);
|
|
SharedShadowNode cloneNodeWithNewProps(const SharedShadowNode &node, folly::dynamic props);
|
|
SharedShadowNode cloneNodeWithNewChildrenAndProps(const SharedShadowNode &node, folly::dynamic newProps);
|
|
void appendChild(const SharedShadowNode &parentNode, const SharedShadowNode &childNode);
|
|
SharedShadowNodeUnsharedList createChildSet(Tag rootTag);
|
|
void appendChildToSet(const SharedShadowNodeUnsharedList &childSet, const SharedShadowNode &childNode);
|
|
void completeRoot(Tag rootTag, const SharedShadowNodeUnsharedList &childSet);
|
|
void registerEventHandler(std::shared_ptr<EventHandler> eventHandler);
|
|
|
|
private:
|
|
|
|
SharedComponentDescriptorRegistry componentDescriptorRegistry_;
|
|
UIManagerDelegate *delegate_;
|
|
std::shared_ptr<EventHandler> eventHandler_;
|
|
std::function<DispatchEventToEmptyTargetFunction> dispatchEventToEmptyTargetFunction_;
|
|
std::function<DispatchEventToTargetFunction> dispatchEventToTargetFunction_;
|
|
std::function<ReleaseEventTargetFunction> releaseEventTargetFunction_;
|
|
};
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|