Browse Source

Refactored getCurrentLeaf and getCurrentChild (#4242)

Yogev Ben David 5 years ago
parent
commit
dd4d6ea7b4
No account linked to committer's email address

+ 3
- 3
lib/ios/RNNCommandsHandler.m View File

138
 			});
138
 			});
139
 		}
139
 		}
140
 	} else {
140
 	} else {
141
-		id animationDelegate = (newVc.resolveOptions.animations.push.hasCustomAnimation || newVc.getCurrentChild.isCustomTransitioned) ? newVc : nil;
142
-		[newVc.getCurrentChild waitForReactViewRender:(newVc.resolveOptions.animations.push.waitForRender || animationDelegate) perform:^{
141
+		id animationDelegate = (newVc.resolveOptions.animations.push.hasCustomAnimation || newVc.getCurrentLeaf.isCustomTransitioned) ? newVc : nil;
142
+		[newVc.getCurrentLeaf waitForReactViewRender:(newVc.resolveOptions.animations.push.waitForRender || animationDelegate) perform:^{
143
 			[_stackManager push:newVc onTop:fromVC animated:newVc.resolveOptions.animations.push.enable animationDelegate:animationDelegate completion:^{
143
 			[_stackManager push:newVc onTop:fromVC animated:newVc.resolveOptions.animations.push.enable animationDelegate:animationDelegate completion:^{
144
 				[_eventEmitter sendOnNavigationCommandCompletion:push params:@{@"componentId": componentId}];
144
 				[_eventEmitter sendOnNavigationCommandCompletion:push params:@{@"componentId": componentId}];
145
 				completion();
145
 				completion();
228
 	
228
 	
229
 	UIViewController<RNNParentProtocol> *newVc = [_controllerFactory createLayout:layout saveToStore:_store];
229
 	UIViewController<RNNParentProtocol> *newVc = [_controllerFactory createLayout:layout saveToStore:_store];
230
 	
230
 	
231
-	[newVc.getCurrentChild waitForReactViewRender:newVc.getCurrentChild.resolveOptions.animations.showModal.waitForRender perform:^{
231
+	[newVc.getCurrentLeaf waitForReactViewRender:newVc.getCurrentLeaf.resolveOptions.animations.showModal.waitForRender perform:^{
232
 		[_modalManager showModal:newVc animated:newVc.getCurrentChild.resolveOptions.animations.showModal.enable hasCustomAnimation:newVc.getCurrentChild.resolveOptions.animations.showModal.hasCustomAnimation completion:^(NSString *componentId) {
232
 		[_modalManager showModal:newVc animated:newVc.getCurrentChild.resolveOptions.animations.showModal.enable hasCustomAnimation:newVc.getCurrentChild.resolveOptions.animations.showModal.hasCustomAnimation completion:^(NSString *componentId) {
233
 			[_eventEmitter sendOnNavigationCommandCompletion:showModal params:@{@"layout": layout}];
233
 			[_eventEmitter sendOnNavigationCommandCompletion:showModal params:@{@"layout": layout}];
234
 			completion(componentId);
234
 			completion(componentId);

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

11
 @property (nonatomic, strong) RNNNavigationOptions* options;
11
 @property (nonatomic, strong) RNNNavigationOptions* options;
12
 @property (nonatomic, strong) RNNNavigationOptions* defaultOptions;
12
 @property (nonatomic, strong) RNNNavigationOptions* defaultOptions;
13
 
13
 
14
-- (UIViewController<RNNLeafProtocol, RNNLayoutProtocol> *)getCurrentChild;
14
+- (UIViewController<RNNLayoutProtocol> *)getCurrentChild;
15
+
16
+- (UIViewController<RNNLeafProtocol, RNNLayoutProtocol> *)getCurrentLeaf;
15
 
17
 
16
 - (void)mergeOptions:(RNNNavigationOptions *)options;
18
 - (void)mergeOptions:(RNNNavigationOptions *)options;
17
 
19
 

+ 4
- 0
lib/ios/RNNNavigationController.m View File

97
 	return ((UIViewController<RNNParentProtocol>*)self.topViewController);
97
 	return ((UIViewController<RNNParentProtocol>*)self.topViewController);
98
 }
98
 }
99
 
99
 
100
+- (UIViewController<RNNLeafProtocol> *)getCurrentLeaf {
101
+	return [[self getCurrentChild] getCurrentLeaf];
102
+}
103
+
100
 - (UIViewController *)childViewControllerForStatusBarStyle {
104
 - (UIViewController *)childViewControllerForStatusBarStyle {
101
 	return self.topViewController;
105
 	return self.topViewController;
102
 }
106
 }

+ 4
- 0
lib/ios/RNNRootViewController.m View File

133
 	return self;
133
 	return self;
134
 }
134
 }
135
 
135
 
136
+- (UIViewController<RNNLeafProtocol> *)getCurrentLeaf {
137
+	return self;
138
+}
139
+
136
 - (void)onReactViewReady:(RNNReactViewReadyCompletionBlock)readyBlock {
140
 - (void)onReactViewReady:(RNNReactViewReadyCompletionBlock)readyBlock {
137
 	if (self.isExternalViewController) {
141
 	if (self.isExternalViewController) {
138
 		readyBlock();
142
 		readyBlock();

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

11
 @interface RNNSideMenuChildVC : UIViewController <RNNParentProtocol>
11
 @interface RNNSideMenuChildVC : UIViewController <RNNParentProtocol>
12
 
12
 
13
 @property (readonly) RNNSideMenuChildType type;
13
 @property (readonly) RNNSideMenuChildType type;
14
-@property (readonly) UIViewController<RNNParentProtocol> *child;
14
+@property (readonly) UIViewController<RNNLayoutProtocol> *child;
15
 
15
 
16
 @property (nonatomic, retain) RNNLayoutInfo* layoutInfo;
16
 @property (nonatomic, retain) RNNLayoutInfo* layoutInfo;
17
 @property (nonatomic, retain) RNNViewControllerPresenter* presenter;
17
 @property (nonatomic, retain) RNNViewControllerPresenter* presenter;

+ 7
- 3
lib/ios/RNNSideMenuChildVC.m View File

3
 @interface RNNSideMenuChildVC ()
3
 @interface RNNSideMenuChildVC ()
4
 
4
 
5
 @property (readwrite) RNNSideMenuChildType type;
5
 @property (readwrite) RNNSideMenuChildType type;
6
-@property (nonatomic, retain) UIViewController<RNNParentProtocol> *child;
6
+@property (nonatomic, retain) UIViewController<RNNLayoutProtocol> *child;
7
 
7
 
8
 @end
8
 @end
9
 
9
 
56
 	return self.child.tabBarItem;
56
 	return self.child.tabBarItem;
57
 }
57
 }
58
 
58
 
59
-- (void)bindChildViewController:(UIViewController<RNNParentProtocol>*)child {
59
+- (void)bindChildViewController:(UIViewController<RNNLayoutProtocol>*)child {
60
 	self.child = child;
60
 	self.child = child;
61
 	[self addChildViewController:self.child];
61
 	[self addChildViewController:self.child];
62
 	[self.child.view setFrame:self.view.bounds];
62
 	[self.child.view setFrame:self.view.bounds];
65
 }
65
 }
66
 
66
 
67
 - (UIViewController *)getCurrentChild {
67
 - (UIViewController *)getCurrentChild {
68
-	return [self.child getCurrentChild];
68
+	return self.child;
69
+}
70
+
71
+- (UIViewController<RNNLeafProtocol> *)getCurrentLeaf {
72
+	return [[self getCurrentChild] getCurrentLeaf];
69
 }
73
 }
70
 
74
 
71
 - (UIStatusBarStyle)preferredStatusBarStyle {
75
 - (UIStatusBarStyle)preferredStatusBarStyle {

+ 5
- 1
lib/ios/RNNSideMenuController.m View File

158
 }
158
 }
159
 
159
 
160
 - (UIViewController<RNNLayoutProtocol> *)getCurrentChild {
160
 - (UIViewController<RNNLayoutProtocol> *)getCurrentChild {
161
-	return [self.center getCurrentChild];
161
+	return self.center;
162
+}
163
+
164
+- (UIViewController<RNNLeafProtocol> *)getCurrentLeaf {
165
+	return [[self getCurrentChild] getCurrentLeaf];
162
 }
166
 }
163
 
167
 
164
 @end
168
 @end

+ 5
- 1
lib/ios/RNNSplitViewController.m View File

48
 }
48
 }
49
 
49
 
50
 - (UIViewController *)getCurrentChild {
50
 - (UIViewController *)getCurrentChild {
51
-	return self;
51
+	return self.viewControllers[0];
52
+}
53
+
54
+- (UIViewController<RNNLeafProtocol> *)getCurrentLeaf {
55
+	return [[self getCurrentChild] getCurrentLeaf];
52
 }
56
 }
53
 
57
 
54
 @end
58
 @end

+ 5
- 1
lib/ios/RNNTabBarController.m View File

79
 }
79
 }
80
 
80
 
81
 - (UIViewController *)getCurrentChild {
81
 - (UIViewController *)getCurrentChild {
82
-	return ((UIViewController<RNNParentProtocol>*)self.selectedViewController).getCurrentChild;
82
+	return self.selectedViewController;
83
+}
84
+
85
+- (UIViewController<RNNLeafProtocol> *)getCurrentLeaf {
86
+	return [[self getCurrentChild] getCurrentLeaf];
83
 }
87
 }
84
 
88
 
85
 - (UIStatusBarStyle)preferredStatusBarStyle {
89
 - (UIStatusBarStyle)preferredStatusBarStyle {

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

111
 	return _currentViewController;
111
 	return _currentViewController;
112
 }
112
 }
113
 
113
 
114
+- (UIViewController<RNNLeafProtocol> *)getCurrentLeaf {
115
+	return [[self getCurrentChild] getCurrentLeaf];
116
+}
117
+
114
 @end
118
 @end

+ 12
- 0
lib/ios/ReactNativeNavigationTests/RNNNavigationControllerTest.m View File

11
 
11
 
12
 @implementation RNNNavigationControllerTest {
12
 @implementation RNNNavigationControllerTest {
13
 	RNNRootViewController* _vc1;
13
 	RNNRootViewController* _vc1;
14
+	id _vc2Mock;
14
 	RNNRootViewController* _vc2;
15
 	RNNRootViewController* _vc2;
15
 	UIViewController* _vc3;
16
 	UIViewController* _vc3;
16
 	RNNNavigationOptions* _options;
17
 	RNNNavigationOptions* _options;
21
 	
22
 	
22
 	_vc1 = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[OCMockObject partialMockForObject:[[RNNViewControllerPresenter alloc] init]] options:[[RNNNavigationOptions alloc] initEmptyOptions]  defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions]];
23
 	_vc1 = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[OCMockObject partialMockForObject:[[RNNViewControllerPresenter alloc] init]] options:[[RNNNavigationOptions alloc] initEmptyOptions]  defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions]];
23
 	_vc2 = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[[RNNViewControllerPresenter alloc] init] options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions]];
24
 	_vc2 = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[[RNNViewControllerPresenter alloc] init] options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions]];
25
+	_vc2Mock = [OCMockObject partialMockForObject:_vc2];
24
 	_vc3 = [UIViewController new];
26
 	_vc3 = [UIViewController new];
25
 	_options = [OCMockObject partialMockForObject:[[RNNNavigationOptions alloc] initEmptyOptions]];
27
 	_options = [OCMockObject partialMockForObject:[[RNNNavigationOptions alloc] initEmptyOptions]];
26
 	self.uut = [[RNNNavigationController alloc] initWithLayoutInfo:nil childViewControllers:@[_vc1, _vc2] options:_options defaultOptions:nil presenter:[OCMockObject partialMockForObject:[[RNNNavigationControllerPresenter alloc] init]]];
28
 	self.uut = [[RNNNavigationController alloc] initWithLayoutInfo:nil childViewControllers:@[_vc1, _vc2] options:_options defaultOptions:nil presenter:[OCMockObject partialMockForObject:[[RNNNavigationControllerPresenter alloc] init]]];
39
 	XCTAssertTrue(self.uut.childViewControllerForStatusBarStyle == self.uut.topViewController);
41
 	XCTAssertTrue(self.uut.childViewControllerForStatusBarStyle == self.uut.topViewController);
40
 }
42
 }
41
 
43
 
44
+- (void)testCurrentChild_shouldReturnTopViewController {
45
+	XCTAssertTrue(self.uut.getCurrentChild == self.uut.topViewController);
46
+}
47
+
48
+- (void)testCurrentLeaf_shouldReturnCurrentChildLeaf {
49
+	[[_vc2Mock expect] getCurrentLeaf];
50
+	[self.uut getCurrentLeaf];
51
+	[_vc2Mock verify];
52
+}
53
+
42
 - (void)testGetLeafViewController_shouldReturnTopViewController {
54
 - (void)testGetLeafViewController_shouldReturnTopViewController {
43
 	XCTAssertTrue(self.uut.getCurrentChild == self.uut.topViewController);
55
 	XCTAssertTrue(self.uut.getCurrentChild == self.uut.topViewController);
44
 }
56
 }

+ 5
- 7
lib/ios/ReactNativeNavigationTests/RNNTabBarControllerTest.m View File

123
 	[parentMock verify];
123
 	[parentMock verify];
124
 }
124
 }
125
 
125
 
126
-- (void)testGetCurrentChild_shouldInvokeSelectedViewControllerGetCurrentChild {
127
-	[[self.mockChildViewController expect] getCurrentChild];
128
-	[self.mockUut getCurrentChild];
126
+- (void)testGetCurrentLeaf_shouldInvokeSelectedViewControllerGetCurrentLeaf {
127
+	[[self.mockChildViewController expect] getCurrentLeaf];
128
+	[self.mockUut getCurrentLeaf];
129
 	[self.mockChildViewController verify];
129
 	[self.mockChildViewController verify];
130
 }
130
 }
131
 
131
 
132
-- (void)testGetCurrentChild_shouldInvokeOnSelectedViewController {
133
-	[[self.mockChildViewController expect] getCurrentChild];
134
-	[self.mockUut getCurrentChild];
135
-	[self.mockChildViewController verify];
132
+- (void)testGetCurrentChild_shouldReturnSelectedViewController {
133
+	XCTAssertEqual([self.mockUut getCurrentChild], [(RNNTabBarController *)self.mockUut selectedViewController]);
136
 }
134
 }
137
 
135
 
138
 - (void)testPreferredStatusBarStyle_shouldInvokeSelectedViewControllerPreferredStatusBarStyle {
136
 - (void)testPreferredStatusBarStyle_shouldInvokeSelectedViewControllerPreferredStatusBarStyle {