Skip to content

Commit

Permalink
Modify RCTTouchableComponentViewProtocol to get touch event emitter…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
RSNara authored and facebook-github-bot committed Sep 10, 2018
1 parent 7c0b707 commit 74c2414
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ - (BOOL)didActivateAccessibilityCustomAction:(UIAccessibilityCustomAction *)acti
return YES;
}

- (SharedEventEmitter)touchEventEmitter
- (SharedTouchEventEmitter)touchEventEmitterAtPoint:(CGPoint)point
{
return _eventEmitter;
}
Expand Down
14 changes: 5 additions & 9 deletions React/Fabric/RCTSurfaceTouchHandler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -46,10 +46,6 @@ void reset() {
int lastIndex;
};

@protocol RCTTouchableComponentViewProtocol <NSObject>
- (SharedViewEventEmitter)touchEventEmitter;
@end

typedef NS_ENUM(NSInteger, RCTTouchEventType) {
RCTTouchEventTypeTouchStart,
RCTTouchEventTypeTouchMove,
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -217,7 +213,7 @@ - (void)_dispatchTouches:(NSSet<UITouch *> *)touches eventType:(RCTTouchEventTyp
{
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) {
Expand Down
13 changes: 13 additions & 0 deletions React/Fabric/RCTTouchableComponentViewProtocol.h
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 74c2414

Please sign in to comment.