Quellcode durchsuchen

Add sideMenu.openGestureMode option (#4348)

Until now controlling drawers touch gestures was impossible, drawers received gesture opening touch from the entire screen and that causes collisions with other gestures (which are implemented on the javascript side).

This commit adding modes for how sideMenu drawers gestures will receive opening touch.
```
{
  sideMenu: {
    openGestureMode: 'entireScreen' | 'bezel'
  }
}
```

- `entireScreen`: drawer gesture will trigger drawer opening from the entire screen
- `bezel`: drawer gesture will trigger drawer opening only from the center screen bezel frame

The default didn't change.
Yogev Ben David vor 6 Jahren
Ursprung
Commit
0a4bf2ade3
Es ist kein Benutzerkonto mit dieser Commiter-Email verbunden

+ 2
- 1
docs/docs/styling.md Datei anzeigen

@@ -199,7 +199,8 @@ Navigation.mergeOptions(this.props.componentId, {
199 199
       shouldStretchDrawer: false, // defaults to true, when false sideMenu contents not stretched when opened past the width
200 200
       animationVelocity: 2500, // defaults to 840, high number is a faster sideMenu open/close animation
201 201
       animationType: 'parallax' // defaults to none if not provided, options are 'parallax', 'door', 'slide', or 'slide-and-scale'    
202
-    }
202
+    },
203
+    openGestureMode: 'entireScreen' | 'bezel'
203 204
   }
204 205
   bottomTabs: {
205 206
     barStyle: 'default' | 'black',

+ 16
- 0
lib/ios/RCTConvert+SideMenuOpenGestureMode.h Datei anzeigen

@@ -0,0 +1,16 @@
1
+#import <React/RCTConvert.h>
2
+#import "MMDrawerController.h"
3
+
4
+@interface RCTConvert (SideMenuOpenGestureMode)
5
+
6
+@end
7
+
8
+@implementation RCTConvert (SideMenuOpenGestureMode)
9
+
10
+RCT_ENUM_CONVERTER(MMOpenDrawerGestureMode,
11
+				   (@{@"entireScreen": @(MMOpenDrawerGestureModeAll),
12
+					  @"bezel": @(MMOpenDrawerGestureModeNone),
13
+					  }), MMOpenDrawerGestureModeAll, integerValue)
14
+
15
+@end
16
+

+ 0
- 1
lib/ios/RNNSideMenuController.m Datei anzeigen

@@ -25,7 +25,6 @@
25 25
 	
26 26
 	self.layoutInfo = layoutInfo;
27 27
 	
28
-	self.openDrawerGestureModeMask = MMOpenDrawerGestureModeAll;
29 28
 	self.closeDrawerGestureModeMask = MMCloseDrawerGestureModeAll;
30 29
 	
31 30
 	[self.presenter applyOptionsOnInit:self.resolveOptions];

+ 2
- 0
lib/ios/RNNSideMenuOptions.h Datei anzeigen

@@ -1,5 +1,6 @@
1 1
 #import "RNNOptions.h"
2 2
 #import "RNNSideMenuSideOptions.h"
3
+#import "SideMenuOpenMode.h"
3 4
 
4 5
 @interface RNNSideMenuOptions : RNNOptions
5 6
 
@@ -7,5 +8,6 @@
7 8
 @property (nonatomic, strong) RNNSideMenuSideOptions* right;
8 9
 
9 10
 @property (nonatomic, strong) Text* animationType;
11
+@property (nonatomic, strong) SideMenuOpenMode* openGestureMode;
10 12
 
11 13
 @end

+ 3
- 1
lib/ios/RNNSideMenuOptions.m Datei anzeigen

@@ -1,5 +1,6 @@
1 1
 #import "RNNSideMenuOptions.h"
2 2
 #import "RNNSideMenuController.h"
3
+#import "SideMenuOpenGestureModeParser.h"
3 4
 
4 5
 @implementation RNNSideMenuOptions
5 6
 
@@ -9,7 +10,8 @@
9 10
 	self.left = [[RNNSideMenuSideOptions alloc] initWithDict:dict[@"left"]];
10 11
 	self.right = [[RNNSideMenuSideOptions alloc] initWithDict:dict[@"right"]];
11 12
 	self.animationType = [TextParser parse:dict key:@"animationType"];
12
-	
13
+	self.openGestureMode = [SideMenuOpenGestureModeParser parse:dict key:@"openGestureMode"];
14
+
13 15
 	return self;
14 16
 }
15 17
 

+ 2
- 0
lib/ios/RNNSideMenuPresenter.m Datei anzeigen

@@ -31,6 +31,8 @@
31 31
 	if (initialOptions.sideMenu.right.width.hasValue) {
32 32
 		[sideMenuController side:MMDrawerSideRight width:initialOptions.sideMenu.right.width.get];
33 33
 	}
34
+	
35
+	[sideMenuController setOpenDrawerGestureModeMask:[initialOptions.sideMenu.openGestureMode getWithDefaultValue:MMOpenDrawerGestureModeAll]];
34 36
 }
35 37
 
36 38
 - (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavigationOptions *)currentOptions defaultOptions:(RNNNavigationOptions *)defaultOptions {

+ 18
- 0
lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj Datei anzeigen

@@ -222,6 +222,10 @@
222 222
 		50CE8503217C6C9B00084EBF /* RNNSideMenuPresenterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 50CE8502217C6C9B00084EBF /* RNNSideMenuPresenterTest.m */; };
223 223
 		50D031342005149000386B3D /* RNNOverlayManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 50D031322005149000386B3D /* RNNOverlayManager.h */; };
224 224
 		50D031352005149000386B3D /* RNNOverlayManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 50D031332005149000386B3D /* RNNOverlayManager.m */; };
225
+		50E02BD821A6EE0F00A43942 /* SideMenuOpenMode.h in Headers */ = {isa = PBXBuildFile; fileRef = 50E02BD621A6EE0F00A43942 /* SideMenuOpenMode.h */; };
226
+		50E02BD921A6EE0F00A43942 /* SideMenuOpenMode.m in Sources */ = {isa = PBXBuildFile; fileRef = 50E02BD721A6EE0F00A43942 /* SideMenuOpenMode.m */; };
227
+		50E02BDC21A6EE7900A43942 /* SideMenuOpenGestureModeParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 50E02BDA21A6EE7900A43942 /* SideMenuOpenGestureModeParser.m */; };
228
+		50E02BDD21A6EE7900A43942 /* SideMenuOpenGestureModeParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 50E02BDB21A6EE7900A43942 /* SideMenuOpenGestureModeParser.h */; };
225 229
 		50EB4ED72068EBE000D6ED34 /* RNNBackgroundOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 50EB4ED52068EBE000D6ED34 /* RNNBackgroundOptions.h */; };
226 230
 		50EB4ED82068EBE000D6ED34 /* RNNBackgroundOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 50EB4ED62068EBE000D6ED34 /* RNNBackgroundOptions.m */; };
227 231
 		50EB93421FE14A3E00BD8EEE /* RNNBottomTabOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 50EB93401FE14A3E00BD8EEE /* RNNBottomTabOptions.m */; };
@@ -537,6 +541,11 @@
537 541
 		50CE8502217C6C9B00084EBF /* RNNSideMenuPresenterTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNSideMenuPresenterTest.m; sourceTree = "<group>"; };
538 542
 		50D031322005149000386B3D /* RNNOverlayManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNOverlayManager.h; sourceTree = "<group>"; };
539 543
 		50D031332005149000386B3D /* RNNOverlayManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNOverlayManager.m; sourceTree = "<group>"; };
544
+		50E02BD521A6E54B00A43942 /* RCTConvert+SideMenuOpenGestureMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RCTConvert+SideMenuOpenGestureMode.h"; sourceTree = "<group>"; };
545
+		50E02BD621A6EE0F00A43942 /* SideMenuOpenMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SideMenuOpenMode.h; sourceTree = "<group>"; };
546
+		50E02BD721A6EE0F00A43942 /* SideMenuOpenMode.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SideMenuOpenMode.m; sourceTree = "<group>"; };
547
+		50E02BDA21A6EE7900A43942 /* SideMenuOpenGestureModeParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SideMenuOpenGestureModeParser.m; sourceTree = "<group>"; };
548
+		50E02BDB21A6EE7900A43942 /* SideMenuOpenGestureModeParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SideMenuOpenGestureModeParser.h; sourceTree = "<group>"; };
540 549
 		50EB4ED52068EBE000D6ED34 /* RNNBackgroundOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNBackgroundOptions.h; sourceTree = "<group>"; };
541 550
 		50EB4ED62068EBE000D6ED34 /* RNNBackgroundOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNBackgroundOptions.m; sourceTree = "<group>"; };
542 551
 		50EB933F1FE14A3E00BD8EEE /* RNNBottomTabOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNBottomTabOptions.h; sourceTree = "<group>"; };
@@ -679,6 +688,7 @@
679 688
 				5038A3BF216E1E66009280BC /* RNNFontAttributesCreator.h */,
680 689
 				5038A3C0216E1E66009280BC /* RNNFontAttributesCreator.m */,
681 690
 				505EDD48214FDA800071C7DE /* RCTConvert+Modal.h */,
691
+				50E02BD521A6E54B00A43942 /* RCTConvert+SideMenuOpenGestureMode.h */,
682 692
 				5038A3BB216E1490009280BC /* RNNTabBarItemCreator.h */,
683 693
 				5038A3BC216E1490009280BC /* RNNTabBarItemCreator.m */,
684 694
 				5053CE7D2175FB1900D0386B /* RNNDefaultOptionsHelper.h */,
@@ -803,6 +813,8 @@
803 813
 				5012241521736667000F5F98 /* Color.m */,
804 814
 				5012241821736678000F5F98 /* Image.h */,
805 815
 				5012241921736678000F5F98 /* Image.m */,
816
+				50E02BD621A6EE0F00A43942 /* SideMenuOpenMode.h */,
817
+				50E02BD721A6EE0F00A43942 /* SideMenuOpenMode.m */,
806 818
 				50495940216F5E5D006D2B81 /* NullBool.h */,
807 819
 				50495941216F5E5D006D2B81 /* NullBool.m */,
808 820
 				50495948216F5FE6006D2B81 /* NullText.h */,
@@ -834,6 +846,8 @@
834 846
 				5049594D216F6277006D2B81 /* NumberParser.m */,
835 847
 				50495954216F6B3D006D2B81 /* DictionaryParser.h */,
836 848
 				50495955216F6B3D006D2B81 /* DictionaryParser.m */,
849
+				50E02BDB21A6EE7900A43942 /* SideMenuOpenGestureModeParser.h */,
850
+				50E02BDA21A6EE7900A43942 /* SideMenuOpenGestureModeParser.m */,
837 851
 				5012241C217366D4000F5F98 /* ColorParser.h */,
838 852
 				5012241D217366D4000F5F98 /* ColorParser.m */,
839 853
 				50122428217372B3000F5F98 /* ImageParser.h */,
@@ -1172,6 +1186,7 @@
1172 1186
 				5012242A217372B3000F5F98 /* ImageParser.h in Headers */,
1173 1187
 				50CB3B691FDE911400AA153B /* RNNSideMenuOptions.h in Headers */,
1174 1188
 				5012240A21735959000F5F98 /* RNNSideMenuPresenter.h in Headers */,
1189
+				50E02BDD21A6EE7900A43942 /* SideMenuOpenGestureModeParser.h in Headers */,
1175 1190
 				263905BD1E4C6F440023D7D3 /* RCCDrawerProtocol.h in Headers */,
1176 1191
 				5038A3B5216DF602009280BC /* UINavigationController+RNNOptions.h in Headers */,
1177 1192
 				5038A3C1216E1E66009280BC /* RNNFontAttributesCreator.h in Headers */,
@@ -1257,6 +1272,7 @@
1257 1272
 				503955972174864E00B0A663 /* NullDouble.h in Headers */,
1258 1273
 				263905C81E4C6F440023D7D3 /* SidebarFlipboardAnimation.h in Headers */,
1259 1274
 				7BEF0D1C1E43771B003E96B0 /* RNNLayoutNode.h in Headers */,
1275
+				50E02BD821A6EE0F00A43942 /* SideMenuOpenMode.h in Headers */,
1260 1276
 				507F43C91FF4F9CC00D9425B /* RNNTopTabOptions.h in Headers */,
1261 1277
 				E8A5CD521F464F0400E89D0D /* RNNAnimator.h in Headers */,
1262 1278
 				50451D0D2042F70900695F00 /* RNNTransition.h in Headers */,
@@ -1424,6 +1440,7 @@
1424 1440
 				263905E71E4CAC950023D7D3 /* RNNSideMenuChildVC.m in Sources */,
1425 1441
 				50495957216F6B3D006D2B81 /* DictionaryParser.m in Sources */,
1426 1442
 				390AD478200F499D00A8250D /* RNNSwizzles.m in Sources */,
1443
+				50E02BD921A6EE0F00A43942 /* SideMenuOpenMode.m in Sources */,
1427 1444
 				7BA500751E2544B9001B9E1B /* ReactNativeNavigation.m in Sources */,
1428 1445
 				5038A3BA216DFCFD009280BC /* UITabBarController+RNNOptions.m in Sources */,
1429 1446
 				263905B21E4C6F440023D7D3 /* MMDrawerController.m in Sources */,
@@ -1443,6 +1460,7 @@
1443 1460
 				50395594217485B000B0A663 /* Double.m in Sources */,
1444 1461
 				504AFE751FFFF0540076E904 /* RNNTopTabsOptions.m in Sources */,
1445 1462
 				50175CD2207A2AA1004FE91B /* RNNComponentOptions.m in Sources */,
1463
+				50E02BDC21A6EE7900A43942 /* SideMenuOpenGestureModeParser.m in Sources */,
1446 1464
 				7BEF0D1D1E43771B003E96B0 /* RNNLayoutNode.m in Sources */,
1447 1465
 				7BA500781E254908001B9E1B /* RNNSplashScreen.m in Sources */,
1448 1466
 				5038A3B6216DF602009280BC /* UINavigationController+RNNOptions.m in Sources */,

+ 14
- 0
lib/ios/ReactNativeNavigationTests/RNNSideMenuPresenterTest.m Datei anzeigen

@@ -69,6 +69,20 @@
69 69
 	[self.bindedViewController verify];
70 70
 }
71 71
 
72
+- (void)testApplyOptionsOnInitShouldSetDefaultDrawerGestureMode {
73
+	[[self.bindedViewController expect] setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
74
+	[self.uut applyOptionsOnInit:self.options];
75
+	[self.bindedViewController verify];
76
+}
77
+
78
+- (void)testApplyOptionsOnInitShouldSetBezelDrawerGestureMode {
79
+	self.options.sideMenu.openGestureMode = [[SideMenuOpenMode alloc] initWithValue:@(MMOpenDrawerGestureModeNone)];
80
+	[[self.bindedViewController expect] setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeNone];
81
+	[self.uut applyOptionsOnInit:self.options];
82
+	[self.bindedViewController verify];
83
+}
84
+
85
+
72 86
 
73 87
 
74 88
 @end

+ 8
- 0
lib/ios/SideMenuOpenGestureModeParser.h Datei anzeigen

@@ -0,0 +1,8 @@
1
+#import <Foundation/Foundation.h>
2
+#import "SideMenuOpenMode.h"
3
+
4
+@interface SideMenuOpenGestureModeParser : NSObject
5
+
6
++ (SideMenuOpenMode *)parse:(NSDictionary *)json key:(NSString *)key;
7
+
8
+@end

+ 10
- 0
lib/ios/SideMenuOpenGestureModeParser.m Datei anzeigen

@@ -0,0 +1,10 @@
1
+#import "SideMenuOpenGestureModeParser.h"
2
+#import "RCTConvert+SideMenuOpenGestureMode.h"
3
+
4
+@implementation SideMenuOpenGestureModeParser
5
+
6
++ (SideMenuOpenMode *)parse:(NSDictionary *)json key:(NSString *)key {	
7
+	return json[key] ? [[SideMenuOpenMode alloc] initWithValue:@([RCTConvert MMOpenDrawerGestureMode:json[key]])] : [[SideMenuOpenMode alloc] initWithValue:nil];
8
+}
9
+
10
+@end

+ 7
- 0
lib/ios/SideMenuOpenMode.h Datei anzeigen

@@ -0,0 +1,7 @@
1
+#import "IntNumber.h"
2
+
3
+@interface SideMenuOpenMode : IntNumber
4
+
5
+
6
+
7
+@end

+ 5
- 0
lib/ios/SideMenuOpenMode.m Datei anzeigen

@@ -0,0 +1,5 @@
1
+#import "SideMenuOpenMode.h"
2
+
3
+@implementation SideMenuOpenMode
4
+
5
+@end

+ 6
- 0
lib/src/interfaces/Options.ts Datei anzeigen

@@ -521,6 +521,12 @@ export interface OptionsSideMenu {
521 521
    * Configure the right side menu
522 522
    */
523 523
   right?: SideMenuSide;
524
+  /**
525
+   * Configure how a user is allowed to open a drawer using gestures
526
+   * #### (iOS specific)
527
+   * @default 'entireScreen'
528
+   */
529
+  openGestureMode?: 'entireScreen' | 'bezel';
524 530
 }
525 531
 
526 532
 export interface OptionsOverlay {