Skip to content

Commit

Permalink
Ignore pan gesture when no drawer is enabled (#4649)
Browse files Browse the repository at this point in the history
  • Loading branch information
StasDoskalenko authored and yogevbd committed Feb 14, 2019
1 parent e7c0d16 commit 664ef34
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions lib/ios/RNNSideMenu/MMDrawerController/MMDrawerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ @interface MMDrawerController () <UIGestureRecognizerDelegate>{
@property (nonatomic, copy) MMDrawerGestureCompletionBlock gestureStart;
@property (nonatomic, copy) MMDrawerGestureCompletionBlock gestureCompletion;
@property (nonatomic, assign, getter = isAnimatingDrawer) BOOL animatingDrawer;
@property (nonatomic, strong) UIGestureRecognizer *pan;

@end

Expand Down Expand Up @@ -875,6 +876,15 @@ -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOr
}
}

-(bool)hasPan
{
for (UIGestureRecognizer *recognizer in self.view.gestureRecognizers) {
if(recognizer == _pan) { return YES; }
}
return NO;
}


#pragma mark - Setters
-(void)setRightDrawerViewController:(UIViewController *)rightDrawerViewController{
[self setDrawerViewController:rightDrawerViewController forSide:MMDrawerSideRight];
Expand Down Expand Up @@ -1014,6 +1024,18 @@ -(void)setAnimatingDrawer:(BOOL)animatingDrawer{
[self.view setUserInteractionEnabled:!animatingDrawer];
}

- (void)setLeftSideEnabled:(BOOL)leftSideEnabled
{
_leftSideEnabled = leftSideEnabled;
[self updatePanHandlersState];
}

- (void)setRightSideEnabled:(BOOL)rightSideEnabled
{
_rightSideEnabled = rightSideEnabled;
[self updatePanHandlersState];
}

#pragma mark - Getters
-(CGFloat)maximumLeftDrawerWidth{
if(self.leftDrawerViewController){
Expand Down Expand Up @@ -1184,6 +1206,15 @@ -(void)panGestureCallback:(UIPanGestureRecognizer *)panGesture{
}
}

- (void)updatePanHandlersState
{
if(_leftSideEnabled == NO && _rightSideEnabled == NO) {
if([self hasPan]) { [self.view removeGestureRecognizer:_pan]; }
} else {
if(![self hasPan]) { [self.view addGestureRecognizer:_pan]; }
}
}

#pragma mark - iOS 7 Status Bar Helpers
-(UIViewController*)childViewControllerForStatusBarStyle{
return [self childViewControllerForSide:self.openSide];
Expand Down Expand Up @@ -1343,9 +1374,9 @@ static inline CGFloat originXForDrawerOriginAndTargetOriginOffset(CGFloat origin

#pragma mark - Helpers
-(void)setupGestureRecognizers{
UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureCallback:)];
[pan setDelegate:self];
[self.view addGestureRecognizer:pan];
_pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureCallback:)];
[_pan setDelegate:self];
[self.view addGestureRecognizer:_pan];

UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureCallback:)];
[tap setDelegate:self];
Expand Down

0 comments on commit 664ef34

Please sign in to comment.