Fabric: All *EventHandlers were renamed to *EventEmitter

Summary:
Using `EventHandlers` name was a bad idea, and I cannot tolerate it anymore.
The worst part of it is that when you have a collection of `EventHandlers` objects you cannot use plural word to describe it because `EventHandlers` is an already plural word.

And, this object is actually an event emitter, the thing on which we call events.

Reviewed By: fkgozali

Differential Revision: D8247723

fbshipit-source-id: b3303a4b9529bd6d32bb8ca0378287ebefaedda8
This commit is contained in:
Valentin Shergin 2018-06-09 13:02:55 -07:00 committed by Facebook Github Bot
parent 521fb6d041
commit d49ebbcf62
28 changed files with 166 additions and 166 deletions

View File

@ -11,7 +11,7 @@
#import <fabric/graphics/Geometry.h> #import <fabric/graphics/Geometry.h>
#import <fabric/scrollview/ScrollViewLocalData.h> #import <fabric/scrollview/ScrollViewLocalData.h>
#import <fabric/scrollview/ScrollViewProps.h> #import <fabric/scrollview/ScrollViewProps.h>
#import <fabric/scrollview/ScrollViewEventHandlers.h> #import <fabric/scrollview/ScrollViewEventEmitter.h>
#import "RCTConversions.h" #import "RCTConversions.h"
#import "RCTEnhancedScrollView.h" #import "RCTEnhancedScrollView.h"
@ -135,47 +135,47 @@ using namespace facebook::react;
- (void)scrollViewDidScroll:(UIScrollView *)scrollView - (void)scrollViewDidScroll:(UIScrollView *)scrollView
{ {
std::static_pointer_cast<const ScrollViewEventHandlers>(_eventHandlers)->onScroll([self _scrollViewMetrics]); std::static_pointer_cast<const ScrollViewEventEmitter>(_eventEmitter)->onScroll([self _scrollViewMetrics]);
} }
- (void)scrollViewDidZoom:(UIScrollView *)scrollView - (void)scrollViewDidZoom:(UIScrollView *)scrollView
{ {
std::static_pointer_cast<const ScrollViewEventHandlers>(_eventHandlers)->onScroll([self _scrollViewMetrics]); std::static_pointer_cast<const ScrollViewEventEmitter>(_eventEmitter)->onScroll([self _scrollViewMetrics]);
} }
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{ {
std::static_pointer_cast<const ScrollViewEventHandlers>(_eventHandlers)->onScrollBeginDrag([self _scrollViewMetrics]); std::static_pointer_cast<const ScrollViewEventEmitter>(_eventEmitter)->onScrollBeginDrag([self _scrollViewMetrics]);
} }
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{ {
std::static_pointer_cast<const ScrollViewEventHandlers>(_eventHandlers)->onScrollEndDrag([self _scrollViewMetrics]); std::static_pointer_cast<const ScrollViewEventEmitter>(_eventEmitter)->onScrollEndDrag([self _scrollViewMetrics]);
} }
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{ {
std::static_pointer_cast<const ScrollViewEventHandlers>(_eventHandlers)->onMomentumScrollBegin([self _scrollViewMetrics]); std::static_pointer_cast<const ScrollViewEventEmitter>(_eventEmitter)->onMomentumScrollBegin([self _scrollViewMetrics]);
} }
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{ {
std::static_pointer_cast<const ScrollViewEventHandlers>(_eventHandlers)->onMomentumScrollEnd([self _scrollViewMetrics]); std::static_pointer_cast<const ScrollViewEventEmitter>(_eventEmitter)->onMomentumScrollEnd([self _scrollViewMetrics]);
} }
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
{ {
std::static_pointer_cast<const ScrollViewEventHandlers>(_eventHandlers)->onMomentumScrollEnd([self _scrollViewMetrics]); std::static_pointer_cast<const ScrollViewEventEmitter>(_eventEmitter)->onMomentumScrollEnd([self _scrollViewMetrics]);
} }
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view - (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view
{ {
std::static_pointer_cast<const ScrollViewEventHandlers>(_eventHandlers)->onScrollBeginDrag([self _scrollViewMetrics]); std::static_pointer_cast<const ScrollViewEventEmitter>(_eventEmitter)->onScrollBeginDrag([self _scrollViewMetrics]);
} }
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view atScale:(CGFloat)scale - (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view atScale:(CGFloat)scale
{ {
std::static_pointer_cast<const ScrollViewEventHandlers>(_eventHandlers)->onScrollEndDrag([self _scrollViewMetrics]); std::static_pointer_cast<const ScrollViewEventEmitter>(_eventEmitter)->onScrollEndDrag([self _scrollViewMetrics]);
} }
@end @end

View File

@ -9,10 +9,10 @@
#import <React/RCTComponentViewProtocol.h> #import <React/RCTComponentViewProtocol.h>
#import <React/UIView+ComponentViewProtocol.h> #import <React/UIView+ComponentViewProtocol.h>
#import <fabric/core/EventHandlers.h> #import <fabric/core/EventEmitter.h>
#import <fabric/core/LayoutMetrics.h> #import <fabric/core/LayoutMetrics.h>
#import <fabric/core/Props.h> #import <fabric/core/Props.h>
#import <fabric/view/ViewEventHandlers.h> #import <fabric/view/ViewEventEmitter.h>
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@ -23,7 +23,7 @@ NS_ASSUME_NONNULL_BEGIN
@protected @protected
facebook::react::LayoutMetrics _layoutMetrics; facebook::react::LayoutMetrics _layoutMetrics;
facebook::react::SharedProps _props; facebook::react::SharedProps _props;
facebook::react::SharedViewEventHandlers _eventHandlers; facebook::react::SharedViewEventEmitter _eventEmitter;
} }
@end @end

View File

@ -8,7 +8,7 @@
#import "RCTViewComponentView.h" #import "RCTViewComponentView.h"
#import <fabric/view/ViewProps.h> #import <fabric/view/ViewProps.h>
#import <fabric/view/ViewEventHandlers.h> #import <fabric/view/ViewEventEmitter.h>
using namespace facebook::react; using namespace facebook::react;
@ -33,10 +33,10 @@ using namespace facebook::react;
// TODO: Implement all sutable non-layout <View> props. // TODO: Implement all sutable non-layout <View> props.
} }
- (void)updateEventHandlers:(SharedEventHandlers)eventHandlers - (void)updateEventEmitter:(SharedEventEmitter)eventEmitter
{ {
assert(std::dynamic_pointer_cast<const ViewEventHandlers>(eventHandlers)); assert(std::dynamic_pointer_cast<const ViewEventEmitter>(eventEmitter));
_eventHandlers = std::static_pointer_cast<const ViewEventHandlers>(eventHandlers); _eventEmitter = std::static_pointer_cast<const ViewEventEmitter>(eventEmitter);
} }
- (void)updateLayoutMetrics:(LayoutMetrics)layoutMetrics - (void)updateLayoutMetrics:(LayoutMetrics)layoutMetrics
@ -51,25 +51,25 @@ using namespace facebook::react;
- (BOOL)accessibilityActivate - (BOOL)accessibilityActivate
{ {
_eventHandlers->onAccessibilityTap(); _eventEmitter->onAccessibilityTap();
return YES; return YES;
} }
- (BOOL)accessibilityPerformMagicTap - (BOOL)accessibilityPerformMagicTap
{ {
_eventHandlers->onAccessibilityMagicTap(); _eventEmitter->onAccessibilityMagicTap();
return YES; return YES;
} }
- (BOOL)didActivateAccessibilityCustomAction:(UIAccessibilityCustomAction *)action - (BOOL)didActivateAccessibilityCustomAction:(UIAccessibilityCustomAction *)action
{ {
_eventHandlers->onAccessibilityAction([action.name cStringUsingEncoding:NSASCIIStringEncoding]); _eventEmitter->onAccessibilityAction([action.name cStringUsingEncoding:NSASCIIStringEncoding]);
return YES; return YES;
} }
- (SharedEventHandlers)touchEventHandlers - (SharedEventEmitter)touchEventEmitter
{ {
return _eventHandlers; return _eventEmitter;
} }
@end @end

View File

@ -9,17 +9,17 @@
#import <React/RCTMountItemProtocol.h> #import <React/RCTMountItemProtocol.h>
#import <React/RCTPrimitives.h> #import <React/RCTPrimitives.h>
#import <fabric/core/EventHandlers.h> #import <fabric/core/EventEmitter.h>
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
/** /**
* Updates event handlers of a component view. * Updates event handlers of a component view.
*/ */
@interface RCTUpdateEventHandlersMountItem : NSObject <RCTMountItemProtocol> @interface RCTUpdateEventEmitterMountItem : NSObject <RCTMountItemProtocol>
- (instancetype)initWithTag:(ReactTag)tag - (instancetype)initWithTag:(ReactTag)tag
eventHandlers:(facebook::react::SharedEventHandlers)eventHandlers; eventEmitter:(facebook::react::SharedEventEmitter)eventEmitter;
@end @end

View File

@ -5,23 +5,23 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
#import "RCTUpdateEventHandlersMountItem.h" #import "RCTUpdateEventEmitterMountItem.h"
#import "RCTComponentViewRegistry.h" #import "RCTComponentViewRegistry.h"
using namespace facebook::react; using namespace facebook::react;
@implementation RCTUpdateEventHandlersMountItem { @implementation RCTUpdateEventEmitterMountItem {
ReactTag _tag; ReactTag _tag;
SharedEventHandlers _eventHandlers; SharedEventEmitter _eventEmitter;
} }
- (instancetype)initWithTag:(ReactTag)tag - (instancetype)initWithTag:(ReactTag)tag
eventHandlers:(SharedEventHandlers)eventHandlers eventEmitter:(SharedEventEmitter)eventEmitter
{ {
if (self = [super init]) { if (self = [super init]) {
_tag = tag; _tag = tag;
_eventHandlers = eventHandlers; _eventEmitter = eventEmitter;
} }
return self; return self;
@ -31,7 +31,7 @@ using namespace facebook::react;
{ {
UIView<RCTComponentViewProtocol> *componentView = [registry componentViewByTag:_tag]; UIView<RCTComponentViewProtocol> *componentView = [registry componentViewByTag:_tag];
[componentView updateEventHandlers:_eventHandlers]; [componentView updateEventEmitter:_eventEmitter];
} }
@end @end

View File

@ -7,7 +7,7 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import <fabric/core/EventHandlers.h> #import <fabric/core/EventEmitter.h>
#import <fabric/core/LocalData.h> #import <fabric/core/LocalData.h>
#import <fabric/core/Props.h> #import <fabric/core/Props.h>
#import <fabric/core/LayoutMetrics.h> #import <fabric/core/LayoutMetrics.h>
@ -55,10 +55,10 @@ NS_ASSUME_NONNULL_BEGIN
/* /*
* Called for updating component's event handlers set. * Called for updating component's event handlers set.
* Receiver must cache `eventHandlers` object inside and use it for emitting * Receiver must cache `eventEmitter` object inside and use it for emitting
* events when needed. * events when needed.
*/ */
- (void)updateEventHandlers:(facebook::react::SharedEventHandlers)eventHandlers; - (void)updateEventEmitter:(facebook::react::SharedEventEmitter)eventEmitter;
/* /*
* Called for updating component's layout metrics. * Called for updating component's layout metrics.

View File

@ -20,7 +20,7 @@
#import "RCTInsertMountItem.h" #import "RCTInsertMountItem.h"
#import "RCTRemoveMountItem.h" #import "RCTRemoveMountItem.h"
#import "RCTUpdatePropsMountItem.h" #import "RCTUpdatePropsMountItem.h"
#import "RCTUpdateEventHandlersMountItem.h" #import "RCTUpdateEventEmitterMountItem.h"
#import "RCTUpdateLocalDataMountItem.h" #import "RCTUpdateLocalDataMountItem.h"
#import "RCTUpdateLayoutMetricsMountItem.h" #import "RCTUpdateLayoutMetricsMountItem.h"
@ -71,9 +71,9 @@ using namespace facebook::react;
oldProps:nullptr oldProps:nullptr
newProps:instruction.getNewChildNode()->getProps()]]; newProps:instruction.getNewChildNode()->getProps()]];
// EventHandlers // EventEmitter
[mountItems addObject:[[RCTUpdateEventHandlersMountItem alloc] initWithTag:instruction.getNewChildNode()->getTag() [mountItems addObject:[[RCTUpdateEventEmitterMountItem alloc] initWithTag:instruction.getNewChildNode()->getTag()
eventHandlers:instruction.getNewChildNode()->getEventHandlers()]]; eventEmitter:instruction.getNewChildNode()->getEventEmitter()]];
// LocalData // LocalData
if (instruction.getNewChildNode()->getLocalData()) { if (instruction.getNewChildNode()->getLocalData()) {
@ -124,11 +124,11 @@ using namespace facebook::react;
[mountItems addObject:mountItem]; [mountItems addObject:mountItem];
} }
// EventHandlers // EventEmitter
if (oldShadowNode->getEventHandlers() != newShadowNode->getEventHandlers()) { if (oldShadowNode->getEventEmitter() != newShadowNode->getEventEmitter()) {
RCTUpdateEventHandlersMountItem *mountItem = RCTUpdateEventEmitterMountItem *mountItem =
[[RCTUpdateEventHandlersMountItem alloc] initWithTag:instruction.getOldChildNode()->getTag() [[RCTUpdateEventEmitterMountItem alloc] initWithTag:instruction.getOldChildNode()->getTag()
eventHandlers:instruction.getOldChildNode()->getEventHandlers()]; eventEmitter:instruction.getOldChildNode()->getEventEmitter()];
[mountItems addObject:mountItem]; [mountItems addObject:mountItem];
} }

View File

@ -26,7 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)updateProps:(facebook::react::SharedProps)props - (void)updateProps:(facebook::react::SharedProps)props
oldProps:(facebook::react::SharedProps)oldProps; oldProps:(facebook::react::SharedProps)oldProps;
- (void)updateEventHandlers:(facebook::react::SharedEventHandlers)eventHandlers; - (void)updateEventEmitter:(facebook::react::SharedEventEmitter)eventEmitter;
- (void)updateLocalData:(facebook::react::SharedLocalData)localData - (void)updateLocalData:(facebook::react::SharedLocalData)localData
oldLocalData:(facebook::react::SharedLocalData)oldLocalData; oldLocalData:(facebook::react::SharedLocalData)oldLocalData;

View File

@ -31,7 +31,7 @@
// Default implementation does nothing. // Default implementation does nothing.
} }
- (void)updateEventHandlers:(facebook::react::SharedEventHandlers)eventHandlers - (void)updateEventEmitter:(facebook::react::SharedEventEmitter)eventEmitter
{ {
// Default implementation does nothing. // Default implementation does nothing.
} }

View File

@ -8,7 +8,7 @@
#import "RCTSurfaceTouchHandler.h" #import "RCTSurfaceTouchHandler.h"
#import <UIKit/UIGestureRecognizerSubclass.h> #import <UIKit/UIGestureRecognizerSubclass.h>
#import <fabric/view/ViewEventHandlers.h> #import <fabric/view/ViewEventEmitter.h>
#import <React/RCTUtils.h> #import <React/RCTUtils.h>
#import <React/RCTViewComponentView.h> #import <React/RCTViewComponentView.h>
@ -47,7 +47,7 @@ private:
}; };
@protocol RCTTouchableComponentViewProtocol <NSObject> @protocol RCTTouchableComponentViewProtocol <NSObject>
- (SharedViewEventHandlers)touchEventHandlers; - (SharedViewEventEmitter)touchEventEmitter;
@end @end
typedef NS_ENUM(NSInteger, RCTTouchEventType) { typedef NS_ENUM(NSInteger, RCTTouchEventType) {
@ -59,7 +59,7 @@ typedef NS_ENUM(NSInteger, RCTTouchEventType) {
struct ActiveTouch { struct ActiveTouch {
Touch touch; Touch touch;
SharedViewEventHandlers eventHandlers; SharedViewEventEmitter eventEmitter;
struct Hasher { struct Hasher {
size_t operator()(const ActiveTouch &activeTouch) const { size_t operator()(const ActiveTouch &activeTouch) const {
@ -95,8 +95,8 @@ static ActiveTouch CreateTouchWithUITouch(UITouch *uiTouch, UIView *rootComponen
ActiveTouch activeTouch = {}; ActiveTouch activeTouch = {};
if ([componentView respondsToSelector:@selector(touchEventHandlers)]) { if ([componentView respondsToSelector:@selector(touchEventEmitter)]) {
activeTouch.eventHandlers = [(id<RCTTouchableComponentViewProtocol>)componentView touchEventHandlers]; activeTouch.eventEmitter = [(id<RCTTouchableComponentViewProtocol>)componentView touchEventEmitter];
activeTouch.touch.target = (Tag)componentView.tag; activeTouch.touch.target = (Tag)componentView.tag;
} }
@ -217,23 +217,23 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithTarget:(id)target action:(SEL)action
{ {
TouchEvent event = {}; TouchEvent event = {};
std::unordered_set<ActiveTouch, ActiveTouch::Hasher, ActiveTouch::Comparator> changedActiveTouches = {}; std::unordered_set<ActiveTouch, ActiveTouch::Hasher, ActiveTouch::Comparator> changedActiveTouches = {};
std::unordered_set<SharedViewEventHandlers> uniqueEventHandlers = {}; std::unordered_set<SharedViewEventEmitter> uniqueEventEmitter = {};
BOOL isEndishEventType = eventType == RCTTouchEventTypeTouchEnd || eventType == RCTTouchEventTypeTouchCancel; BOOL isEndishEventType = eventType == RCTTouchEventTypeTouchEnd || eventType == RCTTouchEventTypeTouchCancel;
for (UITouch *touch in touches) { for (UITouch *touch in touches) {
auto &&activeTouch = _activeTouches[touch]; auto &&activeTouch = _activeTouches[touch];
if (!activeTouch.eventHandlers) { if (!activeTouch.eventEmitter) {
continue; continue;
} }
changedActiveTouches.insert(activeTouch); changedActiveTouches.insert(activeTouch);
event.changedTouches.insert(activeTouch.touch); event.changedTouches.insert(activeTouch.touch);
uniqueEventHandlers.insert(activeTouch.eventHandlers); uniqueEventEmitter.insert(activeTouch.eventEmitter);
} }
for (auto &&pair : _activeTouches) { for (auto &&pair : _activeTouches) {
if (!pair.second.eventHandlers) { if (!pair.second.eventEmitter) {
continue; continue;
} }
@ -247,27 +247,27 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithTarget:(id)target action:(SEL)action
event.touches.insert(pair.second.touch); event.touches.insert(pair.second.touch);
} }
for (auto &&eventHandlers : uniqueEventHandlers) { for (auto &&eventEmitter : uniqueEventEmitter) {
event.targetTouches.clear(); event.targetTouches.clear();
for (auto &&pair : _activeTouches) { for (auto &&pair : _activeTouches) {
if (pair.second.eventHandlers == eventHandlers) { if (pair.second.eventEmitter == eventEmitter) {
event.targetTouches.insert(pair.second.touch); event.targetTouches.insert(pair.second.touch);
} }
} }
switch (eventType) { switch (eventType) {
case RCTTouchEventTypeTouchStart: case RCTTouchEventTypeTouchStart:
eventHandlers->onTouchStart(event); eventEmitter->onTouchStart(event);
break; break;
case RCTTouchEventTypeTouchMove: case RCTTouchEventTypeTouchMove:
eventHandlers->onTouchMove(event); eventEmitter->onTouchMove(event);
break; break;
case RCTTouchEventTypeTouchEnd: case RCTTouchEventTypeTouchEnd:
eventHandlers->onTouchEnd(event); eventEmitter->onTouchEnd(event);
break; break;
case RCTTouchEventTypeTouchCancel: case RCTTouchEventTypeTouchCancel:
eventHandlers->onTouchCancel(event); eventEmitter->onTouchCancel(event);
break; break;
} }
} }

View File

@ -47,7 +47,7 @@ public:
virtual SharedShadowNode createShadowNode( virtual SharedShadowNode createShadowNode(
const Tag &tag, const Tag &tag,
const Tag &rootTag, const Tag &rootTag,
const SharedEventHandlers &eventHandlers, const SharedEventEmitter &eventEmitter,
const SharedProps &props const SharedProps &props
) const = 0; ) const = 0;
@ -57,7 +57,7 @@ public:
virtual SharedShadowNode cloneShadowNode( virtual SharedShadowNode cloneShadowNode(
const SharedShadowNode &shadowNode, const SharedShadowNode &shadowNode,
const SharedProps &props = nullptr, const SharedProps &props = nullptr,
const SharedEventHandlers &eventHandlers = nullptr, const SharedEventEmitter &eventEmitter = nullptr,
const SharedShadowNodeSharedList &children = nullptr const SharedShadowNodeSharedList &children = nullptr
) const = 0; ) const = 0;
@ -81,10 +81,10 @@ public:
) const = 0; ) const = 0;
/* /*
* Creates a new `EventHandlers` object compatible with particular type of * Creates a new `EventEmitter` object compatible with particular type of
* shadow nodes. * shadow nodes.
*/ */
virtual SharedEventHandlers createEventHandlers( virtual SharedEventEmitter createEventEmitter(
const InstanceHandle &instanceHandle, const InstanceHandle &instanceHandle,
const Tag &tag const Tag &tag
) const = 0; ) const = 0;

View File

@ -29,8 +29,8 @@ class ConcreteComponentDescriptor: public ComponentDescriptor {
using SharedShadowNodeT = std::shared_ptr<const ShadowNodeT>; using SharedShadowNodeT = std::shared_ptr<const ShadowNodeT>;
using ConcreteProps = typename ShadowNodeT::ConcreteProps; using ConcreteProps = typename ShadowNodeT::ConcreteProps;
using SharedConcreteProps = typename ShadowNodeT::SharedConcreteProps; using SharedConcreteProps = typename ShadowNodeT::SharedConcreteProps;
using ConcreteEventHandlers = typename ShadowNodeT::ConcreteEventHandlers; using ConcreteEventEmitter = typename ShadowNodeT::ConcreteEventEmitter;
using SharedConcreteEventHandlers = typename ShadowNodeT::SharedConcreteEventHandlers; using SharedConcreteEventEmitter = typename ShadowNodeT::SharedConcreteEventEmitter;
public: public:
ConcreteComponentDescriptor(SharedEventDispatcher eventDispatcher): ConcreteComponentDescriptor(SharedEventDispatcher eventDispatcher):
@ -58,17 +58,17 @@ public:
SharedShadowNode createShadowNode( SharedShadowNode createShadowNode(
const Tag &tag, const Tag &tag,
const Tag &rootTag, const Tag &rootTag,
const SharedEventHandlers &eventHandlers, const SharedEventEmitter &eventEmitter,
const SharedProps &props const SharedProps &props
) const override { ) const override {
assert(std::dynamic_pointer_cast<const ConcreteProps>(props)); assert(std::dynamic_pointer_cast<const ConcreteProps>(props));
assert(std::dynamic_pointer_cast<const ConcreteEventHandlers>(eventHandlers)); assert(std::dynamic_pointer_cast<const ConcreteEventEmitter>(eventEmitter));
auto &&shadowNode = std::make_shared<ShadowNodeT>( auto &&shadowNode = std::make_shared<ShadowNodeT>(
tag, tag,
rootTag, rootTag,
std::static_pointer_cast<const ConcreteProps>(props), std::static_pointer_cast<const ConcreteProps>(props),
std::static_pointer_cast<const ConcreteEventHandlers>(eventHandlers), std::static_pointer_cast<const ConcreteEventEmitter>(eventEmitter),
ShadowNode::emptySharedShadowNodeSharedList(), ShadowNode::emptySharedShadowNodeSharedList(),
getCloneFunction() getCloneFunction()
); );
@ -80,7 +80,7 @@ public:
SharedShadowNode cloneShadowNode( SharedShadowNode cloneShadowNode(
const SharedShadowNode &sourceShadowNode, const SharedShadowNode &sourceShadowNode,
const SharedProps &props = nullptr, const SharedProps &props = nullptr,
const SharedEventHandlers &eventHandlers = nullptr, const SharedEventEmitter &eventEmitter = nullptr,
const SharedShadowNodeSharedList &children = nullptr const SharedShadowNodeSharedList &children = nullptr
) const override { ) const override {
assert(std::dynamic_pointer_cast<const ShadowNodeT>(sourceShadowNode)); assert(std::dynamic_pointer_cast<const ShadowNodeT>(sourceShadowNode));
@ -88,7 +88,7 @@ public:
auto &&shadowNode = std::make_shared<ShadowNodeT>( auto &&shadowNode = std::make_shared<ShadowNodeT>(
std::static_pointer_cast<const ShadowNodeT>(sourceShadowNode), std::static_pointer_cast<const ShadowNodeT>(sourceShadowNode),
std::static_pointer_cast<const ConcreteProps>(props), std::static_pointer_cast<const ConcreteProps>(props),
std::static_pointer_cast<const ConcreteEventHandlers>(eventHandlers), std::static_pointer_cast<const ConcreteEventEmitter>(eventEmitter),
children children
); );
@ -112,11 +112,11 @@ public:
return ShadowNodeT::Props(rawProps, props); return ShadowNodeT::Props(rawProps, props);
}; };
virtual SharedEventHandlers createEventHandlers( virtual SharedEventEmitter createEventEmitter(
const InstanceHandle &instanceHandle, const InstanceHandle &instanceHandle,
const Tag &tag const Tag &tag
) const override { ) const override {
return std::make_shared<ConcreteEventHandlers>(instanceHandle, tag, eventDispatcher_); return std::make_shared<ConcreteEventEmitter>(instanceHandle, tag, eventDispatcher_);
} }
protected: protected:
@ -133,9 +133,9 @@ private:
ShadowNodeCloneFunction getCloneFunction() const { ShadowNodeCloneFunction getCloneFunction() const {
if (!cloneFunction_) { if (!cloneFunction_) {
cloneFunction_ = [this](const SharedShadowNode &shadowNode, const SharedProps &props, const SharedEventHandlers &eventHandlers, const SharedShadowNodeSharedList &children) { cloneFunction_ = [this](const SharedShadowNode &shadowNode, const SharedProps &props, const SharedEventEmitter &eventEmitter, const SharedShadowNodeSharedList &children) {
assert(std::dynamic_pointer_cast<const ShadowNodeT>(shadowNode)); assert(std::dynamic_pointer_cast<const ShadowNodeT>(shadowNode));
return this->cloneShadowNode(shadowNode, props, eventHandlers, children); return this->cloneShadowNode(shadowNode, props, eventEmitter, children);
}; };
} }

View File

@ -21,7 +21,7 @@ using SharedEventDispatcher = std::shared_ptr<const EventDispatcher>;
/* /*
* Abstract class that represent event-delivery infrastructure. * Abstract class that represent event-delivery infrastructure.
* Particular `EventHandlers` clases use an object of this class to invoke * Particular `EventEmitter` clases use an object of this class to invoke
* events. * events.
*/ */
class EventDispatcher { class EventDispatcher {

View File

@ -5,23 +5,23 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
#include "EventHandlers.h" #include "EventEmitter.h"
#include <folly/dynamic.h> #include <folly/dynamic.h>
namespace facebook { namespace facebook {
namespace react { namespace react {
EventHandlers::EventHandlers(const InstanceHandle &instanceHandle, const Tag &tag, const SharedEventDispatcher &eventDispatcher): EventEmitter::EventEmitter(const InstanceHandle &instanceHandle, const Tag &tag, const SharedEventDispatcher &eventDispatcher):
instanceHandle_(instanceHandle), instanceHandle_(instanceHandle),
tag_(tag), tag_(tag),
eventDispatcher_(eventDispatcher) {} eventDispatcher_(eventDispatcher) {}
EventHandlers::~EventHandlers() { EventEmitter::~EventEmitter() {
releaseEventTargetIfNeeded(); releaseEventTargetIfNeeded();
} }
void EventHandlers::dispatchEvent( void EventEmitter::dispatchEvent(
const std::string &type, const std::string &type,
const folly::dynamic &payload, const folly::dynamic &payload,
const EventPriority &priority const EventPriority &priority
@ -42,7 +42,7 @@ void EventHandlers::dispatchEvent(
eventDispatcher->dispatchEvent(eventTarget_, type, extendedPayload, priority); eventDispatcher->dispatchEvent(eventTarget_, type, extendedPayload, priority);
} }
void EventHandlers::createEventTargetIfNeeded() const { void EventEmitter::createEventTargetIfNeeded() const {
std::lock_guard<std::mutex> lock(mutex_); std::lock_guard<std::mutex> lock(mutex_);
if (eventTarget_) { if (eventTarget_) {
@ -54,7 +54,7 @@ void EventHandlers::createEventTargetIfNeeded() const {
eventTarget_ = eventDispatcher->createEventTarget(instanceHandle_); eventTarget_ = eventDispatcher->createEventTarget(instanceHandle_);
} }
void EventHandlers::releaseEventTargetIfNeeded() const { void EventEmitter::releaseEventTargetIfNeeded() const {
std::lock_guard<std::mutex> lock(mutex_); std::lock_guard<std::mutex> lock(mutex_);
if (!eventTarget_) { if (!eventTarget_) {

View File

@ -17,9 +17,9 @@
namespace facebook { namespace facebook {
namespace react { namespace react {
class EventHandlers; class EventEmitter;
using SharedEventHandlers = std::shared_ptr<const EventHandlers>; using SharedEventEmitter = std::shared_ptr<const EventEmitter>;
/* /*
* Base class for all particular typed event handlers. * Base class for all particular typed event handlers.
@ -28,11 +28,11 @@ using SharedEventHandlers = std::shared_ptr<const EventHandlers>;
* *
* TODO: Reconsider naming of all event-related things. * TODO: Reconsider naming of all event-related things.
*/ */
class EventHandlers { class EventEmitter {
public: public:
EventHandlers(const InstanceHandle &instanceHandle, const Tag &tag, const SharedEventDispatcher &eventDispatcher); EventEmitter(const InstanceHandle &instanceHandle, const Tag &tag, const SharedEventDispatcher &eventDispatcher);
virtual ~EventHandlers(); virtual ~EventEmitter();
protected: protected:

View File

@ -19,15 +19,15 @@ namespace react {
* `ConcreteShadowNode` is a default implementation of `ShadowNode` interface * `ConcreteShadowNode` is a default implementation of `ShadowNode` interface
* with many handy features. * with many handy features.
*/ */
template <typename PropsT, typename EventHandlersT = EventHandlers> template <typename PropsT, typename EventEmitterT = EventEmitter>
class ConcreteShadowNode: public ShadowNode { class ConcreteShadowNode: public ShadowNode {
static_assert(std::is_base_of<Props, PropsT>::value, "PropsT must be a descendant of Props"); static_assert(std::is_base_of<Props, PropsT>::value, "PropsT must be a descendant of Props");
public: public:
using ConcreteProps = PropsT; using ConcreteProps = PropsT;
using SharedConcreteProps = std::shared_ptr<const PropsT>; using SharedConcreteProps = std::shared_ptr<const PropsT>;
using ConcreteEventHandlers = EventHandlersT; using ConcreteEventEmitter = EventEmitterT;
using SharedConcreteEventHandlers = std::shared_ptr<const EventHandlersT>; using SharedConcreteEventEmitter = std::shared_ptr<const EventEmitterT>;
using SharedConcreteShadowNode = std::shared_ptr<const ConcreteShadowNode>; using SharedConcreteShadowNode = std::shared_ptr<const ConcreteShadowNode>;
static SharedConcreteProps Props(const RawProps &rawProps, const SharedProps &baseProps = nullptr) { static SharedConcreteProps Props(const RawProps &rawProps, const SharedProps &baseProps = nullptr) {
@ -43,7 +43,7 @@ public:
const Tag &tag, const Tag &tag,
const Tag &rootTag, const Tag &rootTag,
const SharedConcreteProps &props, const SharedConcreteProps &props,
const SharedConcreteEventHandlers &eventHandlers, const SharedConcreteEventEmitter &eventEmitter,
const SharedShadowNodeSharedList &children, const SharedShadowNodeSharedList &children,
const ShadowNodeCloneFunction &cloneFunction const ShadowNodeCloneFunction &cloneFunction
): ):
@ -51,7 +51,7 @@ public:
tag, tag,
rootTag, rootTag,
(SharedProps)props, (SharedProps)props,
eventHandlers, eventEmitter,
children, children,
cloneFunction cloneFunction
) {}; ) {};
@ -59,13 +59,13 @@ public:
ConcreteShadowNode( ConcreteShadowNode(
const SharedConcreteShadowNode &shadowNode, const SharedConcreteShadowNode &shadowNode,
const SharedProps &props, const SharedProps &props,
const SharedEventHandlers &eventHandlers, const SharedEventEmitter &eventEmitter,
const SharedShadowNodeSharedList &children const SharedShadowNodeSharedList &children
): ):
ShadowNode( ShadowNode(
shadowNode, shadowNode,
(SharedProps)props, (SharedProps)props,
eventHandlers, eventEmitter,
children children
) {} ) {}

View File

@ -24,14 +24,14 @@ ShadowNode::ShadowNode(
const Tag &tag, const Tag &tag,
const Tag &rootTag, const Tag &rootTag,
const SharedProps &props, const SharedProps &props,
const SharedEventHandlers &eventHandlers, const SharedEventEmitter &eventEmitter,
const SharedShadowNodeSharedList &children, const SharedShadowNodeSharedList &children,
const ShadowNodeCloneFunction &cloneFunction const ShadowNodeCloneFunction &cloneFunction
): ):
tag_(tag), tag_(tag),
rootTag_(rootTag), rootTag_(rootTag),
props_(props), props_(props),
eventHandlers_(eventHandlers), eventEmitter_(eventEmitter),
children_(std::make_shared<SharedShadowNodeList>(*children)), children_(std::make_shared<SharedShadowNodeList>(*children)),
cloneFunction_(cloneFunction), cloneFunction_(cloneFunction),
revision_(1) {} revision_(1) {}
@ -39,13 +39,13 @@ ShadowNode::ShadowNode(
ShadowNode::ShadowNode( ShadowNode::ShadowNode(
const SharedShadowNode &shadowNode, const SharedShadowNode &shadowNode,
const SharedProps &props, const SharedProps &props,
const SharedEventHandlers &eventHandlers, const SharedEventEmitter &eventEmitter,
const SharedShadowNodeSharedList &children const SharedShadowNodeSharedList &children
): ):
tag_(shadowNode->tag_), tag_(shadowNode->tag_),
rootTag_(shadowNode->rootTag_), rootTag_(shadowNode->rootTag_),
props_(props ? props : shadowNode->props_), props_(props ? props : shadowNode->props_),
eventHandlers_(eventHandlers ? eventHandlers : shadowNode->eventHandlers_), eventEmitter_(eventEmitter ? eventEmitter : shadowNode->eventEmitter_),
children_(std::make_shared<SharedShadowNodeList>(*(children ? children : shadowNode->children_))), children_(std::make_shared<SharedShadowNodeList>(*(children ? children : shadowNode->children_))),
sourceNode_(shadowNode), sourceNode_(shadowNode),
localData_(shadowNode->localData_), localData_(shadowNode->localData_),
@ -57,7 +57,7 @@ SharedShadowNode ShadowNode::clone(
const SharedShadowNodeSharedList &children const SharedShadowNodeSharedList &children
) const { ) const {
assert(cloneFunction_); assert(cloneFunction_);
return cloneFunction_(shared_from_this(), props_, eventHandlers_, children_); return cloneFunction_(shared_from_this(), props_, eventEmitter_, children_);
} }
#pragma mark - Getters #pragma mark - Getters
@ -70,8 +70,8 @@ SharedProps ShadowNode::getProps() const {
return props_; return props_;
} }
SharedEventHandlers ShadowNode::getEventHandlers() const { SharedEventEmitter ShadowNode::getEventEmitter() const {
return eventHandlers_; return eventEmitter_;
} }
Tag ShadowNode::getTag() const { Tag ShadowNode::getTag() const {
@ -147,7 +147,7 @@ bool ShadowNode::operator==(const ShadowNode& rhs) const {
tag_ == rhs.tag_ && tag_ == rhs.tag_ &&
rootTag_ == rhs.rootTag_ && rootTag_ == rhs.rootTag_ &&
props_ == rhs.props_ && props_ == rhs.props_ &&
eventHandlers_ == rhs.eventHandlers_ && eventEmitter_ == rhs.eventEmitter_ &&
localData_ == rhs.localData_; localData_ == rhs.localData_;
} }

View File

@ -11,7 +11,7 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include <fabric/core/EventHandlers.h> #include <fabric/core/EventEmitter.h>
#include <fabric/core/LocalData.h> #include <fabric/core/LocalData.h>
#include <fabric/core/Props.h> #include <fabric/core/Props.h>
#include <fabric/core/ReactPrimitives.h> #include <fabric/core/ReactPrimitives.h>
@ -33,7 +33,7 @@ using WeakShadowNode = std::weak_ptr<const ShadowNode>;
using ShadowNodeCloneFunction = std::function<SharedShadowNode( using ShadowNodeCloneFunction = std::function<SharedShadowNode(
const SharedShadowNode &shadowNode, const SharedShadowNode &shadowNode,
const SharedProps &props, const SharedProps &props,
const SharedEventHandlers &eventHandlers, const SharedEventEmitter &eventEmitter,
const SharedShadowNodeSharedList &children const SharedShadowNodeSharedList &children
)>; )>;
@ -50,7 +50,7 @@ public:
const Tag &tag, const Tag &tag,
const Tag &rootTag, const Tag &rootTag,
const SharedProps &props, const SharedProps &props,
const SharedEventHandlers &eventHandlers, const SharedEventEmitter &eventEmitter,
const SharedShadowNodeSharedList &children, const SharedShadowNodeSharedList &children,
const ShadowNodeCloneFunction &cloneFunction const ShadowNodeCloneFunction &cloneFunction
); );
@ -58,7 +58,7 @@ public:
ShadowNode( ShadowNode(
const SharedShadowNode &shadowNode, const SharedShadowNode &shadowNode,
const SharedProps &props, const SharedProps &props,
const SharedEventHandlers &eventHandlers, const SharedEventEmitter &eventEmitter,
const SharedShadowNodeSharedList &children const SharedShadowNodeSharedList &children
); );
@ -77,7 +77,7 @@ public:
SharedShadowNodeSharedList getChildren() const; SharedShadowNodeSharedList getChildren() const;
SharedProps getProps() const; SharedProps getProps() const;
SharedEventHandlers getEventHandlers() const; SharedEventEmitter getEventEmitter() const;
Tag getTag() const; Tag getTag() const;
Tag getRootTag() const; Tag getRootTag() const;
@ -143,7 +143,7 @@ protected:
Tag tag_; Tag tag_;
Tag rootTag_; Tag rootTag_;
SharedProps props_; SharedProps props_;
SharedEventHandlers eventHandlers_; SharedEventEmitter eventEmitter_;
SharedShadowNodeSharedList children_; SharedShadowNodeSharedList children_;
WeakShadowNode sourceNode_; WeakShadowNode sourceNode_;
SharedLocalData localData_; SharedLocalData localData_;

View File

@ -34,7 +34,7 @@ TEST(ShadowNodeTest, handleShadowNodeCreation) {
ASSERT_STREQ(node->getComponentName().c_str(), "Test"); ASSERT_STREQ(node->getComponentName().c_str(), "Test");
ASSERT_EQ(node->getTag(), 9); ASSERT_EQ(node->getTag(), 9);
ASSERT_EQ(node->getRootTag(), 1); ASSERT_EQ(node->getRootTag(), 1);
ASSERT_EQ(node->getEventHandlers(), nullptr); ASSERT_EQ(node->getEventEmitter(), nullptr);
TestShadowNode *nodePtr = node.get(); TestShadowNode *nodePtr = node.get();
ASSERT_EQ(node->getComponentHandle(), typeid(*nodePtr).hash_code()); ASSERT_EQ(node->getComponentHandle(), typeid(*nodePtr).hash_code());
ASSERT_EQ(node->getSourceNode(), nullptr); ASSERT_EQ(node->getSourceNode(), nullptr);
@ -54,7 +54,7 @@ TEST(ShadowNodeTest, handleShadowNodeSimpleCloning) {
ASSERT_STREQ(node->getComponentName().c_str(), "Test"); ASSERT_STREQ(node->getComponentName().c_str(), "Test");
ASSERT_EQ(node->getTag(), 9); ASSERT_EQ(node->getTag(), 9);
ASSERT_EQ(node->getRootTag(), 1); ASSERT_EQ(node->getRootTag(), 1);
ASSERT_EQ(node->getEventHandlers(), nullptr); ASSERT_EQ(node->getEventEmitter(), nullptr);
ASSERT_EQ(node2->getSourceNode(), node); ASSERT_EQ(node2->getSourceNode(), node);
} }
@ -128,7 +128,7 @@ TEST(ShadowNodeTest, handleCloneFunction) {
std::make_shared<const TestProps>(), std::make_shared<const TestProps>(),
nullptr, nullptr,
ShadowNode::emptySharedShadowNodeSharedList(), ShadowNode::emptySharedShadowNodeSharedList(),
[](const SharedShadowNode &shadowNode, const SharedProps &props, const SharedEventHandlers &eventHandlers, const SharedShadowNodeSharedList &children) { [](const SharedShadowNode &shadowNode, const SharedProps &props, const SharedEventEmitter &eventEmitter, const SharedShadowNodeSharedList &children) {
return std::make_shared<const TestShadowNode>( return std::make_shared<const TestShadowNode>(
std::static_pointer_cast<const TestShadowNode>(shadowNode), std::static_pointer_cast<const TestShadowNode>(shadowNode),
props, props,

View File

@ -5,32 +5,32 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
#include "ScrollViewEventHandlers.h" #include "ScrollViewEventEmitter.h"
namespace facebook { namespace facebook {
namespace react { namespace react {
void ScrollViewEventHandlers::onScroll(const ScrollViewMetrics &scrollViewMetrics) const { void ScrollViewEventEmitter::onScroll(const ScrollViewMetrics &scrollViewMetrics) const {
dispatchScrollViewEvent("scroll", scrollViewMetrics); dispatchScrollViewEvent("scroll", scrollViewMetrics);
} }
void ScrollViewEventHandlers::onScrollBeginDrag(const ScrollViewMetrics &scrollViewMetrics) const { void ScrollViewEventEmitter::onScrollBeginDrag(const ScrollViewMetrics &scrollViewMetrics) const {
dispatchScrollViewEvent("scrollBeginDrag", scrollViewMetrics); dispatchScrollViewEvent("scrollBeginDrag", scrollViewMetrics);
} }
void ScrollViewEventHandlers::onScrollEndDrag(const ScrollViewMetrics &scrollViewMetrics) const { void ScrollViewEventEmitter::onScrollEndDrag(const ScrollViewMetrics &scrollViewMetrics) const {
dispatchScrollViewEvent("scrollEndDrag", scrollViewMetrics); dispatchScrollViewEvent("scrollEndDrag", scrollViewMetrics);
} }
void ScrollViewEventHandlers::onMomentumScrollBegin(const ScrollViewMetrics &scrollViewMetrics) const { void ScrollViewEventEmitter::onMomentumScrollBegin(const ScrollViewMetrics &scrollViewMetrics) const {
dispatchScrollViewEvent("momentumScrollBegin", scrollViewMetrics); dispatchScrollViewEvent("momentumScrollBegin", scrollViewMetrics);
} }
void ScrollViewEventHandlers::onMomentumScrollEnd(const ScrollViewMetrics &scrollViewMetrics) const { void ScrollViewEventEmitter::onMomentumScrollEnd(const ScrollViewMetrics &scrollViewMetrics) const {
dispatchScrollViewEvent("momentumScrollEnd", scrollViewMetrics); dispatchScrollViewEvent("momentumScrollEnd", scrollViewMetrics);
} }
void ScrollViewEventHandlers::dispatchScrollViewEvent(const std::string &name, const ScrollViewMetrics &scrollViewMetrics, const folly::dynamic &payload) const { void ScrollViewEventEmitter::dispatchScrollViewEvent(const std::string &name, const ScrollViewMetrics &scrollViewMetrics, const folly::dynamic &payload) const {
folly::dynamic compoundPayload = folly::dynamic::object(); folly::dynamic compoundPayload = folly::dynamic::object();
compoundPayload["contentOffset"] = folly::dynamic::object compoundPayload["contentOffset"] = folly::dynamic::object

View File

@ -9,8 +9,8 @@
#include <memory> #include <memory>
#include <fabric/graphics/Geometry.h> #include <fabric/graphics/Geometry.h>
#include <fabric/core/EventHandlers.h> #include <fabric/core/EventEmitter.h>
#include <fabric/view/ViewEventHandlers.h> #include <fabric/view/ViewEventEmitter.h>
#include <folly/dynamic.h> #include <folly/dynamic.h>
@ -26,16 +26,16 @@ public:
Float zoomScale; Float zoomScale;
}; };
class ScrollViewEventHandlers; class ScrollViewEventEmitter;
using SharedScrollViewEventHandlers = std::shared_ptr<const ScrollViewEventHandlers>; using SharedScrollViewEventEmitter = std::shared_ptr<const ScrollViewEventEmitter>;
class ScrollViewEventHandlers: class ScrollViewEventEmitter:
public ViewEventHandlers { public ViewEventEmitter {
public: public:
using ViewEventHandlers::ViewEventHandlers; using ViewEventEmitter::ViewEventEmitter;
void onScroll(const ScrollViewMetrics &scrollViewMetrics) const; void onScroll(const ScrollViewMetrics &scrollViewMetrics) const;
void onScrollBeginDrag(const ScrollViewMetrics &scrollViewMetrics) const; void onScrollBeginDrag(const ScrollViewMetrics &scrollViewMetrics) const;

View File

@ -10,7 +10,7 @@
#include <memory> #include <memory>
#include <fabric/core/LayoutContext.h> #include <fabric/core/LayoutContext.h>
#include <fabric/scrollview/ScrollViewEventHandlers.h> #include <fabric/scrollview/ScrollViewEventEmitter.h>
#include <fabric/scrollview/ScrollViewProps.h> #include <fabric/scrollview/ScrollViewProps.h>
#include <fabric/view/ConcreteViewShadowNode.h> #include <fabric/view/ConcreteViewShadowNode.h>
@ -25,7 +25,7 @@ using SharedScrollViewShadowNode = std::shared_ptr<const ScrollViewShadowNode>;
* `ShadowNode` for <ScrollView> component. * `ShadowNode` for <ScrollView> component.
*/ */
class ScrollViewShadowNode final: class ScrollViewShadowNode final:
public ConcreteViewShadowNode<ScrollViewProps, ScrollViewEventHandlers> { public ConcreteViewShadowNode<ScrollViewProps, ScrollViewEventEmitter> {
public: public:

View File

@ -134,7 +134,7 @@ SharedShadowNode FabricUIManager::createNode(int tag, std::string viewName, int
componentDescriptor->createShadowNode( componentDescriptor->createShadowNode(
tag, tag,
rootTag, rootTag,
componentDescriptor->createEventHandlers(instanceHandle, tag), componentDescriptor->createEventEmitter(instanceHandle, tag),
componentDescriptor->cloneProps(nullptr, rawProps) componentDescriptor->cloneProps(nullptr, rawProps)
); );
@ -155,7 +155,7 @@ SharedShadowNode FabricUIManager::cloneNode(const SharedShadowNode &shadowNode,
componentDescriptor->cloneShadowNode( componentDescriptor->cloneShadowNode(
shadowNode, shadowNode,
nullptr, nullptr,
componentDescriptor->createEventHandlers(instanceHandle, shadowNode->getTag()), componentDescriptor->createEventEmitter(instanceHandle, shadowNode->getTag()),
nullptr nullptr
); );
@ -172,7 +172,7 @@ SharedShadowNode FabricUIManager::cloneNodeWithNewChildren(const SharedShadowNod
componentDescriptor->cloneShadowNode( componentDescriptor->cloneShadowNode(
shadowNode, shadowNode,
nullptr, nullptr,
componentDescriptor->createEventHandlers(instanceHandle, shadowNode->getTag()), componentDescriptor->createEventEmitter(instanceHandle, shadowNode->getTag()),
ShadowNode::emptySharedShadowNodeSharedList() ShadowNode::emptySharedShadowNodeSharedList()
); );
@ -190,7 +190,7 @@ SharedShadowNode FabricUIManager::cloneNodeWithNewProps(const SharedShadowNode &
componentDescriptor->cloneShadowNode( componentDescriptor->cloneShadowNode(
shadowNode, shadowNode,
componentDescriptor->cloneProps(shadowNode->getProps(), rawProps), componentDescriptor->cloneProps(shadowNode->getProps(), rawProps),
componentDescriptor->createEventHandlers(instanceHandle, shadowNode->getTag()), componentDescriptor->createEventEmitter(instanceHandle, shadowNode->getTag()),
nullptr nullptr
); );
@ -208,7 +208,7 @@ SharedShadowNode FabricUIManager::cloneNodeWithNewChildrenAndProps(const SharedS
componentDescriptor->cloneShadowNode( componentDescriptor->cloneShadowNode(
shadowNode, shadowNode,
componentDescriptor->cloneProps(shadowNode->getProps(), rawProps), componentDescriptor->cloneProps(shadowNode->getProps(), rawProps),
componentDescriptor->createEventHandlers(instanceHandle, shadowNode->getTag()), componentDescriptor->createEventEmitter(instanceHandle, shadowNode->getTag()),
ShadowNode::emptySharedShadowNodeSharedList() ShadowNode::emptySharedShadowNodeSharedList()
); );

View File

@ -18,12 +18,12 @@ namespace react {
ShadowTree::ShadowTree(Tag rootTag): ShadowTree::ShadowTree(Tag rootTag):
rootTag_(rootTag) { rootTag_(rootTag) {
auto &&noopEventHandlers = std::make_shared<const ViewEventHandlers>(nullptr, rootTag, nullptr); auto &&noopEventEmitter = std::make_shared<const ViewEventEmitter>(nullptr, rootTag, nullptr);
rootShadowNode_ = std::make_shared<RootShadowNode>( rootShadowNode_ = std::make_shared<RootShadowNode>(
rootTag, rootTag,
rootTag, rootTag,
RootShadowNode::defaultSharedProps(), RootShadowNode::defaultSharedProps(),
noopEventHandlers, noopEventEmitter,
ShadowNode::emptySharedShadowNodeSharedList(), ShadowNode::emptySharedShadowNodeSharedList(),
nullptr nullptr
); );
@ -108,11 +108,11 @@ void ShadowTree::emitLayoutEvents(const TreeMutationInstructionList &instruction
type == TreeMutationInstruction::Replacement type == TreeMutationInstruction::Replacement
) { ) {
auto &&newShadowNode = instruction.getNewChildNode(); auto &&newShadowNode = instruction.getNewChildNode();
auto &&eventHandlers = newShadowNode->getEventHandlers(); auto &&eventEmitter = newShadowNode->getEventEmitter();
auto &&viewEventHandlers = std::dynamic_pointer_cast<const ViewEventHandlers>(eventHandlers); auto &&viewEventEmitter = std::dynamic_pointer_cast<const ViewEventEmitter>(eventEmitter);
// Checking if particular shadow node supports `onLayout` event (part of `ViewEventHandlers`). // Checking if particular shadow node supports `onLayout` event (part of `ViewEventEmitter`).
if (viewEventHandlers) { if (viewEventEmitter) {
// Now we know that both (old and new) shadow nodes must be `LayoutableShadowNode` subclasses. // Now we know that both (old and new) shadow nodes must be `LayoutableShadowNode` subclasses.
assert(std::dynamic_pointer_cast<const LayoutableShadowNode>(newShadowNode)); assert(std::dynamic_pointer_cast<const LayoutableShadowNode>(newShadowNode));
// TODO(T29661055): Consider using `std::reinterpret_pointer_cast`. // TODO(T29661055): Consider using `std::reinterpret_pointer_cast`.
@ -132,7 +132,7 @@ void ShadowTree::emitLayoutEvents(const TreeMutationInstructionList &instruction
} }
} }
viewEventHandlers->onLayout(newLayoutableShadowNode->getLayoutMetrics()); viewEventEmitter->onLayout(newLayoutableShadowNode->getLayoutMetrics());
} }
} }
} }

View File

@ -12,7 +12,7 @@
#include <fabric/core/ShadowNode.h> #include <fabric/core/ShadowNode.h>
#include <fabric/debug/DebugStringConvertibleItem.h> #include <fabric/debug/DebugStringConvertibleItem.h>
#include <fabric/view/AccessibleShadowNode.h> #include <fabric/view/AccessibleShadowNode.h>
#include <fabric/view/ViewEventHandlers.h> #include <fabric/view/ViewEventEmitter.h>
#include <fabric/view/ViewProps.h> #include <fabric/view/ViewProps.h>
#include <fabric/view/YogaLayoutableShadowNode.h> #include <fabric/view/YogaLayoutableShadowNode.h>
@ -24,9 +24,9 @@ namespace react {
* as <View> and similar basic behaviour). * as <View> and similar basic behaviour).
* For example: <Paragraph>, <Image>, but not <Text>, <RawText>. * For example: <Paragraph>, <Image>, but not <Text>, <RawText>.
*/ */
template <typename ViewPropsT = ViewProps, typename ViewEventHandlersT = ViewEventHandlers> template <typename ViewPropsT = ViewProps, typename ViewEventEmitterT = ViewEventEmitter>
class ConcreteViewShadowNode: class ConcreteViewShadowNode:
public ConcreteShadowNode<ViewPropsT, ViewEventHandlersT>, public ConcreteShadowNode<ViewPropsT, ViewEventEmitterT>,
public AccessibleShadowNode, public AccessibleShadowNode,
public YogaLayoutableShadowNode { public YogaLayoutableShadowNode {
@ -38,23 +38,23 @@ public:
using ConcreteViewProps = ViewPropsT; using ConcreteViewProps = ViewPropsT;
using SharedConcreteViewProps = std::shared_ptr<const ViewPropsT>; using SharedConcreteViewProps = std::shared_ptr<const ViewPropsT>;
using ConcreteViewEventHandlers = ViewEventHandlersT; using ConcreteViewEventEmitter = ViewEventEmitterT;
using SharedConcreteViewEventHandlers = std::shared_ptr<const ViewEventHandlersT>; using SharedConcreteViewEventEmitter = std::shared_ptr<const ViewEventEmitterT>;
using SharedConcreteViewShadowNode = std::shared_ptr<const ConcreteViewShadowNode>; using SharedConcreteViewShadowNode = std::shared_ptr<const ConcreteViewShadowNode>;
ConcreteViewShadowNode( ConcreteViewShadowNode(
const Tag &tag, const Tag &tag,
const Tag &rootTag, const Tag &rootTag,
const SharedConcreteViewProps &props, const SharedConcreteViewProps &props,
const SharedConcreteViewEventHandlers &eventHandlers, const SharedConcreteViewEventEmitter &eventEmitter,
const SharedShadowNodeSharedList &children, const SharedShadowNodeSharedList &children,
const ShadowNodeCloneFunction &cloneFunction const ShadowNodeCloneFunction &cloneFunction
): ):
ConcreteShadowNode<ViewPropsT, ViewEventHandlersT>( ConcreteShadowNode<ViewPropsT, ViewEventEmitterT>(
tag, tag,
rootTag, rootTag,
props, props,
eventHandlers, eventEmitter,
children, children,
cloneFunction cloneFunction
), ),
@ -69,13 +69,13 @@ public:
ConcreteViewShadowNode( ConcreteViewShadowNode(
const SharedConcreteViewShadowNode &shadowNode, const SharedConcreteViewShadowNode &shadowNode,
const SharedConcreteViewProps &props, const SharedConcreteViewProps &props,
const SharedConcreteViewEventHandlers &eventHandlers, const SharedConcreteViewEventEmitter &eventEmitter,
const SharedShadowNodeSharedList &children const SharedShadowNodeSharedList &children
): ):
ConcreteShadowNode<ViewPropsT, ViewEventHandlersT>( ConcreteShadowNode<ViewPropsT, ViewEventEmitterT>(
shadowNode, shadowNode,
props, props,
eventHandlers, eventEmitter,
children children
), ),
AccessibleShadowNode( AccessibleShadowNode(

View File

@ -5,28 +5,28 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
#include "ViewEventHandlers.h" #include "ViewEventEmitter.h"
namespace facebook { namespace facebook {
namespace react { namespace react {
#pragma mark - Accessibility #pragma mark - Accessibility
void ViewEventHandlers::onAccessibilityAction(const std::string &name) const { void ViewEventEmitter::onAccessibilityAction(const std::string &name) const {
dispatchEvent("accessibilityAction", folly::dynamic::object("action", name)); dispatchEvent("accessibilityAction", folly::dynamic::object("action", name));
} }
void ViewEventHandlers::onAccessibilityTap() const { void ViewEventEmitter::onAccessibilityTap() const {
dispatchEvent("accessibilityTap"); dispatchEvent("accessibilityTap");
} }
void ViewEventHandlers::onAccessibilityMagicTap() const { void ViewEventEmitter::onAccessibilityMagicTap() const {
dispatchEvent("magicTap"); dispatchEvent("magicTap");
} }
#pragma mark - Layout #pragma mark - Layout
void ViewEventHandlers::onLayout(const LayoutMetrics &layoutMetrics) const { void ViewEventEmitter::onLayout(const LayoutMetrics &layoutMetrics) const {
folly::dynamic payload = folly::dynamic::object(); folly::dynamic payload = folly::dynamic::object();
auto &&frame = layoutMetrics.frame; auto &&frame = layoutMetrics.frame;
payload["layout"] = folly::dynamic::object payload["layout"] = folly::dynamic::object
@ -71,19 +71,19 @@ static folly::dynamic touchEventPayload(const TouchEvent &event) {
return object; return object;
} }
void ViewEventHandlers::onTouchStart(const TouchEvent &event) const { void ViewEventEmitter::onTouchStart(const TouchEvent &event) const {
dispatchEvent("touchStart", touchEventPayload(event)); dispatchEvent("touchStart", touchEventPayload(event));
} }
void ViewEventHandlers::onTouchMove(const TouchEvent &event) const { void ViewEventEmitter::onTouchMove(const TouchEvent &event) const {
dispatchEvent("touchMove", touchEventPayload(event)); dispatchEvent("touchMove", touchEventPayload(event));
} }
void ViewEventHandlers::onTouchEnd(const TouchEvent &event) const { void ViewEventEmitter::onTouchEnd(const TouchEvent &event) const {
dispatchEvent("touchEnd", touchEventPayload(event)); dispatchEvent("touchEnd", touchEventPayload(event));
} }
void ViewEventHandlers::onTouchCancel(const TouchEvent &event) const { void ViewEventEmitter::onTouchCancel(const TouchEvent &event) const {
dispatchEvent("touchCancel", touchEventPayload(event)); dispatchEvent("touchCancel", touchEventPayload(event));
} }

View File

@ -8,7 +8,7 @@
#include <memory> #include <memory>
#include <fabric/core/EventHandlers.h> #include <fabric/core/EventEmitter.h>
#include <fabric/core/LayoutMetrics.h> #include <fabric/core/LayoutMetrics.h>
#include <fabric/core/ReactPrimitives.h> #include <fabric/core/ReactPrimitives.h>
@ -97,16 +97,16 @@ struct TouchEvent {
Touches targetTouches; Touches targetTouches;
}; };
class ViewEventHandlers; class ViewEventEmitter;
using SharedViewEventHandlers = std::shared_ptr<const ViewEventHandlers>; using SharedViewEventEmitter = std::shared_ptr<const ViewEventEmitter>;
class ViewEventHandlers: class ViewEventEmitter:
public EventHandlers { public EventEmitter {
public: public:
using EventHandlers::EventHandlers; using EventEmitter::EventEmitter;
#pragma mark - Accessibility #pragma mark - Accessibility

View File

@ -20,7 +20,7 @@ class ViewShadowNode;
using SharedViewShadowNode = std::shared_ptr<const ViewShadowNode>; using SharedViewShadowNode = std::shared_ptr<const ViewShadowNode>;
class ViewShadowNode final: class ViewShadowNode final:
public ConcreteViewShadowNode<ViewProps, ViewEventHandlers> { public ConcreteViewShadowNode<ViewProps, ViewEventEmitter> {
public: public: