Skip to content

Commit 47f18bd

Browse files
sherginfacebook-github-bot
authored andcommitted
Nobody outside RCTTouchHandler should treat it as UIGestureRecognizer subclass
Reviewed By: mmmulani Differential Revision: D4387821 fbshipit-source-id: 8060772a5de669eeaca159ceac13b995d7518a1b
1 parent 2e4be1c commit 47f18bd

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

React/Base/RCTRootView.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ - (instancetype)initWithFrame:(CGRect)frame
380380
_bridge = bridge;
381381
self.reactTag = reactTag;
382382
_touchHandler = [[RCTTouchHandler alloc] initWithBridge:_bridge];
383-
[self addGestureRecognizer:_touchHandler];
383+
[_touchHandler attachToView:self];
384384
[_bridge.uiManager registerRootView:self withSizeFlexibility:sizeFlexibility];
385385
self.layer.backgroundColor = NULL;
386386
}

React/Base/RCTTouchHandler.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
@interface RCTTouchHandler : UIGestureRecognizer
1717

1818
- (instancetype)initWithBridge:(RCTBridge *)bridge NS_DESIGNATED_INITIALIZER;
19+
20+
- (void)attachToView:(UIView *)view;
21+
- (void)detachFromView:(UIView *)view;
22+
1923
- (void)cancel;
2024

2125
@end

React/Base/RCTTouchHandler.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,21 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
6464

6565
RCT_NOT_IMPLEMENTED(- (instancetype)initWithTarget:(id)target action:(SEL)action)
6666

67+
- (void)attachToView:(UIView *)view
68+
{
69+
RCTAssert(self.view == nil, @"RCTTouchHandler already has attached view.");
70+
71+
[view addGestureRecognizer:self];
72+
}
73+
74+
- (void)detachFromView:(UIView *)view
75+
{
76+
RCTAssertParam(view);
77+
RCTAssert(self.view == view, @"RCTTouchHandler attached to another view.");
78+
79+
[view removeGestureRecognizer:self];
80+
}
81+
6782
typedef NS_ENUM(NSInteger, RCTTouchEventType) {
6883
RCTTouchEventTypeStart,
6984
RCTTouchEventTypeMove,

React/Views/RCTModalHostView.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99

1010
#import "RCTModalHostView.h"
1111

12+
#import <UIKit/UIKit.h>
13+
1214
#import "RCTAssert.h"
1315
#import "RCTBridge.h"
1416
#import "RCTModalHostViewController.h"
1517
#import "RCTTouchHandler.h"
1618
#import "RCTUIManager.h"
1719
#import "UIView+React.h"
1820

19-
#import <UIKit/UIKit.h>
20-
2121
@implementation RCTModalHostView
2222
{
2323
__weak RCTBridge *_bridge;
@@ -87,7 +87,7 @@ - (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex
8787
{
8888
RCTAssert(_reactSubview == nil, @"Modal view can only have one subview");
8989
[super insertReactSubview:subview atIndex:atIndex];
90-
[subview addGestureRecognizer:_touchHandler];
90+
[_touchHandler attachToView:subview];
9191
subview.autoresizingMask = UIViewAutoresizingFlexibleHeight |
9292
UIViewAutoresizingFlexibleWidth;
9393

@@ -99,7 +99,7 @@ - (void)removeReactSubview:(UIView *)subview
9999
{
100100
RCTAssert(subview == _reactSubview, @"Cannot remove view other than modal view");
101101
[super removeReactSubview:subview];
102-
[subview removeGestureRecognizer:_touchHandler];
102+
[_touchHandler detachFromView:subview];
103103
_reactSubview = nil;
104104
}
105105

React/Views/RCTModalHostViewManager.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#import "RCTBridge.h"
1313
#import "RCTModalHostView.h"
1414
#import "RCTModalHostViewController.h"
15-
#import "RCTTouchHandler.h"
1615
#import "RCTShadowView.h"
1716
#import "RCTUtils.h"
1817

0 commit comments

Comments
 (0)