diff --git a/lib/ios/InteractivePopGestureDelegate.h b/lib/ios/InteractivePopGestureDelegate.h index 75db0369c2a..7e6e7486702 100644 --- a/lib/ios/InteractivePopGestureDelegate.h +++ b/lib/ios/InteractivePopGestureDelegate.h @@ -6,4 +6,6 @@ @property (nonatomic, weak) UINavigationController *navigationController; @property (nonatomic, weak) id originalDelegate; +@property (nonatomic) BOOL enabled; + @end diff --git a/lib/ios/InteractivePopGestureDelegate.m b/lib/ios/InteractivePopGestureDelegate.m index 1e1370ed828..81150344551 100644 --- a/lib/ios/InteractivePopGestureDelegate.m +++ b/lib/ios/InteractivePopGestureDelegate.m @@ -3,8 +3,13 @@ @implementation InteractivePopGestureDelegate +- (instancetype)init { + self = [super init]; + _enabled = YES; + return self; +} - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { - if (self.navigationController.viewControllers.count < 2) { + if (self.navigationController.viewControllers.count < 2 || !_enabled) { return NO; } else if (self.navigationController.navigationBarHidden) { return YES; diff --git a/lib/ios/RNNStackPresenter.h b/lib/ios/RNNStackPresenter.h index f5cc431aa40..d3da89f16de 100644 --- a/lib/ios/RNNStackPresenter.h +++ b/lib/ios/RNNStackPresenter.h @@ -1,12 +1,9 @@ #import "RNNBasePresenter.h" #import "RNNComponentViewCreator.h" #import "RNNReactComponentRegistry.h" -#import "InteractivePopGestureDelegate.h" @interface RNNStackPresenter : RNNBasePresenter -@property (nonatomic, strong) InteractivePopGestureDelegate *interactivePopGestureDelegate; - - (instancetype)initWithComponentRegistry:(RNNReactComponentRegistry *)componentRegistry defaultOptions:(RNNNavigationOptions *)defaultOptions; - (void)applyOptionsBeforePopping:(RNNNavigationOptions *)options; diff --git a/lib/ios/RNNStackPresenter.m b/lib/ios/RNNStackPresenter.m index 336e0b06192..52be33c12e5 100644 --- a/lib/ios/RNNStackPresenter.m +++ b/lib/ios/RNNStackPresenter.m @@ -4,12 +4,14 @@ #import "RNNCustomTitleView.h" #import "TopBarPresenterCreator.h" #import "RNNReactBackgroundView.h" +#import "InteractivePopGestureDelegate.h" @interface RNNStackPresenter() { RNNReactComponentRegistry* _componentRegistry; UIView* _customTopBarBackground; RNNReactView* _topBarBackgroundReactView; TopBarPresenter* _topBarPresenter; + InteractivePopGestureDelegate *_interactivePopGestureDelegate; } @property (nonatomic, weak) RNNStackController* stackController; @@ -20,12 +22,15 @@ @implementation RNNStackPresenter - (instancetype)initWithComponentRegistry:(RNNReactComponentRegistry *)componentRegistry defaultOptions:(RNNNavigationOptions *)defaultOptions { self = [super initWithDefaultOptions:defaultOptions]; _componentRegistry = componentRegistry; + _interactivePopGestureDelegate = [InteractivePopGestureDelegate new]; return self; } -- (void)bindViewController:(UIViewController *)boundViewController { +- (void)bindViewController:(UINavigationController *)boundViewController { [super bindViewController:boundViewController]; _topBarPresenter = [TopBarPresenterCreator createWithBoundedNavigationController:self.stackController]; + _interactivePopGestureDelegate.navigationController = boundViewController; + _interactivePopGestureDelegate.originalDelegate = boundViewController.interactivePopGestureRecognizer.delegate; } - (void)componentDidAppear { @@ -45,13 +50,10 @@ - (void)applyOptions:(RNNNavigationOptions *)options { RNNStackController* stack = self.stackController; RNNNavigationOptions * withDefault = [options withDefault:[self defaultOptions]]; - self.interactivePopGestureDelegate = [InteractivePopGestureDelegate new]; - self.interactivePopGestureDelegate.navigationController = stack; - self.interactivePopGestureDelegate.originalDelegate = stack.interactivePopGestureRecognizer.delegate; - stack.interactivePopGestureRecognizer.delegate = self.interactivePopGestureDelegate; + [_interactivePopGestureDelegate setEnabled:[withDefault.popGesture getWithDefaultValue:YES]]; + stack.interactivePopGestureRecognizer.delegate = _interactivePopGestureDelegate; [stack setBarStyle:[RCTConvert UIBarStyle:[withDefault.topBar.barStyle getWithDefaultValue:@"default"]]]; - [stack setInteractivePopGestureEnabled:[withDefault.popGesture getWithDefaultValue:YES]]; [stack setRootBackgroundImage:[withDefault.rootBackgroundImage getWithDefaultValue:nil]]; [stack setNavigationBarTestId:[withDefault.topBar.testID getWithDefaultValue:nil]]; [stack setNavigationBarVisible:[withDefault.topBar.visible getWithDefaultValue:YES] animated:[withDefault.topBar.animate getWithDefaultValue:YES]]; @@ -84,7 +86,7 @@ - (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigat RNNStackController* stack = self.stackController; if (options.popGesture.hasValue) { - [stack setInteractivePopGestureEnabled:options.popGesture.get]; + [_interactivePopGestureDelegate setEnabled:options.popGesture.get]; } if (options.rootBackgroundImage.hasValue) { diff --git a/lib/ios/UINavigationController+RNNOptions.h b/lib/ios/UINavigationController+RNNOptions.h index 04d5c5fe554..629361baf24 100644 --- a/lib/ios/UINavigationController+RNNOptions.h +++ b/lib/ios/UINavigationController+RNNOptions.h @@ -2,8 +2,6 @@ @interface UINavigationController (RNNOptions) -- (void)setInteractivePopGestureEnabled:(BOOL)enabled; - - (void)setRootBackgroundImage:(UIImage *)backgroundImage; - (void)setNavigationBarTestId:(NSString *)testID; diff --git a/lib/ios/UINavigationController+RNNOptions.m b/lib/ios/UINavigationController+RNNOptions.m index 83480f747b3..d48d3491254 100644 --- a/lib/ios/UINavigationController+RNNOptions.m +++ b/lib/ios/UINavigationController+RNNOptions.m @@ -5,10 +5,6 @@ @implementation UINavigationController (RNNOptions) -- (void)setInteractivePopGestureEnabled:(BOOL)enabled { - self.interactivePopGestureRecognizer.enabled = enabled; -} - - (void)setRootBackgroundImage:(UIImage *)backgroundImage { UIImageView* backgroundImageView = (self.view.subviews.count > 0) ? self.view.subviews[0] : nil; if (![backgroundImageView isKindOfClass:[UIImageView class]]) {