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,6 +167,7 @@ static NSString *MMDrawerOpenSideKey = @"MMDrawerOpenSide";
167 167
 @property (nonatomic, copy) MMDrawerGestureCompletionBlock gestureStart;
168 168
 @property (nonatomic, copy) MMDrawerGestureCompletionBlock gestureCompletion;
169 169
 @property (nonatomic, assign, getter = isAnimatingDrawer) BOOL animatingDrawer;
170
+@property (nonatomic, strong) UIGestureRecognizer *pan;
170 171
 
171 172
 @end
172 173
 
@@ -875,6 +876,15 @@ static NSString *MMDrawerOpenSideKey = @"MMDrawerOpenSide";
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 888
 #pragma mark - Setters
879 889
 -(void)setRightDrawerViewController:(UIViewController *)rightDrawerViewController{
880 890
     [self setDrawerViewController:rightDrawerViewController forSide:MMDrawerSideRight];
@@ -1014,6 +1024,18 @@ static NSString *MMDrawerOpenSideKey = @"MMDrawerOpenSide";
1014 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 1039
 #pragma mark - Getters
1018 1040
 -(CGFloat)maximumLeftDrawerWidth{
1019 1041
     if(self.leftDrawerViewController){
@@ -1184,6 +1206,15 @@ static NSString *MMDrawerOpenSideKey = @"MMDrawerOpenSide";
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 1218
 #pragma mark - iOS 7 Status Bar Helpers
1188 1219
 -(UIViewController*)childViewControllerForStatusBarStyle{
1189 1220
     return [self childViewControllerForSide:self.openSide];
@@ -1343,9 +1374,9 @@ static inline CGFloat originXForDrawerOriginAndTargetOriginOffset(CGFloat origin
1343 1374
 
1344 1375
 #pragma mark - Helpers
1345 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 1381
     UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureCallback:)];
1351 1382
     [tap setDelegate:self];