Fabric: Integrating `tag` into `EventHandlers`
Summary: In order to dispatch event, `EventHandlers` must also know react tag. So we have to store it inside. We plan to illuminate this requirement (and `tag` from `EventHandlers`) eventually. Reviewed By: fkgozali Differential Revision: D8211685 fbshipit-source-id: 2064c0f4a7869cbf4d2c92d0349f4ee3998cb8f5
This commit is contained in:
parent
d081f83a04
commit
0fc5a91889
|
@ -85,7 +85,8 @@ public:
|
|||
* shadow nodes.
|
||||
*/
|
||||
virtual SharedEventHandlers createEventHandlers(
|
||||
const InstanceHandle &instanceHandle
|
||||
const InstanceHandle &instanceHandle,
|
||||
const Tag &tag
|
||||
) const = 0;
|
||||
};
|
||||
|
||||
|
|
|
@ -113,9 +113,10 @@ public:
|
|||
};
|
||||
|
||||
virtual SharedEventHandlers createEventHandlers(
|
||||
const InstanceHandle &instanceHandle
|
||||
const InstanceHandle &instanceHandle,
|
||||
const Tag &tag
|
||||
) const override {
|
||||
return std::make_shared<ConcreteEventHandlers>(instanceHandle, eventDispatcher_);
|
||||
return std::make_shared<ConcreteEventHandlers>(instanceHandle, tag, eventDispatcher_);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
|
|
@ -12,12 +12,13 @@
|
|||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
EventHandlers::EventHandlers(InstanceHandle instanceHandle, SharedEventDispatcher eventDispatcher):
|
||||
EventHandlers::EventHandlers(const InstanceHandle &instanceHandle, const Tag &tag, const SharedEventDispatcher &eventDispatcher):
|
||||
instanceHandle_(instanceHandle),
|
||||
tag_(tag),
|
||||
eventDispatcher_(eventDispatcher) {}
|
||||
|
||||
void EventHandlers::dispatchEvent(
|
||||
const std::string &name,
|
||||
const std::string &type,
|
||||
const folly::dynamic &payload,
|
||||
const EventPriority &priority
|
||||
) const {
|
||||
|
@ -26,8 +27,13 @@ void EventHandlers::dispatchEvent(
|
|||
return;
|
||||
}
|
||||
|
||||
// Mixing `target` into `payload`.
|
||||
assert(payload.isObject());
|
||||
folly::dynamic extendedPayload = folly::dynamic::object("target", tag_);
|
||||
extendedPayload.merge_patch(payload);
|
||||
|
||||
// TODO(T29610783): Reconsider using dynamic dispatch here.
|
||||
eventDispatcher->dispatchEvent(instanceHandle_, name, payload, priority);
|
||||
eventDispatcher->dispatchEvent(instanceHandle_, type, extendedPayload, priority);
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
|
|
|
@ -32,8 +32,8 @@ using SharedEventHandlers = std::shared_ptr<const EventHandlers>;
|
|||
class EventHandlers {
|
||||
|
||||
public:
|
||||
EventHandlers(InstanceHandle instanceHandle, SharedEventDispatcher eventDispatcher);
|
||||
virtual ~EventHandlers() = default;
|
||||
EventHandlers(const InstanceHandle &instanceHandle, const Tag &tag, const SharedEventDispatcher &eventDispatcher);
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -42,14 +42,15 @@ protected:
|
|||
* Is used by particular subclasses only.
|
||||
*/
|
||||
void dispatchEvent(
|
||||
const std::string &name,
|
||||
const folly::dynamic &payload = {},
|
||||
const std::string &type,
|
||||
const folly::dynamic &payload = folly::dynamic::object(),
|
||||
const EventPriority &priority = EventPriority::AsynchronousBatched
|
||||
) const;
|
||||
|
||||
private:
|
||||
|
||||
InstanceHandle instanceHandle_;
|
||||
Tag tag_;
|
||||
std::weak_ptr<const EventDispatcher> eventDispatcher_;
|
||||
};
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ SharedShadowNode FabricUIManager::createNode(int tag, std::string viewName, int
|
|||
componentDescriptor->createShadowNode(
|
||||
tag,
|
||||
rootTag,
|
||||
componentDescriptor->createEventHandlers(instanceHandle),
|
||||
componentDescriptor->createEventHandlers(instanceHandle, tag),
|
||||
componentDescriptor->cloneProps(nullptr, rawProps)
|
||||
);
|
||||
|
||||
|
@ -155,7 +155,7 @@ SharedShadowNode FabricUIManager::cloneNode(const SharedShadowNode &shadowNode,
|
|||
componentDescriptor->cloneShadowNode(
|
||||
shadowNode,
|
||||
nullptr,
|
||||
componentDescriptor->createEventHandlers(instanceHandle),
|
||||
componentDescriptor->createEventHandlers(instanceHandle, shadowNode->getTag()),
|
||||
nullptr
|
||||
);
|
||||
|
||||
|
@ -172,7 +172,7 @@ SharedShadowNode FabricUIManager::cloneNodeWithNewChildren(const SharedShadowNod
|
|||
componentDescriptor->cloneShadowNode(
|
||||
shadowNode,
|
||||
nullptr,
|
||||
componentDescriptor->createEventHandlers(instanceHandle),
|
||||
componentDescriptor->createEventHandlers(instanceHandle, shadowNode->getTag()),
|
||||
ShadowNode::emptySharedShadowNodeSharedList()
|
||||
);
|
||||
|
||||
|
@ -190,7 +190,7 @@ SharedShadowNode FabricUIManager::cloneNodeWithNewProps(const SharedShadowNode &
|
|||
componentDescriptor->cloneShadowNode(
|
||||
shadowNode,
|
||||
componentDescriptor->cloneProps(shadowNode->getProps(), rawProps),
|
||||
componentDescriptor->createEventHandlers(instanceHandle),
|
||||
componentDescriptor->createEventHandlers(instanceHandle, shadowNode->getTag()),
|
||||
nullptr
|
||||
);
|
||||
|
||||
|
@ -208,7 +208,7 @@ SharedShadowNode FabricUIManager::cloneNodeWithNewChildrenAndProps(const SharedS
|
|||
componentDescriptor->cloneShadowNode(
|
||||
shadowNode,
|
||||
componentDescriptor->cloneProps(shadowNode->getProps(), rawProps),
|
||||
componentDescriptor->createEventHandlers(instanceHandle),
|
||||
componentDescriptor->createEventHandlers(instanceHandle, shadowNode->getTag()),
|
||||
ShadowNode::emptySharedShadowNodeSharedList()
|
||||
);
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace react {
|
|||
ShadowTree::ShadowTree(Tag rootTag):
|
||||
rootTag_(rootTag) {
|
||||
|
||||
auto &&noopEventHandlers = std::make_shared<const ViewEventHandlers>(nullptr, nullptr);
|
||||
auto &&noopEventHandlers = std::make_shared<const ViewEventHandlers>(nullptr, rootTag, nullptr);
|
||||
rootShadowNode_ = std::make_shared<RootShadowNode>(
|
||||
rootTag,
|
||||
rootTag,
|
||||
|
|
Loading…
Reference in New Issue