Modify RCTTouchableComponentViewProtocol to get touch event emitter at point

Summary:
This diff includes two changes:
1. Even though `RCTViewComponentView` conforms to `RCTTouchableComponentViewProtocol`, it never implemented this protocol. This diff makes the correction.
2. Make the necessary changes to `RCTSurfaceTouchHandler` required by the changes in `RCTTouchableComponentViewProtocol`. This means modifying the `ActiveTouch` struct to hold `SharedTouchEventEmitter`s. It also means passing in the touch point to the `componentView`'s `touchEventEmitterAtPoint` method.

Reviewed By: shergin

Differential Revision: D9696909

fbshipit-source-id: 3d4a833f7dbae6d0238a0807eb2220250ccbae3d
This commit is contained in:
Ramanpreet Nara 2018-09-10 11:19:22 -07:00 committed by Facebook Github Bot
parent 7c0b707754
commit 74c24147e2
4 changed files with 21 additions and 11 deletions

View File

@ -13,13 +13,14 @@
#import <fabric/core/Props.h>
#import <fabric/components/view/ViewEventEmitter.h>
#import <fabric/events/EventEmitter.h>
#import <React/RCTTouchableComponentViewProtocol.h>
NS_ASSUME_NONNULL_BEGIN
/**
* UIView class for <View> component.
*/
@interface RCTViewComponentView : UIView <RCTComponentViewProtocol> {
@interface RCTViewComponentView : UIView <RCTComponentViewProtocol, RCTTouchableComponentViewProtocol> {
@protected
facebook::react::LayoutMetrics _layoutMetrics;
facebook::react::SharedProps _props;

View File

@ -449,7 +449,7 @@ static RCTBorderStyle RCTBorderStyleFromBorderStyle(BorderStyle borderStyle) {
return YES;
}
- (SharedEventEmitter)touchEventEmitter
- (SharedTouchEventEmitter)touchEventEmitterAtPoint:(CGPoint)point
{
return _eventEmitter;
}

View File

@ -8,11 +8,11 @@
#import "RCTSurfaceTouchHandler.h"
#import <UIKit/UIGestureRecognizerSubclass.h>
#import <fabric/components/view/ViewEventEmitter.h>
#import <React/RCTUtils.h>
#import <React/RCTViewComponentView.h>
#import "RCTConversions.h"
#import "RCTTouchableComponentViewProtocol.h"
using namespace facebook::react;
@ -46,10 +46,6 @@ private:
int lastIndex;
};
@protocol RCTTouchableComponentViewProtocol <NSObject>
- (SharedViewEventEmitter)touchEventEmitter;
@end
typedef NS_ENUM(NSInteger, RCTTouchEventType) {
RCTTouchEventTypeTouchStart,
RCTTouchEventTypeTouchMove,
@ -59,7 +55,7 @@ typedef NS_ENUM(NSInteger, RCTTouchEventType) {
struct ActiveTouch {
Touch touch;
SharedViewEventEmitter eventEmitter;
SharedTouchEventEmitter eventEmitter;
struct Hasher {
size_t operator()(const ActiveTouch &activeTouch) const {
@ -95,8 +91,8 @@ static ActiveTouch CreateTouchWithUITouch(UITouch *uiTouch, UIView *rootComponen
ActiveTouch activeTouch = {};
if ([componentView respondsToSelector:@selector(touchEventEmitter)]) {
activeTouch.eventEmitter = [(id<RCTTouchableComponentViewProtocol>)componentView touchEventEmitter];
if ([componentView respondsToSelector:@selector(touchEventEmitterAtPoint:)]) {
activeTouch.eventEmitter = [(id<RCTTouchableComponentViewProtocol>)componentView touchEventEmitterAtPoint:[uiTouch locationInView:componentView]];
activeTouch.touch.target = (Tag)componentView.tag;
}
@ -217,7 +213,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithTarget:(id)target action:(SEL)action
{
TouchEvent event = {};
std::unordered_set<ActiveTouch, ActiveTouch::Hasher, ActiveTouch::Comparator> changedActiveTouches = {};
std::unordered_set<SharedViewEventEmitter> uniqueEventEmitter = {};
std::unordered_set<SharedTouchEventEmitter> uniqueEventEmitter = {};
BOOL isEndishEventType = eventType == RCTTouchEventTypeTouchEnd || eventType == RCTTouchEventTypeTouchCancel;
for (UITouch *touch in touches) {

View File

@ -0,0 +1,13 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <UIKit/UIKit.h>
#import <fabric/components/view/TouchEventEmitter.h>
@protocol RCTTouchableComponentViewProtocol <NSObject>
- (facebook::react::SharedTouchEventEmitter)touchEventEmitterAtPoint:(CGPoint)point;
@end