Skip to content

Commit

Permalink
[V2] Fix iOS pop gesture when topBar is hidden (#4568)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rawrmaan authored and yogevbd committed Mar 11, 2019
1 parent fdee254 commit 81d8b69
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/ios/InteractivePopGestureDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// InteractivePopGestureDelegate.h
// ReactNativeNavigation
//
// Created by Arman Dezfuli-Arjomandi on 1/10/19.
// Copyright © 2019 Wix. All rights reserved.
//
//

// This file is adapted from the following StackOverflow answer:
// https://stackoverflow.com/questions/24710258/no-swipe-back-when-hiding-navigation-bar-in-uinavigationcontroller/41895151#41895151

#import <UIKit/UIKit.h>

@interface InteractivePopGestureDelegate : NSObject <UIGestureRecognizerDelegate>

@property (nonatomic, weak) UINavigationController *navigationController;
@property (nonatomic, weak) id<UIGestureRecognizerDelegate> originalDelegate;

@end
35 changes: 35 additions & 0 deletions lib/ios/InteractivePopGestureDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// InteractivePopGestureDelegate.m
// ReactNativeNavigation
//
// Created by Arman Dezfuli-Arjomandi on 1/10/19.
// Copyright © 2019 Wix. All rights reserved.
//

#import "InteractivePopGestureDelegate.h"

@implementation InteractivePopGestureDelegate

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if (self.navigationController.navigationBarHidden && self.navigationController.viewControllers.count > 1) {
return YES;
} else if (!self.navigationController.navigationBarHidden && self.originalDelegate == nil) {
return YES;
} else {
return [self.originalDelegate gestureRecognizer:gestureRecognizer shouldReceiveTouch:touch];
}
}

- (BOOL)respondsToSelector:(SEL)aSelector {
if (aSelector == @selector(gestureRecognizer:shouldReceiveTouch:)) {
return YES;
} else {
return [self.originalDelegate respondsToSelector:aSelector];
}
}

- (id)forwardingTargetForSelector:(SEL)aSelector {
return self.originalDelegate;
}

@end
1 change: 1 addition & 0 deletions lib/ios/RNNNavigationController.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#import "RNNNavigationController.h"
#import "RNNModalAnimation.h"
#import "RNNRootViewController.h"
#import "InteractivePopGestureDelegate.h"

const NSInteger TOP_BAR_TRANSPARENT_TAG = 78264803;

Expand Down
3 changes: 3 additions & 0 deletions lib/ios/RNNNavigationControllerPresenter.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#import "RNNBasePresenter.h"
#import "RNNRootViewCreator.h"
#import "RNNReactComponentRegistry.h"
#import "InteractivePopGestureDelegate.h"

@interface RNNNavigationControllerPresenter : RNNBasePresenter

@property (nonatomic, strong) InteractivePopGestureDelegate *interactivePopGestureDelegate;

- (instancetype)initWithcomponentRegistry:(RNNReactComponentRegistry *)componentRegistry;

- (void)applyOptionsBeforePopping:(RNNNavigationOptions *)options;
Expand Down
5 changes: 5 additions & 0 deletions lib/ios/RNNNavigationControllerPresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ - (void)applyOptions:(RNNNavigationOptions *)options {

RNNNavigationController* navigationController = self.bindedViewController;

self.interactivePopGestureDelegate = [InteractivePopGestureDelegate new];
self.interactivePopGestureDelegate.navigationController = navigationController;
self.interactivePopGestureDelegate.originalDelegate = navigationController.interactivePopGestureRecognizer.delegate;
navigationController.interactivePopGestureRecognizer.delegate = self.interactivePopGestureDelegate;

[navigationController rnn_setInteractivePopGestureEnabled:[options.popGesture getWithDefaultValue:YES]];
[navigationController rnn_setRootBackgroundImage:[options.rootBackgroundImage getWithDefaultValue:nil]];
[navigationController rnn_setNavigationBarTestID:[options.topBar.testID getWithDefaultValue:nil]];
Expand Down
8 changes: 8 additions & 0 deletions lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@
7BEF0D1D1E43771B003E96B0 /* RNNLayoutNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BEF0D1B1E43771B003E96B0 /* RNNLayoutNode.m */; };
A7626BFD1FC2FB2C00492FB8 /* RNNTopBarOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = A7626BFC1FC2FB2C00492FB8 /* RNNTopBarOptions.m */; };
A7626C011FC5796200492FB8 /* RNNBottomTabsOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = A7626C001FC5796200492FB8 /* RNNBottomTabsOptions.m */; };
C2A57A1C21E815F80066711C /* InteractivePopGestureDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = C2A57A1A21E815F80066711C /* InteractivePopGestureDelegate.h */; };
C2A57A1D21E815F80066711C /* InteractivePopGestureDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = C2A57A1B21E815F80066711C /* InteractivePopGestureDelegate.m */; };
E33AC20020B5BA0B0090DB8A /* RNNSplitViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E33AC1FF20B5BA0B0090DB8A /* RNNSplitViewController.m */; };
E33AC20520B5C3890090DB8A /* RNNStatusBarOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = E33AC20320B5C3890090DB8A /* RNNStatusBarOptions.m */; };
E33AC20820B5C4F90090DB8A /* RNNSplitViewOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = E33AC20720B5C4F90090DB8A /* RNNSplitViewOptions.m */; };
Expand Down Expand Up @@ -617,6 +619,8 @@
A7626BFE1FC2FB6700492FB8 /* RNNTopBarOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNTopBarOptions.h; sourceTree = "<group>"; };
A7626BFF1FC578AB00492FB8 /* RNNBottomTabsOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNBottomTabsOptions.h; sourceTree = "<group>"; };
A7626C001FC5796200492FB8 /* RNNBottomTabsOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNBottomTabsOptions.m; sourceTree = "<group>"; };
C2A57A1A21E815F80066711C /* InteractivePopGestureDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = InteractivePopGestureDelegate.h; sourceTree = "<group>"; };
C2A57A1B21E815F80066711C /* InteractivePopGestureDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = InteractivePopGestureDelegate.m; sourceTree = "<group>"; };
D8AFADBD1BEE6F3F00A4592D /* libReactNativeNavigation.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libReactNativeNavigation.a; sourceTree = BUILT_PRODUCTS_DIR; };
E33AC1FF20B5BA0B0090DB8A /* RNNSplitViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNSplitViewController.m; sourceTree = "<group>"; };
E33AC20120B5BA550090DB8A /* RNNSplitViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNSplitViewController.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -719,6 +723,8 @@
5038A3BC216E1490009280BC /* RNNTabBarItemCreator.m */,
5053CE7D2175FB1900D0386B /* RNNDefaultOptionsHelper.h */,
5053CE7E2175FB1900D0386B /* RNNDefaultOptionsHelper.m */,
C2A57A1A21E815F80066711C /* InteractivePopGestureDelegate.h */,
C2A57A1B21E815F80066711C /* InteractivePopGestureDelegate.m */,
);
name = Helpers;
sourceTree = "<group>";
Expand Down Expand Up @@ -1206,6 +1212,7 @@
E8AEDB4A1F5C0BAF000F5A6A /* RNNInteractivePopAnimator.h in Headers */,
263905B71E4C6F440023D7D3 /* UIViewController+MMDrawerController.h in Headers */,
263905BB1E4C6F440023D7D3 /* RCCDrawerHelper.h in Headers */,
C2A57A1C21E815F80066711C /* InteractivePopGestureDelegate.h in Headers */,
263905CC1E4C6F440023D7D3 /* SidebarWunderlistAnimation.h in Headers */,
507F43F41FF4FCFE00D9425B /* HMSegmentedControl.h in Headers */,
501CD31F214A5B6900A6E225 /* RNNLayoutInfo.h in Headers */,
Expand Down Expand Up @@ -1515,6 +1522,7 @@
50F5DFC21F407A8C001A00BC /* RNNTabBarController.m in Sources */,
50887CA920F26BFE00D06111 /* RNNOverlayWindow.m in Sources */,
5038A3CF216E35E0009280BC /* Dictionary.m in Sources */,
C2A57A1D21E815F80066711C /* InteractivePopGestureDelegate.m in Sources */,
263905BC1E4C6F440023D7D3 /* RCCDrawerHelper.m in Sources */,
4534E72620CB6724009F8185 /* RNNLargeTitleOptions.m in Sources */,
507E7D58201DDD3000444E6C /* RNNAnimationOptions.m in Sources */,
Expand Down

0 comments on commit 81d8b69

Please sign in to comment.