Browse Source

[V2] Fix iOS pop gesture when topBar is hidden (#4568)

* Fix iOS pop gesture when nav bar is hidden

* Add missing property

* Factor out InteractivePopGestureDelegate into its own file

* Add missing import

* Make sure fix supports hidden and visible nav bars

* Minor code style fix
Arman Dezfuli-Arjomandi 5 years ago
parent
commit
81d8b69d61

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

@@ -0,0 +1,20 @@
1
+//
2
+//  InteractivePopGestureDelegate.h
3
+//  ReactNativeNavigation
4
+//
5
+//  Created by Arman Dezfuli-Arjomandi on 1/10/19.
6
+//  Copyright © 2019 Wix. All rights reserved.
7
+//
8
+//
9
+
10
+// This file is adapted from the following StackOverflow answer:
11
+// https://stackoverflow.com/questions/24710258/no-swipe-back-when-hiding-navigation-bar-in-uinavigationcontroller/41895151#41895151
12
+
13
+#import <UIKit/UIKit.h>
14
+
15
+@interface InteractivePopGestureDelegate : NSObject <UIGestureRecognizerDelegate>
16
+
17
+@property (nonatomic, weak) UINavigationController *navigationController;
18
+@property (nonatomic, weak) id<UIGestureRecognizerDelegate> originalDelegate;
19
+
20
+@end

+ 35
- 0
lib/ios/InteractivePopGestureDelegate.m View File

@@ -0,0 +1,35 @@
1
+//
2
+//  InteractivePopGestureDelegate.m
3
+//  ReactNativeNavigation
4
+//
5
+//  Created by Arman Dezfuli-Arjomandi on 1/10/19.
6
+//  Copyright © 2019 Wix. All rights reserved.
7
+//
8
+
9
+#import "InteractivePopGestureDelegate.h"
10
+
11
+@implementation InteractivePopGestureDelegate
12
+
13
+- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
14
+	if (self.navigationController.navigationBarHidden && self.navigationController.viewControllers.count > 1) {
15
+		return YES;
16
+	} else if (!self.navigationController.navigationBarHidden && self.originalDelegate == nil) {
17
+		return YES;
18
+	} else {
19
+		return [self.originalDelegate gestureRecognizer:gestureRecognizer shouldReceiveTouch:touch];
20
+	}
21
+}
22
+
23
+- (BOOL)respondsToSelector:(SEL)aSelector {
24
+	if (aSelector == @selector(gestureRecognizer:shouldReceiveTouch:)) {
25
+		return YES;
26
+	} else {
27
+		return [self.originalDelegate respondsToSelector:aSelector];
28
+	}
29
+}
30
+
31
+- (id)forwardingTargetForSelector:(SEL)aSelector {
32
+	return self.originalDelegate;
33
+}
34
+
35
+@end

+ 1
- 0
lib/ios/RNNNavigationController.m View File

@@ -2,6 +2,7 @@
2 2
 #import "RNNNavigationController.h"
3 3
 #import "RNNModalAnimation.h"
4 4
 #import "RNNRootViewController.h"
5
+#import "InteractivePopGestureDelegate.h"
5 6
 
6 7
 const NSInteger TOP_BAR_TRANSPARENT_TAG = 78264803;
7 8
 

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

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

+ 5
- 0
lib/ios/RNNNavigationControllerPresenter.m View File

@@ -28,6 +28,11 @@
28 28
 	
29 29
 	RNNNavigationController* navigationController = self.bindedViewController;
30 30
 	
31
+	self.interactivePopGestureDelegate = [InteractivePopGestureDelegate new];
32
+	self.interactivePopGestureDelegate.navigationController = navigationController;
33
+	self.interactivePopGestureDelegate.originalDelegate = navigationController.interactivePopGestureRecognizer.delegate;
34
+	navigationController.interactivePopGestureRecognizer.delegate = self.interactivePopGestureDelegate;
35
+	
31 36
 	[navigationController rnn_setInteractivePopGestureEnabled:[options.popGesture getWithDefaultValue:YES]];
32 37
 	[navigationController rnn_setRootBackgroundImage:[options.rootBackgroundImage getWithDefaultValue:nil]];
33 38
 	[navigationController rnn_setNavigationBarTestID:[options.topBar.testID getWithDefaultValue:nil]];

+ 8
- 0
lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj View File

@@ -280,6 +280,8 @@
280 280
 		7BEF0D1D1E43771B003E96B0 /* RNNLayoutNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BEF0D1B1E43771B003E96B0 /* RNNLayoutNode.m */; };
281 281
 		A7626BFD1FC2FB2C00492FB8 /* RNNTopBarOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = A7626BFC1FC2FB2C00492FB8 /* RNNTopBarOptions.m */; };
282 282
 		A7626C011FC5796200492FB8 /* RNNBottomTabsOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = A7626C001FC5796200492FB8 /* RNNBottomTabsOptions.m */; };
283
+		C2A57A1C21E815F80066711C /* InteractivePopGestureDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = C2A57A1A21E815F80066711C /* InteractivePopGestureDelegate.h */; };
284
+		C2A57A1D21E815F80066711C /* InteractivePopGestureDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = C2A57A1B21E815F80066711C /* InteractivePopGestureDelegate.m */; };
283 285
 		E33AC20020B5BA0B0090DB8A /* RNNSplitViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E33AC1FF20B5BA0B0090DB8A /* RNNSplitViewController.m */; };
284 286
 		E33AC20520B5C3890090DB8A /* RNNStatusBarOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = E33AC20320B5C3890090DB8A /* RNNStatusBarOptions.m */; };
285 287
 		E33AC20820B5C4F90090DB8A /* RNNSplitViewOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = E33AC20720B5C4F90090DB8A /* RNNSplitViewOptions.m */; };
@@ -617,6 +619,8 @@
617 619
 		A7626BFE1FC2FB6700492FB8 /* RNNTopBarOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNTopBarOptions.h; sourceTree = "<group>"; };
618 620
 		A7626BFF1FC578AB00492FB8 /* RNNBottomTabsOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNBottomTabsOptions.h; sourceTree = "<group>"; };
619 621
 		A7626C001FC5796200492FB8 /* RNNBottomTabsOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNBottomTabsOptions.m; sourceTree = "<group>"; };
622
+		C2A57A1A21E815F80066711C /* InteractivePopGestureDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = InteractivePopGestureDelegate.h; sourceTree = "<group>"; };
623
+		C2A57A1B21E815F80066711C /* InteractivePopGestureDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = InteractivePopGestureDelegate.m; sourceTree = "<group>"; };
620 624
 		D8AFADBD1BEE6F3F00A4592D /* libReactNativeNavigation.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libReactNativeNavigation.a; sourceTree = BUILT_PRODUCTS_DIR; };
621 625
 		E33AC1FF20B5BA0B0090DB8A /* RNNSplitViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNSplitViewController.m; sourceTree = "<group>"; };
622 626
 		E33AC20120B5BA550090DB8A /* RNNSplitViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNSplitViewController.h; sourceTree = "<group>"; };
@@ -719,6 +723,8 @@
719 723
 				5038A3BC216E1490009280BC /* RNNTabBarItemCreator.m */,
720 724
 				5053CE7D2175FB1900D0386B /* RNNDefaultOptionsHelper.h */,
721 725
 				5053CE7E2175FB1900D0386B /* RNNDefaultOptionsHelper.m */,
726
+				C2A57A1A21E815F80066711C /* InteractivePopGestureDelegate.h */,
727
+				C2A57A1B21E815F80066711C /* InteractivePopGestureDelegate.m */,
722 728
 			);
723 729
 			name = Helpers;
724 730
 			sourceTree = "<group>";
@@ -1206,6 +1212,7 @@
1206 1212
 				E8AEDB4A1F5C0BAF000F5A6A /* RNNInteractivePopAnimator.h in Headers */,
1207 1213
 				263905B71E4C6F440023D7D3 /* UIViewController+MMDrawerController.h in Headers */,
1208 1214
 				263905BB1E4C6F440023D7D3 /* RCCDrawerHelper.h in Headers */,
1215
+				C2A57A1C21E815F80066711C /* InteractivePopGestureDelegate.h in Headers */,
1209 1216
 				263905CC1E4C6F440023D7D3 /* SidebarWunderlistAnimation.h in Headers */,
1210 1217
 				507F43F41FF4FCFE00D9425B /* HMSegmentedControl.h in Headers */,
1211 1218
 				501CD31F214A5B6900A6E225 /* RNNLayoutInfo.h in Headers */,
@@ -1515,6 +1522,7 @@
1515 1522
 				50F5DFC21F407A8C001A00BC /* RNNTabBarController.m in Sources */,
1516 1523
 				50887CA920F26BFE00D06111 /* RNNOverlayWindow.m in Sources */,
1517 1524
 				5038A3CF216E35E0009280BC /* Dictionary.m in Sources */,
1525
+				C2A57A1D21E815F80066711C /* InteractivePopGestureDelegate.m in Sources */,
1518 1526
 				263905BC1E4C6F440023D7D3 /* RCCDrawerHelper.m in Sources */,
1519 1527
 				4534E72620CB6724009F8185 /* RNNLargeTitleOptions.m in Sources */,
1520 1528
 				507E7D58201DDD3000444E6C /* RNNAnimationOptions.m in Sources */,