From 74c24147e28ef0a684817dee01a71e2c05dd4658 Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Mon, 10 Sep 2018 11:19:22 -0700 Subject: [PATCH] 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 --- .../ComponentViews/View/RCTViewComponentView.h | 3 ++- .../ComponentViews/View/RCTViewComponentView.mm | 2 +- React/Fabric/RCTSurfaceTouchHandler.mm | 14 +++++--------- React/Fabric/RCTTouchableComponentViewProtocol.h | 13 +++++++++++++ 4 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 React/Fabric/RCTTouchableComponentViewProtocol.h diff --git a/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.h b/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.h index 9359240be..d966bb7a4 100644 --- a/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.h +++ b/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.h @@ -13,13 +13,14 @@ #import #import #import +#import NS_ASSUME_NONNULL_BEGIN /** * UIView class for component. */ -@interface RCTViewComponentView : UIView { +@interface RCTViewComponentView : UIView { @protected facebook::react::LayoutMetrics _layoutMetrics; facebook::react::SharedProps _props; diff --git a/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm b/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm index 24482c762..870f41d9a 100644 --- a/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm +++ b/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm @@ -449,7 +449,7 @@ static RCTBorderStyle RCTBorderStyleFromBorderStyle(BorderStyle borderStyle) { return YES; } -- (SharedEventEmitter)touchEventEmitter +- (SharedTouchEventEmitter)touchEventEmitterAtPoint:(CGPoint)point { return _eventEmitter; } diff --git a/React/Fabric/RCTSurfaceTouchHandler.mm b/React/Fabric/RCTSurfaceTouchHandler.mm index 569521123..c7196eb69 100644 --- a/React/Fabric/RCTSurfaceTouchHandler.mm +++ b/React/Fabric/RCTSurfaceTouchHandler.mm @@ -8,11 +8,11 @@ #import "RCTSurfaceTouchHandler.h" #import -#import #import #import #import "RCTConversions.h" +#import "RCTTouchableComponentViewProtocol.h" using namespace facebook::react; @@ -46,10 +46,6 @@ private: int lastIndex; }; -@protocol RCTTouchableComponentViewProtocol - - (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)componentView touchEventEmitter]; + if ([componentView respondsToSelector:@selector(touchEventEmitterAtPoint:)]) { + activeTouch.eventEmitter = [(id)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 changedActiveTouches = {}; - std::unordered_set uniqueEventEmitter = {}; + std::unordered_set uniqueEventEmitter = {}; BOOL isEndishEventType = eventType == RCTTouchEventTypeTouchEnd || eventType == RCTTouchEventTypeTouchCancel; for (UITouch *touch in touches) { diff --git a/React/Fabric/RCTTouchableComponentViewProtocol.h b/React/Fabric/RCTTouchableComponentViewProtocol.h new file mode 100644 index 000000000..d2fee6e44 --- /dev/null +++ b/React/Fabric/RCTTouchableComponentViewProtocol.h @@ -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 +#import + +@protocol RCTTouchableComponentViewProtocol +- (facebook::react::SharedTouchEventEmitter)touchEventEmitterAtPoint:(CGPoint)point; +@end