Skip to content

Commit

Permalink
Fix popGesture freezes the app (#5863)
Browse files Browse the repository at this point in the history
* Fix popGesture freeze the app

* Move popGestureDelegate initialization to init
  • Loading branch information
yogevbd authored Jan 21, 2020
1 parent d81b0bf commit 37473f8
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
2 changes: 2 additions & 0 deletions lib/ios/InteractivePopGestureDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
@property (nonatomic, weak) UINavigationController *navigationController;
@property (nonatomic, weak) id<UIGestureRecognizerDelegate> originalDelegate;

@property (nonatomic) BOOL enabled;

@end
7 changes: 6 additions & 1 deletion lib/ios/InteractivePopGestureDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions lib/ios/RNNStackPresenter.h
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
16 changes: 9 additions & 7 deletions lib/ios/RNNStackPresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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]];
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions lib/ios/UINavigationController+RNNOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

@interface UINavigationController (RNNOptions)

- (void)setInteractivePopGestureEnabled:(BOOL)enabled;

- (void)setRootBackgroundImage:(UIImage *)backgroundImage;

- (void)setNavigationBarTestId:(NSString *)testID;
Expand Down
4 changes: 0 additions & 4 deletions lib/ios/UINavigationController+RNNOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]]) {
Expand Down

3 comments on commit 37473f8

@itsam
Copy link
Contributor

@itsam itsam commented on 37473f8 Jan 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this but still, for popGesture to work as expected, you need to try 3-4 times to actually make it happen... It's not butter smooth (like for example when you slide the sideMenu). Any ideas?

@guyca
Copy link
Collaborator

@guyca guyca commented on 37473f8 Jan 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@itsam What do you mean when you say it doesn't work as expected? Could you please open an issue and post any information you have? Thanks.

@itsam
Copy link
Contributor

@itsam itsam commented on 37473f8 Jan 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@itsam What do you mean when you say it doesn't work as expected? Could you please open an issue and post any information you have? Thanks.

Hi @guyca. Thanks you prompt reply. Actually the issue I had was related with popGesture when sidebar is disabled. So not directly related with this commit but still there's a problem. I have figure it how to solve this though. Please check #5865. If I apply this patch (see gist), popGesture works butter smooth.

Still, as I am not an expert you need to complete the patch in order to respect the options (.e.g. bezel).
Hope I make myself clear.

Your work and effort is much appreciated! Thank you for this excellent library.

Please sign in to comment.