Browse Source

Fix top bar layout frame (#5008)

* Fix top bar layout frame, Closes #5003

* Set layout child view controllers on initialization

* Remove duplicate initWithLayoutInfo: function
Yogev Ben David 5 years ago
parent
commit
be00c4c36d
No account linked to committer's email address

+ 0
- 7
lib/ios/RNNBasePresenter.m View File

@@ -5,18 +5,11 @@
5 5
 #import "UIViewController+LayoutProtocol.h"
6 6
 
7 7
 @interface RNNBasePresenter ()
8
-@property (nonatomic, strong) RNNReactComponentRegistry* componentRegistry;
9 8
 @end
10 9
 
11 10
 
12 11
 @implementation RNNBasePresenter
13 12
 
14
-- (instancetype)initWithComponentRegistry:(RNNReactComponentRegistry *)componentRegistry {
15
-	self = [super init];
16
-	self.componentRegistry = componentRegistry;
17
-	return self;
18
-}
19
-
20 13
 - (void)bindViewController:(UIViewController<RNNLayoutProtocol> *)bindedViewController {
21 14
 	self.bindedComponentId = bindedViewController.layoutInfo.componentId;
22 15
 	_bindedViewController = bindedViewController;

+ 5
- 9
lib/ios/RNNControllerFactory.m View File

@@ -141,8 +141,7 @@
141 141
 	
142 142
 	NSArray *childViewControllers = [self extractChildrenViewControllersFromNode:node];
143 143
 	
144
-	RNNNavigationController* stack = [[RNNNavigationController alloc] initWithLayoutInfo:layoutInfo creator:_creator options:options defaultOptions:_defaultOptions presenter:presenter eventEmitter:_eventEmitter];
145
-	[stack setViewControllers:childViewControllers];
144
+	RNNNavigationController* stack = [[RNNNavigationController alloc] initWithLayoutInfo:layoutInfo creator:_creator options:options defaultOptions:_defaultOptions presenter:presenter eventEmitter:_eventEmitter childViewControllers:childViewControllers];
146 145
 	
147 146
 	return stack;
148 147
 }
@@ -154,8 +153,7 @@
154 153
 
155 154
 	NSArray *childViewControllers = [self extractChildrenViewControllersFromNode:node];
156 155
 	
157
-	RNNTabBarController* tabsController = [[RNNTabBarController alloc] initWithLayoutInfo:layoutInfo creator:_creator options:options defaultOptions:_defaultOptions presenter:presenter eventEmitter:_eventEmitter];
158
-	[tabsController setViewControllers:childViewControllers];
156
+	RNNTabBarController* tabsController = [[RNNTabBarController alloc] initWithLayoutInfo:layoutInfo creator:_creator options:options defaultOptions:_defaultOptions presenter:presenter eventEmitter:_eventEmitter childViewControllers:childViewControllers];
159 157
 	
160 158
 	return tabsController;
161 159
 }
@@ -167,8 +165,7 @@
167 165
 
168 166
 	NSArray *childViewControllers = [self extractChildrenViewControllersFromNode:node];
169 167
 	
170
-	RNNTopTabsViewController* topTabsController = [[RNNTopTabsViewController alloc] initWithLayoutInfo:layoutInfo creator:_creator options:options defaultOptions:_defaultOptions presenter:presenter eventEmitter:_eventEmitter];
171
-	[topTabsController setViewControllers:childViewControllers];
168
+	RNNTopTabsViewController* topTabsController = [[RNNTopTabsViewController alloc] initWithLayoutInfo:layoutInfo creator:_creator options:options defaultOptions:_defaultOptions presenter:presenter eventEmitter:_eventEmitter childViewControllers:childViewControllers];
172 169
 	
173 170
 	return topTabsController;
174 171
 }
@@ -191,7 +188,7 @@
191 188
 	RNNLayoutInfo* layoutInfo = [[RNNLayoutInfo alloc] initWithNode:node];
192 189
 	RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:node.data[@"options"]];;
193 190
 
194
-	RNNSideMenuChildVC *sideMenuChild = [[RNNSideMenuChildVC alloc] initWithLayoutInfo:layoutInfo childViewControllers:@[childVc] options:options defaultOptions:_defaultOptions presenter:[[RNNViewControllerPresenter alloc] init] type:type];
191
+	RNNSideMenuChildVC *sideMenuChild = [[RNNSideMenuChildVC alloc] initWithLayoutInfo:layoutInfo creator:_creator options:options defaultOptions:_defaultOptions presenter:[[RNNViewControllerPresenter alloc] init] eventEmitter:_eventEmitter childViewController:childVc type:type];
195 192
 	
196 193
 	return sideMenuChild;
197 194
 }
@@ -203,8 +200,7 @@
203 200
 
204 201
 	NSArray *childViewControllers = [self extractChildrenViewControllersFromNode:node];
205 202
 
206
-	RNNSplitViewController* splitViewController = [[RNNSplitViewController alloc] initWithLayoutInfo:layoutInfo creator:_creator options:options defaultOptions:_defaultOptions presenter:presenter eventEmitter:_eventEmitter];
207
-	[splitViewController bindChildViewControllers:childViewControllers];
203
+	RNNSplitViewController* splitViewController = [[RNNSplitViewController alloc] initWithLayoutInfo:layoutInfo creator:_creator options:options defaultOptions:_defaultOptions presenter:presenter eventEmitter:_eventEmitter childViewControllers:childViewControllers];
208 204
 	
209 205
 	return splitViewController;
210 206
 }

+ 2
- 1
lib/ios/RNNLayoutProtocol.h View File

@@ -14,7 +14,8 @@ typedef void (^RNNReactViewReadyCompletionBlock)(void);
14 14
 						   options:(RNNNavigationOptions *)options
15 15
 					defaultOptions:(RNNNavigationOptions *)defaultOptions
16 16
 						 presenter:(RNNBasePresenter *)presenter
17
-					  eventEmitter:(RNNEventEmitter *)eventEmitter;
17
+					  eventEmitter:(RNNEventEmitter *)eventEmitter
18
+			  childViewControllers:(NSArray *)childViewControllers;
18 19
 
19 20
 - (void)renderTreeAndWait:(BOOL)wait perform:(RNNReactViewReadyCompletionBlock)readyBlock;
20 21
 

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

@@ -11,7 +11,7 @@
11 11
 @synthesize previewCallback;
12 12
 
13 13
 - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo rootViewCreator:(id<RNNRootViewCreator>)creator eventEmitter:(RNNEventEmitter *)eventEmitter presenter:(RNNViewControllerPresenter *)presenter options:(RNNNavigationOptions *)options defaultOptions:(RNNNavigationOptions *)defaultOptions {
14
-	self = [super initWithLayoutInfo:layoutInfo creator:creator options:options defaultOptions:defaultOptions presenter:presenter eventEmitter:eventEmitter];
14
+	self = [super initWithLayoutInfo:layoutInfo creator:creator options:options defaultOptions:defaultOptions presenter:presenter eventEmitter:eventEmitter childViewControllers:nil];
15 15
 	
16 16
 	self.animator = [[RNNAnimator alloc] initWithTransitionOptions:self.resolveOptions.customTransition];
17 17
 	

+ 2
- 2
lib/ios/RNNSideMenuChildVC.h View File

@@ -11,12 +11,12 @@ typedef NS_ENUM(NSInteger, RNNSideMenuChildType) {
11 11
 
12 12
 @interface RNNSideMenuChildVC : UIViewController <RNNLayoutProtocol>
13 13
 
14
+- (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo creator:(id<RNNRootViewCreator>)creator options:(RNNNavigationOptions *)options defaultOptions:(RNNNavigationOptions *)defaultOptions presenter:(RNNBasePresenter *)presenter eventEmitter:(RNNEventEmitter *)eventEmitter childViewController:(UIViewController *)childViewController type:(RNNSideMenuChildType)type;
15
+
14 16
 @property (readonly) RNNSideMenuChildType type;
15 17
 @property (readonly) UIViewController<RNNLayoutProtocol> *child;
16 18
 
17 19
 
18
-- (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo childViewControllers:(NSArray *)childViewControllers options:(RNNNavigationOptions *)options defaultOptions:(RNNNavigationOptions *)defaultOptions presenter:(RNNViewControllerPresenter *)presenter type:(RNNSideMenuChildType)type;
19
-
20 20
 - (void)setWidth:(CGFloat)width;
21 21
 
22 22
 @end

+ 6
- 23
lib/ios/RNNSideMenuChildVC.m View File

@@ -9,28 +9,11 @@
9 9
 
10 10
 @implementation RNNSideMenuChildVC
11 11
 
12
-- (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo childViewControllers:(NSArray *)childViewControllers options:(RNNNavigationOptions *)options defaultOptions:(RNNNavigationOptions *)defaultOptions presenter:(RNNViewControllerPresenter *)presenter type:(RNNSideMenuChildType)type {
13
-	self = [self initWithLayoutInfo:layoutInfo childViewControllers:childViewControllers options:options defaultOptions:defaultOptions presenter:presenter];
14
-	
15
-	self.type = type;
16
-
17
-	return self;
18
-}
19
-
20
-- (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo childViewControllers:(NSArray *)childViewControllers options:(RNNNavigationOptions *)options defaultOptions:(RNNNavigationOptions *)defaultOptions presenter:(RNNViewControllerPresenter *)presenter {
21
-	self = [super init];
22
-	
23
-	self.child = childViewControllers[0];
24
-	
25
-	self.presenter = presenter;
26
-	[self.presenter bindViewController:self];
27
-	
28
-	self.defaultOptions = defaultOptions;
29
-	self.options = options;
30
-	self.layoutInfo = layoutInfo;
31
-	
32
-	[self bindChildViewController:self.child];
33 12
 
13
+- (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo creator:(id<RNNRootViewCreator>)creator options:(RNNNavigationOptions *)options defaultOptions:(RNNNavigationOptions *)defaultOptions presenter:(RNNBasePresenter *)presenter eventEmitter:(RNNEventEmitter *)eventEmitter childViewController:(UIViewController *)childViewController type:(RNNSideMenuChildType)type {
14
+	self = [super initWithLayoutInfo:layoutInfo creator:creator options:options defaultOptions:defaultOptions presenter:presenter eventEmitter:eventEmitter childViewControllers:nil];
15
+	self.type = type;
16
+	self.child = childViewController;
34 17
 	return self;
35 18
 }
36 19
 
@@ -38,8 +21,8 @@
38 21
 	[self.getCurrentChild renderTreeAndWait:wait perform:readyBlock];
39 22
 }
40 23
 
41
-- (void)bindChildViewController:(UIViewController<RNNLayoutProtocol>*)child {
42
-	self.child = child;
24
+- (void)setChild:(UIViewController<RNNLayoutProtocol> *)child {
25
+	_child = child;
43 26
 	[self addChildViewController:self.child];
44 27
 	[self.child.view setFrame:self.view.bounds];
45 28
 	[self.view addSubview:self.child.view];

+ 0
- 15
lib/ios/RNNTopTabsViewController.m View File

@@ -14,21 +14,6 @@
14 14
 
15 15
 @implementation RNNTopTabsViewController
16 16
 
17
-- (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo childViewControllers:(NSArray *)childViewControllers options:(RNNNavigationOptions *)options defaultOptions:(RNNNavigationOptions *)defaultOptions presenter:(RNNViewControllerPresenter *)presenter {
18
-	self = [self init];
19
-	
20
-	self.presenter = presenter;
21
-	[self.presenter bindViewController:self];
22
-	
23
-	self.defaultOptions = defaultOptions;
24
-	self.options = options;
25
-	self.layoutInfo = layoutInfo;
26
-	
27
-	[self setViewControllers:childViewControllers];
28
-	
29
-	return self;
30
-}
31
-
32 17
 - (instancetype)init {
33 18
 	self = [super init];
34 19
 	

+ 1
- 0
lib/ios/RNNViewControllerPresenter.m View File

@@ -173,6 +173,7 @@
173 173
 		BOOL isCenter = [alignment isEqualToString:@"center"];
174 174
 		__weak RNNReactView *weakTitleView = _customTitleView;
175 175
 		CGRect frame = viewController.navigationController.navigationBar.bounds;
176
+		[_customTitleView setFrame:frame];
176 177
 		[_customTitleView setRootViewDidChangeIntrinsicSize:^(CGSize intrinsicContentSize) {
177 178
 			if (isCenter) {
178 179
 				[weakTitleView setFrame:CGRectMake(0, 0, intrinsicContentSize.width, intrinsicContentSize.height)];

+ 1
- 2
lib/ios/ReactNativeNavigationTests/RNNCommandsHandlerTest.m View File

@@ -122,8 +122,7 @@
122 122
 	RNNViewControllerPresenter* presenter = [[RNNViewControllerPresenter alloc] init];
123 123
 	RNNRootViewController* vc = [[RNNRootViewController alloc] initWithLayoutInfo:layoutInfo rootViewCreator:creator eventEmitter:nil presenter:presenter options:initialOptions defaultOptions:nil];
124 124
 
125
-	RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:creator options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:[[RNNNavigationControllerPresenter alloc] init] eventEmitter:nil];
126
-	[nav setViewControllers:@[vc]];
125
+	RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:creator options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:[[RNNNavigationControllerPresenter alloc] init] eventEmitter:nil childViewControllers:@[vc]];
127 126
 	
128 127
 	[vc viewWillAppear:false];
129 128
 	XCTAssertTrue([vc.navigationItem.title isEqual:@"the title"]);

+ 3
- 6
lib/ios/ReactNativeNavigationTests/RNNNavigationControllerTest.m View File

@@ -27,8 +27,7 @@
27 27
 	_vc2Mock = [OCMockObject partialMockForObject:_vc2];
28 28
 	_vc3 = [UIViewController new];
29 29
 	_options = [OCMockObject partialMockForObject:[[RNNNavigationOptions alloc] initEmptyOptions]];
30
-	self.uut = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator options:_options defaultOptions:nil presenter:[OCMockObject partialMockForObject:[[RNNNavigationControllerPresenter alloc] init]] eventEmitter:nil];
31
-	[self.uut setViewControllers:@[_vc1, _vc2]];
30
+	self.uut = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator options:_options defaultOptions:nil presenter:[OCMockObject partialMockForObject:[[RNNNavigationControllerPresenter alloc] init]] eventEmitter:nil childViewControllers:@[_vc1, _vc2]];
32 31
 }
33 32
 
34 33
 - (void)testInitWithLayoutInfo_shouldBindPresenter {
@@ -36,8 +35,7 @@
36 35
 }
37 36
 
38 37
 - (void)testInitWithLayoutInfo_shouldSetMultipleViewControllers {
39
-	self.uut = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator options:[[RNNNavigationOptions alloc] initWithDict:@{}] defaultOptions:nil presenter:[[RNNViewControllerPresenter alloc] init] eventEmitter:nil];
40
-	[self.uut setViewControllers:@[_vc1, _vc2]];
38
+	self.uut = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator options:[[RNNNavigationOptions alloc] initWithDict:@{}] defaultOptions:nil presenter:[[RNNViewControllerPresenter alloc] init] eventEmitter:nil childViewControllers:@[_vc1, _vc2]];
41 39
 	XCTAssertTrue(self.uut.viewControllers.count == 2);
42 40
 }
43 41
 
@@ -155,8 +153,7 @@
155 153
 }
156 154
 
157 155
 - (RNNNavigationController *)createNavigationControllerWithOptions:(RNNNavigationOptions *)options {
158
-	RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator options:options defaultOptions:nil presenter:[[RNNNavigationControllerPresenter alloc] init] eventEmitter:nil];
159
-	[nav setViewControllers:@[_vc1]];
156
+	RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator options:options defaultOptions:nil presenter:[[RNNNavigationControllerPresenter alloc] init] eventEmitter:nil childViewControllers:@[_vc1]];
160 157
 	return nav;
161 158
 }
162 159
 

+ 5
- 10
lib/ios/ReactNativeNavigationTests/RNNRootViewControllerTest.m View File

@@ -415,8 +415,7 @@
415 415
 -(void)testRightButtonsWithTitle_withoutStyle {
416 416
 	self.options.topBar.rightButtons = @[@{@"id": @"testId", @"text": @"test"}];
417 417
 	self.uut = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[RNNViewControllerPresenter new] options:self.options defaultOptions:nil];
418
-	RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator options:nil defaultOptions:nil presenter:nil eventEmitter:nil];
419
-	[nav setViewControllers:@[self.uut]];
418
+	RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:@[self.uut]];
420 419
 
421 420
 	RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.rightBarButtonItems objectAtIndex:0];
422 421
 	NSString* expectedButtonId = @"testId";
@@ -431,8 +430,7 @@
431 430
 
432 431
 	self.options.topBar.rightButtons = @[@{@"id": @"testId", @"text": @"test", @"enabled": @false, @"buttonColor": inputColor, @"buttonFontSize": @22, @"buttonFontWeight": @"800"}];
433 432
 	self.uut = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[RNNViewControllerPresenter new] options:self.options defaultOptions:nil];
434
-	RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator options:nil defaultOptions:nil presenter:nil eventEmitter:nil];
435
-	[nav setViewControllers:@[self.uut]];
433
+	RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:@[self.uut]];
436 434
 
437 435
 	RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.rightBarButtonItems objectAtIndex:0];
438 436
 	NSString* expectedButtonId = @"testId";
@@ -448,8 +446,7 @@
448 446
 -(void)testLeftButtonsWithTitle_withoutStyle {
449 447
 	self.options.topBar.leftButtons = @[@{@"id": @"testId", @"text": @"test"}];
450 448
 	self.uut = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[RNNViewControllerPresenter new] options:self.options defaultOptions:nil];
451
-	RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator options:nil defaultOptions:nil presenter:nil eventEmitter:nil];
452
-	[nav setViewControllers:@[self.uut]];
449
+	RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:@[self.uut]];
453 450
 	
454 451
 	RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.leftBarButtonItems objectAtIndex:0];
455 452
 	NSString* expectedButtonId = @"testId";
@@ -464,8 +461,7 @@
464 461
 
465 462
 	self.options.topBar.leftButtons = @[@{@"id": @"testId", @"text": @"test", @"enabled": @false, @"buttonColor": inputColor, @"buttonFontSize": @22, @"buttonFontWeight": @"800"}];
466 463
 	self.uut = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[RNNViewControllerPresenter new] options:self.options defaultOptions:nil];
467
-	RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator options:nil defaultOptions:nil presenter:nil eventEmitter:nil];
468
-	[nav setViewControllers:@[self.uut]];
464
+	RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:_creator options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:@[self.uut]];
469 465
 
470 466
 	RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.leftBarButtonItems objectAtIndex:0];
471 467
 	NSString* expectedButtonId = @"testId";
@@ -569,8 +565,7 @@
569 565
 
570 566
 
571 567
 - (RNNNavigationController *)createNavigationController {
572
-	RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:[[RNNNavigationControllerPresenter alloc] init] eventEmitter:nil];
573
-	[nav setViewControllers:@[self.uut]];
568
+	RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:[[RNNNavigationControllerPresenter alloc] init] eventEmitter:nil childViewControllers:@[self.uut]];
574 569
 	
575 570
 	return nav;
576 571
 }

+ 3
- 3
lib/ios/ReactNativeNavigationTests/RNNSideMenuControllerTest.m View File

@@ -13,9 +13,9 @@
13 13
 
14 14
 - (void)setUp {
15 15
     [super setUp];
16
-	_leftVC = [[RNNSideMenuChildVC alloc] initWithLayoutInfo:nil childViewControllers:@[[RNNRootViewController new]] options:nil defaultOptions:nil presenter:nil type:RNNSideMenuChildTypeLeft];
17
-	_rightVC = [[RNNSideMenuChildVC alloc] initWithLayoutInfo:nil childViewControllers:@[[RNNRootViewController new]] options:nil defaultOptions:nil presenter:nil type:RNNSideMenuChildTypeRight];
18
-	_centerVC = [[RNNSideMenuChildVC alloc] initWithLayoutInfo:nil childViewControllers:@[[RNNRootViewController new]] options:nil defaultOptions:nil presenter:nil type:RNNSideMenuChildTypeCenter];
16
+	_leftVC = [[RNNSideMenuChildVC alloc] initWithLayoutInfo:nil creator:nil options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewController:[RNNRootViewController new] type:RNNSideMenuChildTypeLeft];
17
+	_rightVC = [[RNNSideMenuChildVC alloc] initWithLayoutInfo:nil creator:nil options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewController:[RNNRootViewController new] type:RNNSideMenuChildTypeRight];
18
+	_centerVC =[[RNNSideMenuChildVC alloc] initWithLayoutInfo:nil creator:nil options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewController:[RNNRootViewController new] type:RNNSideMenuChildTypeCenter];
19 19
 	self.uut = [[RNNSideMenuController alloc] initWithLayoutInfo:nil creator:nil childViewControllers:@[_leftVC, _centerVC, _rightVC] options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:nil eventEmitter:nil];
20 20
 }
21 21
 

+ 6
- 11
lib/ios/ReactNativeNavigationTests/RNNTabBarControllerTest.m View File

@@ -26,8 +26,7 @@
26 26
 	self.mockTabBarPresenter = [OCMockObject partialMockForObject:[[RNNTabBarPresenter alloc] init]];
27 27
 	self.mockChildViewController = [OCMockObject partialMockForObject:[RNNRootViewController new]];
28 28
 	self.mockEventEmmiter = [OCMockObject partialMockForObject:[RNNEventEmitter new]];
29
-	self.mockUut = [OCMockObject partialMockForObject:[[RNNTabBarController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initWithDict:@{}] defaultOptions:nil presenter:self.mockTabBarPresenter eventEmitter:self.mockEventEmmiter]];
30
-	[self.mockUut setViewControllers:@[[[UIViewController alloc] init]]];
29
+	self.mockUut = [OCMockObject partialMockForObject:[[RNNTabBarController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initWithDict:@{}] defaultOptions:nil presenter:self.mockTabBarPresenter eventEmitter:self.mockEventEmmiter childViewControllers:@[[[UIViewController alloc] init]]]];
31 30
 	OCMStub([self.mockUut selectedViewController]).andReturn(self.mockChildViewController);
32 31
 }
33 32
 
@@ -39,8 +38,7 @@
39 38
 	UIViewController* vc1 = [[UIViewController alloc] init];
40 39
 	UIViewController* vc2 = [[UIViewController alloc] init];
41 40
 	
42
-	RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initWithDict:@{}] defaultOptions:nil presenter:[[RNNViewControllerPresenter alloc] init] eventEmitter:nil];
43
-	[uut setViewControllers:@[vc1, vc2]];
41
+	RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initWithDict:@{}] defaultOptions:nil presenter:[[RNNViewControllerPresenter alloc] init] eventEmitter:nil childViewControllers:@[vc1, vc2]];
44 42
 	XCTAssertTrue(uut.viewControllers.count == 2);
45 43
 }
46 44
 
@@ -50,8 +48,7 @@
50 48
 	RNNTabBarPresenter* presenter = [[RNNTabBarPresenter alloc] init];
51 49
 	NSArray* childViewControllers = @[[UIViewController new]];
52 50
 	
53
-	RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:layoutInfo creator:nil options:options defaultOptions:nil presenter:presenter eventEmitter:nil];
54
-	[uut setViewControllers:childViewControllers];
51
+	RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:layoutInfo creator:nil options:options defaultOptions:nil presenter:presenter eventEmitter:nil childViewControllers:childViewControllers];
55 52
 	XCTAssertTrue(uut.layoutInfo == layoutInfo);
56 53
 	XCTAssertTrue(uut.options == options);
57 54
 	XCTAssertTrue(uut.presenter == presenter);
@@ -66,8 +63,7 @@
66 63
 
67 64
 	NSArray* childViewControllers = @[[UIViewController new]];
68 65
 	
69
-	RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:layoutInfo creator:nil options:options defaultOptions:nil presenter:presenter eventEmitter:eventEmmiter];
70
-	[uut setViewControllers:childViewControllers];
66
+	RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:layoutInfo creator:nil options:options defaultOptions:nil presenter:presenter eventEmitter:eventEmmiter childViewControllers:childViewControllers];
71 67
 	XCTAssertTrue(uut.layoutInfo == layoutInfo);
72 68
 	XCTAssertTrue(uut.options == options);
73 69
 	XCTAssertTrue(uut.presenter == presenter);
@@ -76,7 +72,7 @@
76 72
 }
77 73
 
78 74
 - (void)testInitWithLayoutInfo_shouldSetDelegate {
79
-	RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initWithDict:@{}] defaultOptions:nil presenter:[[RNNBasePresenter alloc] init] eventEmitter:nil];
75
+	RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initWithDict:@{}] defaultOptions:nil presenter:[[RNNBasePresenter alloc] init] eventEmitter:nil childViewControllers:nil];
80 76
 	
81 77
 	XCTAssertTrue(uut.delegate == uut);
82 78
 }
@@ -152,8 +148,7 @@
152 148
 	
153 149
 	RNNRootViewController* vc = [[RNNRootViewController alloc] initWithLayoutInfo:layoutInfo rootViewCreator:nil eventEmitter:nil presenter:nil options:nil defaultOptions:nil];
154 150
 	
155
-	RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil creator:nil options:nil defaultOptions:nil presenter:[RNNTabBarPresenter new] eventEmitter:nil];
156
-	[uut setViewControllers:@[[UIViewController new], vc]];
151
+	RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil creator:nil options:nil defaultOptions:nil presenter:[RNNTabBarPresenter new] eventEmitter:nil childViewControllers:@[[UIViewController new], vc]];
157 152
 	[uut setSelectedIndexByComponentID:@"componentId"];
158 153
 	XCTAssertTrue(uut.selectedIndex == 1);
159 154
 }

+ 22
- 0
lib/ios/ReactNativeNavigationTests/UIViewController+LayoutProtocolTest.m View File

@@ -1,6 +1,8 @@
1 1
 #import <XCTest/XCTest.h>
2 2
 #import <OCMock/OCMock.h>
3 3
 #import "UIViewController+LayoutProtocol.h"
4
+#import "RNNViewControllerPresenter.h"
5
+#import "RCTConvert+Modal.h"
4 6
 
5 7
 @interface UIViewController_LayoutProtocolTest : XCTestCase
6 8
 
@@ -17,5 +19,25 @@
17 19
     self.uut.layoutInfo.componentId = @"componentId";
18 20
 }
19 21
 
22
+- (void)testInitWithLayoutApplyDefaultOptions {
23
+    RNNViewControllerPresenter* presenter = [[RNNViewControllerPresenter alloc] init];
24
+    RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
25
+    RNNNavigationOptions* defaultOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
26
+    defaultOptions.modalPresentationStyle = [[Text alloc] initWithValue:@"fullScreen"];
27
+
28
+    UIViewController* uut = [[UIViewController alloc] initWithLayoutInfo:nil creator:nil options:options defaultOptions:defaultOptions presenter:presenter eventEmitter:nil childViewControllers:nil];
29
+    XCTAssertEqual(uut.modalPresentationStyle, [RCTConvert UIModalPresentationStyle:@"fullScreen"]);
30
+}
31
+
32
+- (void)testInitWithLayoutInfoShouldSetChildViewControllers {
33
+	UIViewController* child1 = [UIViewController new];
34
+	UIViewController* child2 = [UIViewController new];
35
+	NSArray* childViewControllers = @[child1, child2];
36
+	UINavigationController* uut = [[UINavigationController alloc] initWithLayoutInfo:nil creator:nil options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:childViewControllers];
37
+	
38
+	XCTAssertEqual(uut.viewControllers[0], child1);
39
+	XCTAssertEqual(uut.viewControllers[1], child2);
40
+}
41
+
20 42
 
21 43
 @end

+ 7
- 2
lib/ios/UIViewController+LayoutProtocol.m View File

@@ -9,7 +9,8 @@
9 9
 						   options:(RNNNavigationOptions *)options
10 10
 					defaultOptions:(RNNNavigationOptions *)defaultOptions
11 11
 						 presenter:(RNNBasePresenter *)presenter
12
-					  eventEmitter:(RNNEventEmitter *)eventEmitter {
12
+					  eventEmitter:(RNNEventEmitter *)eventEmitter
13
+			  childViewControllers:(NSArray *)childViewControllers {
13 14
 	self = [self init];
14 15
 	
15 16
 	self.options = options;
@@ -17,9 +18,13 @@
17 18
 	self.layoutInfo = layoutInfo;
18 19
 	self.creator = creator;
19 20
 	self.eventEmitter = eventEmitter;
21
+	if ([self respondsToSelector:@selector(setViewControllers:)]) {
22
+		[self performSelector:@selector(setViewControllers:) withObject:childViewControllers];
23
+	}
20 24
 	self.presenter = presenter;
21 25
 	[self.presenter bindViewController:self];
22
-	[self.presenter applyOptionsOnInit:self.options];
26
+	[self.presenter applyOptionsOnInit:self.resolveOptions];
27
+	
23 28
 
24 29
 	return self;
25 30
 }