Browse Source

Fix popGesture freezes the app (#5863)

* Fix popGesture freeze the app

* Move popGestureDelegate initialization to init
Yogev Ben David 5 years ago
parent
commit
37473f88e9
No account linked to committer's email address

+ 2
- 0
lib/ios/InteractivePopGestureDelegate.h View File

6
 @property (nonatomic, weak) UINavigationController *navigationController;
6
 @property (nonatomic, weak) UINavigationController *navigationController;
7
 @property (nonatomic, weak) id<UIGestureRecognizerDelegate> originalDelegate;
7
 @property (nonatomic, weak) id<UIGestureRecognizerDelegate> originalDelegate;
8
 
8
 
9
+@property (nonatomic) BOOL enabled;
10
+
9
 @end
11
 @end

+ 6
- 1
lib/ios/InteractivePopGestureDelegate.m View File

3
 
3
 
4
 @implementation InteractivePopGestureDelegate
4
 @implementation InteractivePopGestureDelegate
5
 
5
 
6
+- (instancetype)init {
7
+    self = [super init];
8
+    _enabled = YES;
9
+    return self;
10
+}
6
 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
11
 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
7
-	if (self.navigationController.viewControllers.count < 2) {
12
+	if (self.navigationController.viewControllers.count < 2 || !_enabled) {
8
 		return NO;
13
 		return NO;
9
 	} else if (self.navigationController.navigationBarHidden) {
14
 	} else if (self.navigationController.navigationBarHidden) {
10
 		return YES;
15
 		return YES;

+ 0
- 3
lib/ios/RNNStackPresenter.h View File

1
 #import "RNNBasePresenter.h"
1
 #import "RNNBasePresenter.h"
2
 #import "RNNComponentViewCreator.h"
2
 #import "RNNComponentViewCreator.h"
3
 #import "RNNReactComponentRegistry.h"
3
 #import "RNNReactComponentRegistry.h"
4
-#import "InteractivePopGestureDelegate.h"
5
 
4
 
6
 @interface RNNStackPresenter : RNNBasePresenter
5
 @interface RNNStackPresenter : RNNBasePresenter
7
 
6
 
8
-@property (nonatomic, strong) InteractivePopGestureDelegate *interactivePopGestureDelegate;
9
-
10
 - (instancetype)initWithComponentRegistry:(RNNReactComponentRegistry *)componentRegistry defaultOptions:(RNNNavigationOptions *)defaultOptions;
7
 - (instancetype)initWithComponentRegistry:(RNNReactComponentRegistry *)componentRegistry defaultOptions:(RNNNavigationOptions *)defaultOptions;
11
 
8
 
12
 - (void)applyOptionsBeforePopping:(RNNNavigationOptions *)options;
9
 - (void)applyOptionsBeforePopping:(RNNNavigationOptions *)options;

+ 9
- 7
lib/ios/RNNStackPresenter.m View File

4
 #import "RNNCustomTitleView.h"
4
 #import "RNNCustomTitleView.h"
5
 #import "TopBarPresenterCreator.h"
5
 #import "TopBarPresenterCreator.h"
6
 #import "RNNReactBackgroundView.h"
6
 #import "RNNReactBackgroundView.h"
7
+#import "InteractivePopGestureDelegate.h"
7
 
8
 
8
 @interface RNNStackPresenter() {
9
 @interface RNNStackPresenter() {
9
 	RNNReactComponentRegistry* _componentRegistry;
10
 	RNNReactComponentRegistry* _componentRegistry;
10
 	UIView* _customTopBarBackground;
11
 	UIView* _customTopBarBackground;
11
 	RNNReactView* _topBarBackgroundReactView;
12
 	RNNReactView* _topBarBackgroundReactView;
12
     TopBarPresenter* _topBarPresenter;
13
     TopBarPresenter* _topBarPresenter;
14
+    InteractivePopGestureDelegate *_interactivePopGestureDelegate;
13
 }
15
 }
14
 
16
 
15
 @property (nonatomic, weak) RNNStackController* stackController;
17
 @property (nonatomic, weak) RNNStackController* stackController;
20
 - (instancetype)initWithComponentRegistry:(RNNReactComponentRegistry *)componentRegistry defaultOptions:(RNNNavigationOptions *)defaultOptions {
22
 - (instancetype)initWithComponentRegistry:(RNNReactComponentRegistry *)componentRegistry defaultOptions:(RNNNavigationOptions *)defaultOptions {
21
 	self = [super initWithDefaultOptions:defaultOptions];
23
 	self = [super initWithDefaultOptions:defaultOptions];
22
 	_componentRegistry = componentRegistry;
24
 	_componentRegistry = componentRegistry;
25
+    _interactivePopGestureDelegate = [InteractivePopGestureDelegate new];
23
 	return self;
26
 	return self;
24
 }
27
 }
25
 
28
 
26
-- (void)bindViewController:(UIViewController *)boundViewController {
29
+- (void)bindViewController:(UINavigationController *)boundViewController {
27
     [super bindViewController:boundViewController];
30
     [super bindViewController:boundViewController];
28
     _topBarPresenter = [TopBarPresenterCreator createWithBoundedNavigationController:self.stackController];
31
     _topBarPresenter = [TopBarPresenterCreator createWithBoundedNavigationController:self.stackController];
32
+    _interactivePopGestureDelegate.navigationController = boundViewController;
33
+    _interactivePopGestureDelegate.originalDelegate = boundViewController.interactivePopGestureRecognizer.delegate;
29
 }
34
 }
30
 
35
 
31
 - (void)componentDidAppear {
36
 - (void)componentDidAppear {
45
 	RNNStackController* stack = self.stackController;
50
 	RNNStackController* stack = self.stackController;
46
 	RNNNavigationOptions * withDefault = [options withDefault:[self defaultOptions]];
51
 	RNNNavigationOptions * withDefault = [options withDefault:[self defaultOptions]];
47
 	
52
 	
48
-	self.interactivePopGestureDelegate = [InteractivePopGestureDelegate new];
49
-	self.interactivePopGestureDelegate.navigationController = stack;
50
-	self.interactivePopGestureDelegate.originalDelegate = stack.interactivePopGestureRecognizer.delegate;
51
-	stack.interactivePopGestureRecognizer.delegate = self.interactivePopGestureDelegate;
53
+    [_interactivePopGestureDelegate setEnabled:[withDefault.popGesture getWithDefaultValue:YES]];
54
+	stack.interactivePopGestureRecognizer.delegate = _interactivePopGestureDelegate;
52
 
55
 
53
     [stack setBarStyle:[RCTConvert UIBarStyle:[withDefault.topBar.barStyle getWithDefaultValue:@"default"]]];
56
     [stack setBarStyle:[RCTConvert UIBarStyle:[withDefault.topBar.barStyle getWithDefaultValue:@"default"]]];
54
-	[stack setInteractivePopGestureEnabled:[withDefault.popGesture getWithDefaultValue:YES]];
55
 	[stack setRootBackgroundImage:[withDefault.rootBackgroundImage getWithDefaultValue:nil]];
57
 	[stack setRootBackgroundImage:[withDefault.rootBackgroundImage getWithDefaultValue:nil]];
56
 	[stack setNavigationBarTestId:[withDefault.topBar.testID getWithDefaultValue:nil]];
58
 	[stack setNavigationBarTestId:[withDefault.topBar.testID getWithDefaultValue:nil]];
57
 	[stack setNavigationBarVisible:[withDefault.topBar.visible getWithDefaultValue:YES] animated:[withDefault.topBar.animate getWithDefaultValue:YES]];
59
 	[stack setNavigationBarVisible:[withDefault.topBar.visible getWithDefaultValue:YES] animated:[withDefault.topBar.animate getWithDefaultValue:YES]];
84
 	RNNStackController* stack = self.stackController;
86
 	RNNStackController* stack = self.stackController;
85
     
87
     
86
 	if (options.popGesture.hasValue) {
88
 	if (options.popGesture.hasValue) {
87
-		[stack setInteractivePopGestureEnabled:options.popGesture.get];
89
+		[_interactivePopGestureDelegate setEnabled:options.popGesture.get];
88
 	}
90
 	}
89
 	
91
 	
90
 	if (options.rootBackgroundImage.hasValue) {
92
 	if (options.rootBackgroundImage.hasValue) {

+ 0
- 2
lib/ios/UINavigationController+RNNOptions.h View File

2
 
2
 
3
 @interface UINavigationController (RNNOptions)
3
 @interface UINavigationController (RNNOptions)
4
 
4
 
5
-- (void)setInteractivePopGestureEnabled:(BOOL)enabled;
6
-
7
 - (void)setRootBackgroundImage:(UIImage *)backgroundImage;
5
 - (void)setRootBackgroundImage:(UIImage *)backgroundImage;
8
 
6
 
9
 - (void)setNavigationBarTestId:(NSString *)testID;
7
 - (void)setNavigationBarTestId:(NSString *)testID;

+ 0
- 4
lib/ios/UINavigationController+RNNOptions.m View File

5
 
5
 
6
 @implementation UINavigationController (RNNOptions)
6
 @implementation UINavigationController (RNNOptions)
7
 
7
 
8
-- (void)setInteractivePopGestureEnabled:(BOOL)enabled {
9
-	self.interactivePopGestureRecognizer.enabled = enabled;
10
-}
11
-
12
 - (void)setRootBackgroundImage:(UIImage *)backgroundImage {
8
 - (void)setRootBackgroundImage:(UIImage *)backgroundImage {
13
 	UIImageView* backgroundImageView = (self.view.subviews.count > 0) ? self.view.subviews[0] : nil;
9
 	UIImageView* backgroundImageView = (self.view.subviews.count > 0) ? self.view.subviews[0] : nil;
14
 	if (![backgroundImageView isKindOfClass:[UIImageView class]]) {
10
 	if (![backgroundImageView isKindOfClass:[UIImageView class]]) {