Bladeren bron

Fix popGesture freezes the app (#5863)

* Fix popGesture freeze the app

* Move popGestureDelegate initialization to init
Yogev Ben David 5 jaren geleden
bovenliggende
commit
37473f88e9
No account linked to committer's email address

+ 2
- 0
lib/ios/InteractivePopGestureDelegate.h Bestand weergeven

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

+ 6
- 1
lib/ios/InteractivePopGestureDelegate.m Bestand weergeven

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

+ 0
- 3
lib/ios/RNNStackPresenter.h Bestand weergeven

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

+ 9
- 7
lib/ios/RNNStackPresenter.m Bestand weergeven

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

+ 0
- 2
lib/ios/UINavigationController+RNNOptions.h Bestand weergeven

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

+ 0
- 4
lib/ios/UINavigationController+RNNOptions.m Bestand weergeven

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