Browse Source

Implement layout options

yogevbd 6 years ago
parent
commit
f822fac935

+ 10
- 0
lib/ios/RNNLayoutOptions.h View File

@@ -0,0 +1,10 @@
1
+#import "RNNOptions.h"
2
+
3
+@interface RNNLayoutOptions : RNNOptions
4
+
5
+@property (nonatomic, strong) NSNumber* screenBackgroundColor;
6
+@property (nonatomic, strong) id orientation;
7
+
8
+- (UIInterfaceOrientationMask)supportedOrientations;
9
+
10
+@end

+ 40
- 0
lib/ios/RNNLayoutOptions.m View File

@@ -0,0 +1,40 @@
1
+#import "RNNLayoutOptions.h"
2
+#import <React/RCTConvert.h>
3
+
4
+@implementation RNNLayoutOptions
5
+
6
+- (void)applyOn:(UIViewController *)viewController {
7
+	if (self.screenBackgroundColor) {
8
+		UIColor* screenColor = [RCTConvert UIColor:self.screenBackgroundColor];
9
+		viewController.view.backgroundColor = screenColor;
10
+	}
11
+}
12
+
13
+- (UIInterfaceOrientationMask)supportedOrientations {
14
+	NSArray* orientationsArray = [self.orientation isKindOfClass:[NSString class]] ? @[self.orientation] : self.orientation;
15
+	NSUInteger supportedOrientationsMask = 0;
16
+	if (!orientationsArray || [self.orientation isEqual:@"default"]) {
17
+		return [[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:[[UIApplication sharedApplication] keyWindow]];
18
+	} else {
19
+		for (NSString* orientation in orientationsArray) {
20
+			if ([orientation isEqualToString:@"all"]) {
21
+				supportedOrientationsMask = UIInterfaceOrientationMaskAll;
22
+				break;
23
+			}
24
+			if ([orientation isEqualToString:@"landscape"]) {
25
+				supportedOrientationsMask = (supportedOrientationsMask | UIInterfaceOrientationMaskLandscape);
26
+			}
27
+			if ([orientation isEqualToString:@"portrait"]) {
28
+				supportedOrientationsMask = (supportedOrientationsMask | UIInterfaceOrientationMaskPortrait);
29
+			}
30
+			if ([orientation isEqualToString:@"upsideDown"]) {
31
+				supportedOrientationsMask = (supportedOrientationsMask | UIInterfaceOrientationMaskPortraitUpsideDown);
32
+			}
33
+		}
34
+	}
35
+	
36
+	return supportedOrientationsMask;
37
+}
38
+
39
+
40
+@end

+ 2
- 5
lib/ios/RNNNavigationOptions.h View File

@@ -9,6 +9,7 @@
9 9
 #import "RNNAnimationOptions.h"
10 10
 #import "RNNTransitionsOptions.h"
11 11
 #import "RNNStatusBarOptions.h"
12
+#import "RNNLayoutOptions.h"
12 13
 
13 14
 extern const NSInteger BLUR_TOPBAR_TAG;
14 15
 extern const NSInteger TOP_BAR_TRANSPARENT_TAG;
@@ -25,20 +26,16 @@ extern const NSInteger TOP_BAR_TRANSPARENT_TAG;
25 26
 @property (nonatomic, strong) RNNAnimationOptions* customTransition;
26 27
 @property (nonatomic, strong) RNNTransitionsOptions* animations;
27 28
 @property (nonatomic, strong) RNNStatusBarOptions* statusBar;
29
+@property (nonatomic, strong) RNNLayoutOptions* layout;
28 30
 
29
-
30
-@property (nonatomic, strong) NSNumber* screenBackgroundColor;
31 31
 @property (nonatomic, strong) NSMutableDictionary* originalTopBarImages;
32 32
 @property (nonatomic, strong) NSString* backButtonTransition;
33
-@property (nonatomic, strong) id orientation;
34 33
 @property (nonatomic, strong) NSNumber* popGesture;
35 34
 @property (nonatomic, strong) NSDictionary* backgroundImage;
36 35
 @property (nonatomic, strong) NSDictionary* rootBackgroundImage;
37 36
 @property (nonatomic, strong) NSString* modalPresentationStyle;
38 37
 @property (nonatomic, strong) NSString* modalTransitionStyle;
39 38
 
40
-- (UIInterfaceOrientationMask)supportedOrientations;
41
-
42 39
 - (void)applyModalOptions:(UIViewController*)viewController;
43 40
 
44 41
 @end

+ 1
- 31
lib/ios/RNNNavigationOptions.m View File

@@ -50,7 +50,7 @@ RCT_ENUM_CONVERTER(UIModalTransitionStyle,
50 50
 	[self.sideMenu applyOn:viewController];
51 51
 	[self.overlay applyOn:viewController];
52 52
 	[self.statusBar applyOn:viewController];
53
-	
53
+	[self.layout applyOn:viewController];
54 54
 	[self applyOtherOptionsOn:viewController];
55 55
 	
56 56
 	[viewController optionsUpdated];
@@ -61,11 +61,6 @@ RCT_ENUM_CONVERTER(UIModalTransitionStyle,
61 61
 		viewController.navigationController.interactivePopGestureRecognizer.enabled = [self.popGesture boolValue];
62 62
 	}
63 63
 	
64
-	if (self.screenBackgroundColor) {
65
-		UIColor* screenColor = [RCTConvert UIColor:self.screenBackgroundColor];
66
-		viewController.view.backgroundColor = screenColor;
67
-	}
68
-	
69 64
 	if (self.backgroundImage) {
70 65
 		UIImageView* backgroundImageView = (viewController.view.subviews.count > 0) ? viewController.view.subviews[0] : nil;
71 66
 		if (![backgroundImageView isKindOfClass:[UIImageView class]]) {
@@ -102,30 +97,5 @@ RCT_ENUM_CONVERTER(UIModalTransitionStyle,
102 97
     }
103 98
 }
104 99
 
105
-- (UIInterfaceOrientationMask)supportedOrientations {
106
-	NSArray* orientationsArray = [self.orientation isKindOfClass:[NSString class]] ? @[self.orientation] : self.orientation;
107
-	NSUInteger supportedOrientationsMask = 0;
108
-	if (!orientationsArray || [self.orientation isEqual:@"default"]) {
109
-		return [[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:[[UIApplication sharedApplication] keyWindow]];
110
-	} else {
111
-		for (NSString* orientation in orientationsArray) {
112
-			if ([orientation isEqualToString:@"all"]) {
113
-				supportedOrientationsMask = UIInterfaceOrientationMaskAll;
114
-				break;
115
-			}
116
-			if ([orientation isEqualToString:@"landscape"]) {
117
-				supportedOrientationsMask = (supportedOrientationsMask | UIInterfaceOrientationMaskLandscape);
118
-			}
119
-			if ([orientation isEqualToString:@"portrait"]) {
120
-				supportedOrientationsMask = (supportedOrientationsMask | UIInterfaceOrientationMaskPortrait);
121
-			}
122
-			if ([orientation isEqualToString:@"upsideDown"]) {
123
-				supportedOrientationsMask = (supportedOrientationsMask | UIInterfaceOrientationMaskPortraitUpsideDown);
124
-			}
125
-		}
126
-	}
127
-	
128
-	return supportedOrientationsMask;
129
-}
130 100
 
131 101
 @end

+ 2
- 1
lib/ios/RNNRootViewController.m View File

@@ -163,6 +163,7 @@
163 163
 	} else if ([self.options.statusBar.hideWithTopBar boolValue]) {
164 164
 		return self.navigationController.isNavigationBarHidden;
165 165
 	}
166
+
166 167
 	return NO;
167 168
 }
168 169
 
@@ -175,7 +176,7 @@
175 176
 }
176 177
 
177 178
 - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
178
-	return self.options.supportedOrientations;
179
+	return self.options.layout.supportedOrientations;
179 180
 }
180 181
 
181 182
 - (BOOL)hidesBottomBarWhenPushed

+ 8
- 0
lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj View File

@@ -73,6 +73,8 @@
73 73
 		50451D0A2042E20600695F00 /* RNNTransitionsOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 50451D082042E20600695F00 /* RNNTransitionsOptions.m */; };
74 74
 		50451D0D2042F70900695F00 /* RNNTransition.h in Headers */ = {isa = PBXBuildFile; fileRef = 50451D0B2042F70900695F00 /* RNNTransition.h */; };
75 75
 		50451D0E2042F70900695F00 /* RNNTransition.m in Sources */ = {isa = PBXBuildFile; fileRef = 50451D0C2042F70900695F00 /* RNNTransition.m */; };
76
+		5048862D20BE976D000908DE /* RNNLayoutOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 5048862B20BE976D000908DE /* RNNLayoutOptions.h */; };
77
+		5048862E20BE976D000908DE /* RNNLayoutOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 5048862C20BE976D000908DE /* RNNLayoutOptions.m */; };
76 78
 		504AFE641FFE53070076E904 /* RNNOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 504AFE621FFE53070076E904 /* RNNOptions.h */; };
77 79
 		504AFE651FFE53070076E904 /* RNNOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 504AFE631FFE53070076E904 /* RNNOptions.m */; };
78 80
 		504AFE741FFFF0540076E904 /* RNNTopTabsOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 504AFE721FFFF0540076E904 /* RNNTopTabsOptions.h */; };
@@ -276,6 +278,8 @@
276 278
 		50451D082042E20600695F00 /* RNNTransitionsOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNTransitionsOptions.m; sourceTree = "<group>"; };
277 279
 		50451D0B2042F70900695F00 /* RNNTransition.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNTransition.h; sourceTree = "<group>"; };
278 280
 		50451D0C2042F70900695F00 /* RNNTransition.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNTransition.m; sourceTree = "<group>"; };
281
+		5048862B20BE976D000908DE /* RNNLayoutOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNLayoutOptions.h; sourceTree = "<group>"; };
282
+		5048862C20BE976D000908DE /* RNNLayoutOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNLayoutOptions.m; sourceTree = "<group>"; };
279 283
 		504AFE621FFE53070076E904 /* RNNOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNOptions.h; sourceTree = "<group>"; };
280 284
 		504AFE631FFE53070076E904 /* RNNOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNOptions.m; sourceTree = "<group>"; };
281 285
 		504AFE721FFFF0540076E904 /* RNNTopTabsOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNTopTabsOptions.h; sourceTree = "<group>"; };
@@ -525,6 +529,8 @@
525 529
 				50570B252061473D006A1B5C /* RNNTitleOptions.m */,
526 530
 				50C4A494206BDDBB00DB292E /* RNNSubtitleOptions.h */,
527 531
 				50C4A495206BDDBB00DB292E /* RNNSubtitleOptions.m */,
532
+				5048862B20BE976D000908DE /* RNNLayoutOptions.h */,
533
+				5048862C20BE976D000908DE /* RNNLayoutOptions.m */,
528 534
 				50BE951120B5A787004F5DF5 /* RNNStatusBarOptions.h */,
529 535
 				50BE951020B5A787004F5DF5 /* RNNStatusBarOptions.m */,
530 536
 				50EB4ED52068EBE000D6ED34 /* RNNBackgroundOptions.h */,
@@ -816,6 +822,7 @@
816 822
 				263905B91E4C6F440023D7D3 /* RCCDrawerController.h in Headers */,
817 823
 				263905B31E4C6F440023D7D3 /* MMDrawerVisualState.h in Headers */,
818 824
 				50451D092042E20600695F00 /* RNNTransitionsOptions.h in Headers */,
825
+				5048862D20BE976D000908DE /* RNNLayoutOptions.h in Headers */,
819 826
 				E8A5CD621F49114F00E89D0D /* RNNElement.h in Headers */,
820 827
 				50570B262061473D006A1B5C /* RNNTitleOptions.h in Headers */,
821 828
 				504AFE741FFFF0540076E904 /* RNNTopTabsOptions.h in Headers */,
@@ -946,6 +953,7 @@
946 953
 				263905B41E4C6F440023D7D3 /* MMDrawerVisualState.m in Sources */,
947 954
 				263905C51E4C6F440023D7D3 /* SidebarFacebookAnimation.m in Sources */,
948 955
 				50451D0E2042F70900695F00 /* RNNTransition.m in Sources */,
956
+				5048862E20BE976D000908DE /* RNNLayoutOptions.m in Sources */,
949 957
 				7BEF0D191E437684003E96B0 /* RNNRootViewController.m in Sources */,
950 958
 				50415CBB20553B8E00BB682E /* RNNScreenTransition.m in Sources */,
951 959
 				263905C31E4C6F440023D7D3 /* SidebarAnimation.m in Sources */,

+ 9
- 9
lib/ios/ReactNativeNavigationTests/RNNRootViewControllerTest.m View File

@@ -131,7 +131,7 @@
131 131
 
132 132
 -(void)testScreenBackgroundColor_validColor{
133 133
 	NSNumber* inputColor = @(0xFFFF0000);
134
-	self.options.screenBackgroundColor = inputColor;
134
+	self.options.layout.screenBackgroundColor = inputColor;
135 135
 	[self.uut viewWillAppear:false];
136 136
 	UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
137 137
 	XCTAssertTrue([self.uut.view.backgroundColor isEqual:expectedColor]);
@@ -283,7 +283,7 @@
283 283
 
284 284
 -(void)testOrientation_portrait {
285 285
 	NSArray* supportedOrientations = @[@"portrait"];
286
-	self.options.orientation = supportedOrientations;
286
+	self.options.layout.orientation = supportedOrientations;
287 287
 	__unused UINavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
288 288
 	[self.uut viewWillAppear:false];
289 289
 	UIInterfaceOrientationMask expectedOrientation = UIInterfaceOrientationMaskPortrait;
@@ -292,7 +292,7 @@
292 292
 
293 293
 -(void)testOrientation_portraitString {
294 294
 	NSString* supportedOrientation = @"portrait";
295
-	self.options.orientation = supportedOrientation;
295
+	self.options.layout.orientation = supportedOrientation;
296 296
 	__unused UINavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
297 297
 	[self.uut viewWillAppear:false];
298 298
 	UIInterfaceOrientationMask expectedOrientation = (UIInterfaceOrientationMaskPortrait);
@@ -301,7 +301,7 @@
301 301
 
302 302
 -(void)testOrientation_portraitAndLandscape {
303 303
 	NSArray* supportedOrientations = @[@"portrait", @"landscape"];
304
-	self.options.orientation = supportedOrientations;
304
+	self.options.layout.orientation = supportedOrientations;
305 305
 	__unused UINavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
306 306
 	[self.uut viewWillAppear:false];
307 307
 	UIInterfaceOrientationMask expectedOrientation = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape);
@@ -310,7 +310,7 @@
310 310
 
311 311
 -(void)testOrientation_all {
312 312
 	NSArray* supportedOrientations = @[@"all"];
313
-	self.options.orientation = supportedOrientations;
313
+	self.options.layout.orientation = supportedOrientations;
314 314
 	__unused UINavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
315 315
 	[self.uut viewWillAppear:false];
316 316
 	UIInterfaceOrientationMask expectedOrientation = UIInterfaceOrientationMaskAll;
@@ -319,7 +319,7 @@
319 319
 
320 320
 -(void)testOrientation_default {
321 321
 	NSString* supportedOrientations = @"default";
322
-	self.options.orientation = supportedOrientations;
322
+	self.options.layout.orientation = supportedOrientations;
323 323
 	__unused UINavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
324 324
 	[self.uut viewWillAppear:false];
325 325
 	UIInterfaceOrientationMask expectedOrientation = [[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:[[UIApplication sharedApplication] keyWindow]];
@@ -329,7 +329,7 @@
329 329
 
330 330
 -(void)testOrientationTabsController_portrait {
331 331
 	NSArray* supportedOrientations = @[@"portrait"];
332
-	self.options.orientation = supportedOrientations;
332
+	self.options.layout.orientation = supportedOrientations;
333 333
 	__unused RNNTabBarController* vc = [[RNNTabBarController alloc] init];
334 334
 	NSMutableArray* controllers = [NSMutableArray new];
335 335
 	
@@ -343,7 +343,7 @@
343 343
 
344 344
 -(void)testOrientationTabsController_portraitAndLandscape {
345 345
 	NSArray* supportedOrientations = @[@"portrait", @"landscape"];
346
-	self.options.orientation = supportedOrientations;
346
+	self.options.layout.orientation = supportedOrientations;
347 347
 	__unused RNNTabBarController* vc = [[RNNTabBarController alloc] init];
348 348
 	NSMutableArray* controllers = [NSMutableArray new];
349 349
 	
@@ -357,7 +357,7 @@
357 357
 
358 358
 -(void)testOrientationTabsController_all {
359 359
 	NSArray* supportedOrientations = @[@"all"];
360
-	self.options.orientation = supportedOrientations;
360
+	self.options.layout.orientation = supportedOrientations;
361 361
 	__unused RNNTabBarController* vc = [[RNNTabBarController alloc] init];
362 362
 	NSMutableArray* controllers = [NSMutableArray new];
363 363