Browse Source

Ignore pan gesture when no drawer is enabled (#4649)

Stanislav Doskalenko 5 years ago
parent
commit
664ef34309
1 changed files with 34 additions and 3 deletions
  1. 34
    3
      lib/ios/RNNSideMenu/MMDrawerController/MMDrawerController.m

+ 34
- 3
lib/ios/RNNSideMenu/MMDrawerController/MMDrawerController.m View File

167
 @property (nonatomic, copy) MMDrawerGestureCompletionBlock gestureStart;
167
 @property (nonatomic, copy) MMDrawerGestureCompletionBlock gestureStart;
168
 @property (nonatomic, copy) MMDrawerGestureCompletionBlock gestureCompletion;
168
 @property (nonatomic, copy) MMDrawerGestureCompletionBlock gestureCompletion;
169
 @property (nonatomic, assign, getter = isAnimatingDrawer) BOOL animatingDrawer;
169
 @property (nonatomic, assign, getter = isAnimatingDrawer) BOOL animatingDrawer;
170
+@property (nonatomic, strong) UIGestureRecognizer *pan;
170
 
171
 
171
 @end
172
 @end
172
 
173
 
875
     }
876
     }
876
 }
877
 }
877
 
878
 
879
+-(bool)hasPan
880
+{
881
+    for (UIGestureRecognizer *recognizer in self.view.gestureRecognizers) {
882
+        if(recognizer == _pan) { return YES; }
883
+    }
884
+    return NO;
885
+}
886
+
887
+
878
 #pragma mark - Setters
888
 #pragma mark - Setters
879
 -(void)setRightDrawerViewController:(UIViewController *)rightDrawerViewController{
889
 -(void)setRightDrawerViewController:(UIViewController *)rightDrawerViewController{
880
     [self setDrawerViewController:rightDrawerViewController forSide:MMDrawerSideRight];
890
     [self setDrawerViewController:rightDrawerViewController forSide:MMDrawerSideRight];
1014
     [self.view setUserInteractionEnabled:!animatingDrawer];
1024
     [self.view setUserInteractionEnabled:!animatingDrawer];
1015
 }
1025
 }
1016
 
1026
 
1027
+- (void)setLeftSideEnabled:(BOOL)leftSideEnabled
1028
+{
1029
+    _leftSideEnabled = leftSideEnabled;
1030
+    [self updatePanHandlersState];
1031
+}
1032
+
1033
+- (void)setRightSideEnabled:(BOOL)rightSideEnabled
1034
+{
1035
+    _rightSideEnabled = rightSideEnabled;
1036
+    [self updatePanHandlersState];
1037
+}
1038
+
1017
 #pragma mark - Getters
1039
 #pragma mark - Getters
1018
 -(CGFloat)maximumLeftDrawerWidth{
1040
 -(CGFloat)maximumLeftDrawerWidth{
1019
     if(self.leftDrawerViewController){
1041
     if(self.leftDrawerViewController){
1184
     }
1206
     }
1185
 }
1207
 }
1186
 
1208
 
1209
+- (void)updatePanHandlersState
1210
+{
1211
+    if(_leftSideEnabled == NO && _rightSideEnabled == NO) {
1212
+        if([self hasPan]) { [self.view removeGestureRecognizer:_pan]; }
1213
+    } else {
1214
+        if(![self hasPan]) { [self.view addGestureRecognizer:_pan]; }
1215
+    }
1216
+}
1217
+
1187
 #pragma mark - iOS 7 Status Bar Helpers
1218
 #pragma mark - iOS 7 Status Bar Helpers
1188
 -(UIViewController*)childViewControllerForStatusBarStyle{
1219
 -(UIViewController*)childViewControllerForStatusBarStyle{
1189
     return [self childViewControllerForSide:self.openSide];
1220
     return [self childViewControllerForSide:self.openSide];
1343
 
1374
 
1344
 #pragma mark - Helpers
1375
 #pragma mark - Helpers
1345
 -(void)setupGestureRecognizers{
1376
 -(void)setupGestureRecognizers{
1346
-    UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureCallback:)];
1347
-    [pan setDelegate:self];
1348
-    [self.view addGestureRecognizer:pan];
1377
+    _pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureCallback:)];
1378
+    [_pan setDelegate:self];
1379
+    [self.view addGestureRecognizer:_pan];
1349
     
1380
     
1350
     UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureCallback:)];
1381
     UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureCallback:)];
1351
     [tap setDelegate:self];
1382
     [tap setDelegate:self];