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/scrollview/ScrollViewLocalData.h>
#import <fabric/scrollview/ScrollViewProps.h>
#import <fabric/scrollview/ScrollViewEventHandlers.h>
#import <fabric/scrollview/ScrollViewEventEmitter.h>
#import "RCTConversions.h"
#import "RCTEnhancedScrollView.h"
@ -135,47 +135,47 @@ using namespace facebook::react;
- (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
{
std::static_pointer_cast<const ScrollViewEventHandlers>(_eventHandlers)->onScroll([self _scrollViewMetrics]);
std::static_pointer_cast<const ScrollViewEventEmitter>(_eventEmitter)->onScroll([self _scrollViewMetrics]);
}
- (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
{
std::static_pointer_cast<const ScrollViewEventHandlers>(_eventHandlers)->onScrollEndDrag([self _scrollViewMetrics]);
std::static_pointer_cast<const ScrollViewEventEmitter>(_eventEmitter)->onScrollEndDrag([self _scrollViewMetrics]);
}
- (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
{
std::static_pointer_cast<const ScrollViewEventHandlers>(_eventHandlers)->onMomentumScrollEnd([self _scrollViewMetrics]);
std::static_pointer_cast<const ScrollViewEventEmitter>(_eventEmitter)->onMomentumScrollEnd([self _scrollViewMetrics]);
}
- (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
{
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
{
std::static_pointer_cast<const ScrollViewEventHandlers>(_eventHandlers)->onScrollEndDrag([self _scrollViewMetrics]);
std::static_pointer_cast<const ScrollViewEventEmitter>(_eventEmitter)->onScrollEndDrag([self _scrollViewMetrics]);
}
@end

View File

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

View File

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

View File

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

View File

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

View File

@ -7,7 +7,7 @@
#import <UIKit/UIKit.h>
#import <fabric/core/EventHandlers.h>
#import <fabric/core/EventEmitter.h>
#import <fabric/core/LocalData.h>
#import <fabric/core/Props.h>
#import <fabric/core/LayoutMetrics.h>
@ -55,10 +55,10 @@ NS_ASSUME_NONNULL_BEGIN
/*
* 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.
*/
- (void)updateEventHandlers:(facebook::react::SharedEventHandlers)eventHandlers;
- (void)updateEventEmitter:(facebook::react::SharedEventEmitter)eventEmitter;
/*
* Called for updating component's layout metrics.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -29,8 +29,8 @@ class ConcreteComponentDescriptor: public ComponentDescriptor {
using SharedShadowNodeT = std::shared_ptr<const ShadowNodeT>;
using ConcreteProps = typename ShadowNodeT::ConcreteProps;
using SharedConcreteProps = typename ShadowNodeT::SharedConcreteProps;
using ConcreteEventHandlers = typename ShadowNodeT::ConcreteEventHandlers;
using SharedConcreteEventHandlers = typename ShadowNodeT::SharedConcreteEventHandlers;
using ConcreteEventEmitter = typename ShadowNodeT::ConcreteEventEmitter;
using SharedConcreteEventEmitter = typename ShadowNodeT::SharedConcreteEventEmitter;
public:
ConcreteComponentDescriptor(SharedEventDispatcher eventDispatcher):
@ -58,17 +58,17 @@ public:
SharedShadowNode createShadowNode(
const Tag &tag,
const Tag &rootTag,
const SharedEventHandlers &eventHandlers,
const SharedEventEmitter &eventEmitter,
const SharedProps &props
) const override {
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>(
tag,
rootTag,
std::static_pointer_cast<const ConcreteProps>(props),
std::static_pointer_cast<const ConcreteEventHandlers>(eventHandlers),
std::static_pointer_cast<const ConcreteEventEmitter>(eventEmitter),
ShadowNode::emptySharedShadowNodeSharedList(),
getCloneFunction()
);
@ -80,7 +80,7 @@ public:
SharedShadowNode cloneShadowNode(
const SharedShadowNode &sourceShadowNode,
const SharedProps &props = nullptr,
const SharedEventHandlers &eventHandlers = nullptr,
const SharedEventEmitter &eventEmitter = nullptr,
const SharedShadowNodeSharedList &children = nullptr
) const override {
assert(std::dynamic_pointer_cast<const ShadowNodeT>(sourceShadowNode));
@ -88,7 +88,7 @@ public:
auto &&shadowNode = std::make_shared<ShadowNodeT>(
std::static_pointer_cast<const ShadowNodeT>(sourceShadowNode),
std::static_pointer_cast<const ConcreteProps>(props),
std::static_pointer_cast<const ConcreteEventHandlers>(eventHandlers),
std::static_pointer_cast<const ConcreteEventEmitter>(eventEmitter),
children
);
@ -112,11 +112,11 @@ public:
return ShadowNodeT::Props(rawProps, props);
};
virtual SharedEventHandlers createEventHandlers(
virtual SharedEventEmitter createEventEmitter(
const InstanceHandle &instanceHandle,
const Tag &tag
) const override {
return std::make_shared<ConcreteEventHandlers>(instanceHandle, tag, eventDispatcher_);
return std::make_shared<ConcreteEventEmitter>(instanceHandle, tag, eventDispatcher_);
}
protected:
@ -133,9 +133,9 @@ private:
ShadowNodeCloneFunction getCloneFunction() const {
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));
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.
* Particular `EventHandlers` clases use an object of this class to invoke
* Particular `EventEmitter` clases use an object of this class to invoke
* events.
*/
class EventDispatcher {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -34,7 +34,7 @@ TEST(ShadowNodeTest, handleShadowNodeCreation) {
ASSERT_STREQ(node->getComponentName().c_str(), "Test");
ASSERT_EQ(node->getTag(), 9);
ASSERT_EQ(node->getRootTag(), 1);
ASSERT_EQ(node->getEventHandlers(), nullptr);
ASSERT_EQ(node->getEventEmitter(), nullptr);
TestShadowNode *nodePtr = node.get();
ASSERT_EQ(node->getComponentHandle(), typeid(*nodePtr).hash_code());
ASSERT_EQ(node->getSourceNode(), nullptr);
@ -54,7 +54,7 @@ TEST(ShadowNodeTest, handleShadowNodeSimpleCloning) {
ASSERT_STREQ(node->getComponentName().c_str(), "Test");
ASSERT_EQ(node->getTag(), 9);
ASSERT_EQ(node->getRootTag(), 1);
ASSERT_EQ(node->getEventHandlers(), nullptr);
ASSERT_EQ(node->getEventEmitter(), nullptr);
ASSERT_EQ(node2->getSourceNode(), node);
}
@ -128,7 +128,7 @@ TEST(ShadowNodeTest, handleCloneFunction) {
std::make_shared<const TestProps>(),
nullptr,
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>(
std::static_pointer_cast<const TestShadowNode>(shadowNode),
props,

View File

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

View File

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

View File

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

View File

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

View File

@ -18,12 +18,12 @@ namespace react {
ShadowTree::ShadowTree(Tag 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>(
rootTag,
rootTag,
RootShadowNode::defaultSharedProps(),
noopEventHandlers,
noopEventEmitter,
ShadowNode::emptySharedShadowNodeSharedList(),
nullptr
);
@ -108,11 +108,11 @@ void ShadowTree::emitLayoutEvents(const TreeMutationInstructionList &instruction
type == TreeMutationInstruction::Replacement
) {
auto &&newShadowNode = instruction.getNewChildNode();
auto &&eventHandlers = newShadowNode->getEventHandlers();
auto &&viewEventHandlers = std::dynamic_pointer_cast<const ViewEventHandlers>(eventHandlers);
auto &&eventEmitter = newShadowNode->getEventEmitter();
auto &&viewEventEmitter = std::dynamic_pointer_cast<const ViewEventEmitter>(eventEmitter);
// Checking if particular shadow node supports `onLayout` event (part of `ViewEventHandlers`).
if (viewEventHandlers) {
// Checking if particular shadow node supports `onLayout` event (part of `ViewEventEmitter`).
if (viewEventEmitter) {
// Now we know that both (old and new) shadow nodes must be `LayoutableShadowNode` subclasses.
assert(std::dynamic_pointer_cast<const LayoutableShadowNode>(newShadowNode));
// 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/debug/DebugStringConvertibleItem.h>
#include <fabric/view/AccessibleShadowNode.h>
#include <fabric/view/ViewEventHandlers.h>
#include <fabric/view/ViewEventEmitter.h>
#include <fabric/view/ViewProps.h>
#include <fabric/view/YogaLayoutableShadowNode.h>
@ -24,9 +24,9 @@ namespace react {
* as <View> and similar basic behaviour).
* For example: <Paragraph>, <Image>, but not <Text>, <RawText>.
*/
template <typename ViewPropsT = ViewProps, typename ViewEventHandlersT = ViewEventHandlers>
template <typename ViewPropsT = ViewProps, typename ViewEventEmitterT = ViewEventEmitter>
class ConcreteViewShadowNode:
public ConcreteShadowNode<ViewPropsT, ViewEventHandlersT>,
public ConcreteShadowNode<ViewPropsT, ViewEventEmitterT>,
public AccessibleShadowNode,
public YogaLayoutableShadowNode {
@ -38,23 +38,23 @@ public:
using ConcreteViewProps = ViewPropsT;
using SharedConcreteViewProps = std::shared_ptr<const ViewPropsT>;
using ConcreteViewEventHandlers = ViewEventHandlersT;
using SharedConcreteViewEventHandlers = std::shared_ptr<const ViewEventHandlersT>;
using ConcreteViewEventEmitter = ViewEventEmitterT;
using SharedConcreteViewEventEmitter = std::shared_ptr<const ViewEventEmitterT>;
using SharedConcreteViewShadowNode = std::shared_ptr<const ConcreteViewShadowNode>;
ConcreteViewShadowNode(
const Tag &tag,
const Tag &rootTag,
const SharedConcreteViewProps &props,
const SharedConcreteViewEventHandlers &eventHandlers,
const SharedConcreteViewEventEmitter &eventEmitter,
const SharedShadowNodeSharedList &children,
const ShadowNodeCloneFunction &cloneFunction
):
ConcreteShadowNode<ViewPropsT, ViewEventHandlersT>(
ConcreteShadowNode<ViewPropsT, ViewEventEmitterT>(
tag,
rootTag,
props,
eventHandlers,
eventEmitter,
children,
cloneFunction
),
@ -69,13 +69,13 @@ public:
ConcreteViewShadowNode(
const SharedConcreteViewShadowNode &shadowNode,
const SharedConcreteViewProps &props,
const SharedConcreteViewEventHandlers &eventHandlers,
const SharedConcreteViewEventEmitter &eventEmitter,
const SharedShadowNodeSharedList &children
):
ConcreteShadowNode<ViewPropsT, ViewEventHandlersT>(
ConcreteShadowNode<ViewPropsT, ViewEventEmitterT>(
shadowNode,
props,
eventHandlers,
eventEmitter,
children
),
AccessibleShadowNode(

View File

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

View File

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

View File

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