Преглед изворни кода

Fixes sideMenu shouldStretchDrawer and animationVelocity ooptions - #4178 (#4179)

Yogev Ben David пре 6 година
родитељ
комит
e8806ea96b
No account linked to committer's email address

+ 2
- 0
lib/ios/Bool.h Прегледај датотеку

@@ -2,6 +2,8 @@
2 2
 
3 3
 @interface Bool : Param
4 4
 
5
+- (instancetype)initWithBOOL:(BOOL)boolValue;
6
+
5 7
 - (BOOL)get;
6 8
 
7 9
 - (NSNumber *)getValue;

+ 5
- 0
lib/ios/Bool.m Прегледај датотеку

@@ -8,6 +8,11 @@
8 8
 
9 9
 @implementation Bool
10 10
 
11
+- (instancetype)initWithBOOL:(BOOL)boolValue {
12
+	self = [super initWithValue:@(boolValue)];
13
+	return self;
14
+}
15
+
11 16
 - (BOOL)get {
12 17
 	return [self.value boolValue];
13 18
 }

+ 4
- 2
lib/ios/RNNSideMenu/MMDrawerController/MMDrawerController.h Прегледај датотеку

@@ -156,14 +156,16 @@ typedef void (^MMDrawerControllerDrawerVisualStateBlock)(MMDrawerController * dr
156 156
  
157 157
  By default, this is set to 840 points per second (three times the default drawer width), meaning it takes 1/3 of a second for the `centerViewController` to open/close across the default drawer width. Note that there is a minimum .1 second duration for built in animations, to account for small distance animations.
158 158
  */
159
-@property (nonatomic, assign) CGFloat animationVelocity;
159
+@property (nonatomic, assign) CGFloat animationVelocityLeft;
160
+@property (nonatomic, assign) CGFloat animationVelocityRight;
160 161
 
161 162
 /**
162 163
  A boolean that determines whether or not the panning gesture will "hard-stop" at the maximum width for a given drawer side.
163 164
  
164 165
  By default, this value is set to YES. Enabling `shouldStretchDrawer` will give the pan a gradual asymptotic stopping point much like `UIScrollView` behaves. Note that if this value is set to YES, the `drawerVisualStateBlock` can be passed a `percentVisible` greater than 1.0, so be sure to handle that case appropriately.
165 166
  */
166
-@property (nonatomic, assign) BOOL shouldStretchDrawer;
167
+@property (nonatomic, assign) BOOL shouldStretchLeftDrawer;
168
+@property (nonatomic, assign) BOOL shouldStretchRightDrawer;
167 169
 
168 170
 /**
169 171
  The current open side of the drawer.

+ 27
- 9
lib/ios/RNNSideMenu/MMDrawerController/MMDrawerController.m Прегледај датотеку

@@ -213,10 +213,12 @@ static NSString *MMDrawerOpenSideKey = @"MMDrawerOpenSide";
213 213
     [self setMaximumLeftDrawerWidth:MMDrawerDefaultWidth];
214 214
     [self setMaximumRightDrawerWidth:MMDrawerDefaultWidth];
215 215
     
216
-    [self setAnimationVelocity:MMDrawerDefaultAnimationVelocity];
216
+    [self setAnimationVelocityLeft:MMDrawerDefaultAnimationVelocity];
217
+	[self setAnimationVelocityRight:MMDrawerDefaultAnimationVelocity];
217 218
     
218 219
     [self setShowsShadow:YES];
219
-    [self setShouldStretchDrawer:YES];
220
+    [self setShouldStretchLeftDrawer:YES];
221
+	[self setShouldStretchRightDrawer:YES];
220 222
     
221 223
     [self setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeNone];
222 224
     [self setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeNone];
@@ -297,7 +299,8 @@ static NSString *MMDrawerOpenSideKey = @"MMDrawerOpenSide";
297 299
 }
298 300
 
299 301
 -(void)closeDrawerAnimated:(BOOL)animated completion:(void (^)(BOOL finished))completion{
300
-    [self closeDrawerAnimated:animated velocity:self.animationVelocity animationOptions:UIViewAnimationOptionCurveEaseInOut completion:completion];
302
+	CGFloat velocity = self.openSide == MMDrawerSideLeft ? self.animationVelocityLeft : self.animationVelocityRight;
303
+	[self closeDrawerAnimated:animated velocity:velocity animationOptions:UIViewAnimationOptionCurveEaseInOut completion:completion];
301 304
 }
302 305
 
303 306
 -(void)closeDrawerAnimated:(BOOL)animated velocity:(CGFloat)velocity animationOptions:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion{
@@ -359,8 +362,8 @@ static NSString *MMDrawerOpenSideKey = @"MMDrawerOpenSide";
359 362
 
360 363
 -(void)openDrawerSide:(MMDrawerSide)drawerSide animated:(BOOL)animated completion:(void (^)(BOOL finished))completion{
361 364
     NSParameterAssert(drawerSide != MMDrawerSideNone);
362
-    
363
-    [self openDrawerSide:drawerSide animated:animated velocity:self.animationVelocity animationOptions:UIViewAnimationOptionCurveEaseInOut completion:completion];
365
+	CGFloat velocity = drawerSide == MMDrawerSideLeft ? self.animationVelocityLeft : self.animationVelocityRight;
366
+    [self openDrawerSide:drawerSide animated:animated velocity:velocity animationOptions:UIViewAnimationOptionCurveEaseInOut completion:completion];
364 367
 }
365 368
 
366 369
 -(void)openDrawerSide:(MMDrawerSide)drawerSide animated:(BOOL)animated velocity:(CGFloat)velocity animationOptions:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion{
@@ -1250,11 +1253,25 @@ static NSString *MMDrawerOpenSideKey = @"MMDrawerOpenSide";
1250 1253
     if(self.drawerVisualState){
1251 1254
         self.drawerVisualState(self,drawerSide,percentVisible);
1252 1255
     }
1253
-    else if(self.shouldStretchDrawer){
1256
+    else if([self shouldStretchForSide:drawerSide]){
1254 1257
         [self applyOvershootScaleTransformForDrawerSide:drawerSide percentVisible:percentVisible];
1255 1258
     }
1256 1259
 }
1257 1260
 
1261
+- (BOOL)shouldStretchForSide:(MMDrawerSide)drawerSide {
1262
+	switch (drawerSide) {
1263
+		case MMDrawerSideLeft:
1264
+			return self.shouldStretchLeftDrawer;
1265
+			break;
1266
+		case MMDrawerSideRight:
1267
+			return self.shouldStretchRightDrawer;
1268
+			break;
1269
+		default:
1270
+			return YES;
1271
+			break;
1272
+	}
1273
+}
1274
+
1258 1275
 - (void)applyOvershootScaleTransformForDrawerSide:(MMDrawerSide)drawerSide percentVisible:(CGFloat)percentVisible{
1259 1276
     
1260 1277
     if (percentVisible >= 1.f) {
@@ -1283,7 +1300,7 @@ static NSString *MMDrawerOpenSideKey = @"MMDrawerOpenSide";
1283 1300
 -(CGFloat)roundedOriginXForDrawerConstriants:(CGFloat)originX{
1284 1301
     
1285 1302
     if (originX < -self.maximumRightDrawerWidth) {
1286
-        if (self.shouldStretchDrawer &&
1303
+        if (self.shouldStretchRightDrawer &&
1287 1304
             self.rightDrawerViewController) {
1288 1305
             CGFloat maxOvershoot = (CGRectGetWidth(self.centerContainerView.frame)-self.maximumRightDrawerWidth)*MMDrawerOvershootPercentage;
1289 1306
             return originXForDrawerOriginAndTargetOriginOffset(originX, -self.maximumRightDrawerWidth, maxOvershoot);
@@ -1293,7 +1310,7 @@ static NSString *MMDrawerOpenSideKey = @"MMDrawerOpenSide";
1293 1310
         }
1294 1311
     }
1295 1312
     else if(originX > self.maximumLeftDrawerWidth){
1296
-        if (self.shouldStretchDrawer &&
1313
+        if (self.shouldStretchLeftDrawer &&
1297 1314
             self.leftDrawerViewController) {
1298 1315
             CGFloat maxOvershoot = (CGRectGetWidth(self.centerContainerView.frame)-self.maximumLeftDrawerWidth)*MMDrawerOvershootPercentage;
1299 1316
             return originXForDrawerOriginAndTargetOriginOffset(originX, self.maximumLeftDrawerWidth, maxOvershoot);
@@ -1387,7 +1404,8 @@ static inline CGFloat originXForDrawerOriginAndTargetOriginOffset(CGFloat origin
1387 1404
 }
1388 1405
 
1389 1406
 -(NSTimeInterval)animationDurationForAnimationDistance:(CGFloat)distance{
1390
-    NSTimeInterval duration = MAX(distance/self.animationVelocity,MMDrawerMinimumAnimationDuration);
1407
+	CGFloat velocity = self.openSide == MMDrawerSideLeft ? self.animationVelocityLeft : self.animationVelocityRight;
1408
+    NSTimeInterval duration = MAX(distance/velocity,MMDrawerMinimumAnimationDuration);
1391 1409
     return duration;
1392 1410
 }
1393 1411
 

+ 0
- 5
lib/ios/RNNSideMenuController.m Прегледај датотеку

@@ -40,11 +40,6 @@
40 40
 	}
41 41
 }
42 42
 
43
-- (void)viewWillAppear:(BOOL)animated {
44
-	[super viewWillAppear:animated];
45
-	[_presenter applyOptions:self.options];
46
-}
47
-
48 43
 - (UITabBarItem *)tabBarItem {
49 44
 	return self.center.tabBarItem;
50 45
 }

+ 0
- 3
lib/ios/RNNSideMenuOptions.h Прегледај датотеку

@@ -6,7 +6,4 @@
6 6
 @property (nonatomic, strong) RNNSideMenuSideOptions* left;
7 7
 @property (nonatomic, strong) RNNSideMenuSideOptions* right;
8 8
 
9
-@property (nonatomic, strong) Bool* shouldStretchDrawer;
10
-@property (nonatomic, strong) Double* animationVelocity;
11
-
12 9
 @end

+ 0
- 2
lib/ios/RNNSideMenuOptions.m Прегледај датотеку

@@ -8,8 +8,6 @@
8 8
 	
9 9
 	self.left = [[RNNSideMenuSideOptions alloc] initWithDict:dict[@"left"]];
10 10
 	self.right = [[RNNSideMenuSideOptions alloc] initWithDict:dict[@"right"]];
11
-	self.shouldStretchDrawer = [BoolParser parse:dict key:@"shouldStretchDrawer"];
12
-	self.animationVelocity = [DoubleParser parse:dict key:@"animationVelocity"];
13 11
 	
14 12
 	return self;
15 13
 }

+ 17
- 6
lib/ios/RNNSideMenuPresenter.m Прегледај датотеку

@@ -13,8 +13,11 @@
13 13
 	[sideMenuController side:MMDrawerSideLeft enabled:[options.sideMenu.left.enabled getWithDefaultValue:YES]];
14 14
 	[sideMenuController side:MMDrawerSideRight enabled:[options.sideMenu.right.enabled getWithDefaultValue:YES]];
15 15
 	
16
-	[sideMenuController setShouldStretchDrawer:[options.sideMenu.shouldStretchDrawer getWithDefaultValue:YES]];
17
-	[sideMenuController setAnimationVelocity:[options.sideMenu.animationVelocity getWithDefaultValue:840.0f]];
16
+	[sideMenuController setShouldStretchLeftDrawer:[options.sideMenu.left.shouldStretchDrawer getWithDefaultValue:YES]];
17
+	[sideMenuController setShouldStretchRightDrawer:[options.sideMenu.right.shouldStretchDrawer getWithDefaultValue:YES]];
18
+	
19
+	[sideMenuController setAnimationVelocityLeft:[options.sideMenu.left.animationVelocity getWithDefaultValue:840.0f]];
20
+	[sideMenuController setAnimationVelocityRight:[options.sideMenu.right.animationVelocity getWithDefaultValue:840.0f]];
18 21
 	
19 22
 	if (options.sideMenu.left.width.hasValue) {
20 23
 		[sideMenuController side:MMDrawerSideLeft width:options.sideMenu.left.width.get];
@@ -58,12 +61,20 @@
58 61
 		[sideMenuController side:MMDrawerSideRight width:options.sideMenu.right.width.get];
59 62
 	}
60 63
 	
61
-	if (options.sideMenu.shouldStretchDrawer.hasValue) {
62
-		sideMenuController.shouldStretchDrawer = options.sideMenu.shouldStretchDrawer.get;
64
+	if (options.sideMenu.left.shouldStretchDrawer.hasValue) {
65
+		sideMenuController.shouldStretchLeftDrawer = options.sideMenu.left.shouldStretchDrawer.get;
66
+	}
67
+	
68
+	if (options.sideMenu.right.shouldStretchDrawer.hasValue) {
69
+		sideMenuController.shouldStretchRightDrawer = options.sideMenu.right.shouldStretchDrawer.get;
70
+	}
71
+	
72
+	if (options.sideMenu.left.animationVelocity.hasValue) {
73
+		sideMenuController.animationVelocityLeft = options.sideMenu.left.animationVelocity.get;
63 74
 	}
64 75
 	
65
-	if (options.sideMenu.animationVelocity.hasValue) {
66
-		sideMenuController.animationVelocity = options.sideMenu.animationVelocity.get;
76
+	if (options.sideMenu.right.animationVelocity.hasValue) {
77
+		sideMenuController.animationVelocityRight = options.sideMenu.right.animationVelocity.get;
67 78
 	}
68 79
 }
69 80
 

+ 2
- 0
lib/ios/RNNSideMenuSideOptions.h Прегледај датотеку

@@ -7,5 +7,7 @@
7 7
 @property (nonatomic, strong) Bool* enabled;
8 8
 @property (nonatomic, strong) Double* width;
9 9
 @property (nonatomic, strong) Text* animationType;
10
+@property (nonatomic, strong) Bool* shouldStretchDrawer;
11
+@property (nonatomic, strong) Double* animationVelocity;
10 12
 
11 13
 @end

+ 2
- 2
lib/ios/RNNSideMenuSideOptions.m Прегледај датотеку

@@ -7,10 +7,10 @@
7 7
 	
8 8
 	self.visible = [BoolParser parse:dict key:@"visible"];
9 9
 	self.enabled = [BoolParser parse:dict key:@"enabled"];
10
-	
11 10
 	self.width = [DoubleParser parse:dict key:@"width"];
12
-	
13 11
 	self.animationType = [TextParser parse:dict key:@"animationType"];
12
+	self.shouldStretchDrawer = [BoolParser parse:dict key:@"shouldStretchDrawer"];
13
+	self.animationVelocity = [DoubleParser parse:dict key:@"animationVelocity"];
14 14
 	
15 15
 	return self;
16 16
 }

+ 4
- 0
lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj Прегледај датотеку

@@ -220,6 +220,7 @@
220 220
 		50C5FD8320D7D6DD00F1EA8A /* RNNBridgeManagerDelegate.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 502CB43920CBCA140019B2FE /* RNNBridgeManagerDelegate.h */; };
221 221
 		50CB3B691FDE911400AA153B /* RNNSideMenuOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 50CB3B671FDE911400AA153B /* RNNSideMenuOptions.h */; };
222 222
 		50CB3B6A1FDE911400AA153B /* RNNSideMenuOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 50CB3B681FDE911400AA153B /* RNNSideMenuOptions.m */; };
223
+		50CE8503217C6C9B00084EBF /* RNNSideMenuPresenterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 50CE8502217C6C9B00084EBF /* RNNSideMenuPresenterTest.m */; };
223 224
 		50D031342005149000386B3D /* RNNOverlayManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 50D031322005149000386B3D /* RNNOverlayManager.h */; };
224 225
 		50D031352005149000386B3D /* RNNOverlayManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 50D031332005149000386B3D /* RNNOverlayManager.m */; };
225 226
 		50EB4ED72068EBE000D6ED34 /* RNNBackgroundOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 50EB4ED52068EBE000D6ED34 /* RNNBackgroundOptions.h */; };
@@ -537,6 +538,7 @@
537 538
 		50C4A495206BDDBB00DB292E /* RNNSubtitleOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNSubtitleOptions.m; sourceTree = "<group>"; };
538 539
 		50CB3B671FDE911400AA153B /* RNNSideMenuOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNSideMenuOptions.h; sourceTree = "<group>"; };
539 540
 		50CB3B681FDE911400AA153B /* RNNSideMenuOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNSideMenuOptions.m; sourceTree = "<group>"; };
541
+		50CE8502217C6C9B00084EBF /* RNNSideMenuPresenterTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNSideMenuPresenterTest.m; sourceTree = "<group>"; };
540 542
 		50D031322005149000386B3D /* RNNOverlayManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNOverlayManager.h; sourceTree = "<group>"; };
541 543
 		50D031332005149000386B3D /* RNNOverlayManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNOverlayManager.m; sourceTree = "<group>"; };
542 544
 		50EB4ED52068EBE000D6ED34 /* RNNBackgroundOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNBackgroundOptions.h; sourceTree = "<group>"; };
@@ -1004,6 +1006,7 @@
1004 1006
 				506F630E216A5AD700AD0D0A /* RNNViewControllerPresenterTest.m */,
1005 1007
 				509B258E2178BE7A00C83C23 /* RNNNavigationControllerPresenterTest.m */,
1006 1008
 				502F0E172179C39900367CC3 /* RNNTabBarPresenterTest.m */,
1009
+				50CE8502217C6C9B00084EBF /* RNNSideMenuPresenterTest.m */,
1007 1010
 				502F0E152178D09600367CC3 /* RNNBottomTabPresenterTest.m */,
1008 1011
 				5038A378216D01F6009280BC /* RNNBottomTabOptionsTest.m */,
1009 1012
 				7B49FEBF1E95090800DEB3EA /* Info.plist */,
@@ -1383,6 +1386,7 @@
1383 1386
 				509B258F2178BE7A00C83C23 /* RNNNavigationControllerPresenterTest.m in Sources */,
1384 1387
 				7B49FECD1E95098500DEB3EA /* RNNModalManagerTest.m in Sources */,
1385 1388
 				E83BAD791F27416B00A9F3DD /* RNNRootViewControllerTest.m in Sources */,
1389
+				50CE8503217C6C9B00084EBF /* RNNSideMenuPresenterTest.m in Sources */,
1386 1390
 				E8DA243D1F973C1900CD552B /* RNNTransitionStateHolderTest.m in Sources */,
1387 1391
 				7B49FECC1E95098500DEB3EA /* RNNStoreTest.m in Sources */,
1388 1392
 			);

+ 64
- 0
lib/ios/ReactNativeNavigationTests/RNNSideMenuPresenterTest.m Прегледај датотеку

@@ -0,0 +1,64 @@
1
+#import <XCTest/XCTest.h>
2
+#import <OCMock/OCMock.h>
3
+#import "RNNSideMenuPresenter.h"
4
+#import "RNNSideMenuController.h"
5
+
6
+@interface RNNSideMenuPresenterTest : XCTestCase
7
+
8
+@property (nonatomic, strong) RNNSideMenuPresenter *uut;
9
+@property (nonatomic, strong) RNNNavigationOptions *options;
10
+@property (nonatomic, strong) id bindedViewController;
11
+
12
+@end
13
+
14
+@implementation RNNSideMenuPresenterTest
15
+
16
+- (void)setUp {
17
+    [super setUp];
18
+	self.uut = [[RNNSideMenuPresenter alloc] init];
19
+	self.bindedViewController = [OCMockObject partialMockForObject:[RNNSideMenuController new]];
20
+	[self.uut bindViewController:self.bindedViewController];
21
+	self.options = [[RNNNavigationOptions alloc] initEmptyOptions];
22
+}
23
+
24
+- (void)testApplyOptionsShouldSetDefaultValues {
25
+	[[self.bindedViewController expect] side:MMDrawerSideLeft enabled:YES];
26
+	[[self.bindedViewController expect] side:MMDrawerSideRight enabled:YES];
27
+	[[self.bindedViewController expect] setShouldStretchLeftDrawer:YES];
28
+	[[self.bindedViewController expect] setShouldStretchRightDrawer:YES];
29
+	[[self.bindedViewController expect] setAnimationVelocityLeft:840.0f];
30
+	[[self.bindedViewController expect] setAnimationVelocityRight:840.0f];
31
+	[[self.bindedViewController reject] side:MMDrawerSideLeft width:0];
32
+	[[self.bindedViewController reject] side:MMDrawerSideRight width:0];
33
+	
34
+	[self.uut applyOptions:self.options];
35
+
36
+	[self.bindedViewController verify];
37
+}
38
+
39
+- (void)testApplyOptionsShouldSetInitialValues {
40
+	self.options.sideMenu.left.enabled = [[Bool alloc] initWithBOOL:NO];
41
+	self.options.sideMenu.right.enabled = [[Bool alloc] initWithBOOL:NO];
42
+	self.options.sideMenu.left.shouldStretchDrawer = [[Bool alloc] initWithBOOL:NO];
43
+	self.options.sideMenu.right.shouldStretchDrawer = [[Bool alloc] initWithBOOL:NO];
44
+	self.options.sideMenu.right.animationVelocity = [[Double alloc] initWithValue:@(100.0f)];
45
+	self.options.sideMenu.left.animationVelocity = [[Double alloc] initWithValue:@(100.0f)];
46
+	self.options.sideMenu.right.width = [[Double alloc] initWithValue:@(100.0f)];
47
+	self.options.sideMenu.left.width = [[Double alloc] initWithValue:@(100.0f)];
48
+	
49
+	[[self.bindedViewController expect] side:MMDrawerSideLeft enabled:NO];
50
+	[[self.bindedViewController expect] side:MMDrawerSideRight enabled:NO];
51
+	[[self.bindedViewController expect] setShouldStretchLeftDrawer:NO];
52
+	[[self.bindedViewController expect] setShouldStretchRightDrawer:NO];
53
+	[[self.bindedViewController expect] setAnimationVelocityLeft:100.0f];
54
+	[[self.bindedViewController expect] setAnimationVelocityRight:100.0f];
55
+	[[self.bindedViewController expect] side:MMDrawerSideLeft width:100.0f];
56
+	[[self.bindedViewController expect] side:MMDrawerSideRight width:100.0f];
57
+	
58
+	[self.uut applyOptions:self.options];
59
+	
60
+	[self.bindedViewController verify];
61
+}
62
+
63
+
64
+@end