Przeglądaj źródła

Refactored getCurrentLeaf and getCurrentChild (#4242)

Yogev Ben David 6 lat temu
rodzic
commit
dd4d6ea7b4
No account linked to committer's email address

+ 3
- 3
lib/ios/RNNCommandsHandler.m Wyświetl plik

@@ -138,8 +138,8 @@ static NSString* const setDefaultOptions	= @"setDefaultOptions";
138 138
 			});
139 139
 		}
140 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 143
 			[_stackManager push:newVc onTop:fromVC animated:newVc.resolveOptions.animations.push.enable animationDelegate:animationDelegate completion:^{
144 144
 				[_eventEmitter sendOnNavigationCommandCompletion:push params:@{@"componentId": componentId}];
145 145
 				completion();
@@ -228,7 +228,7 @@ static NSString* const setDefaultOptions	= @"setDefaultOptions";
228 228
 	
229 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 232
 		[_modalManager showModal:newVc animated:newVc.getCurrentChild.resolveOptions.animations.showModal.enable hasCustomAnimation:newVc.getCurrentChild.resolveOptions.animations.showModal.hasCustomAnimation completion:^(NSString *componentId) {
233 233
 			[_eventEmitter sendOnNavigationCommandCompletion:showModal params:@{@"layout": layout}];
234 234
 			completion(componentId);

+ 3
- 1
lib/ios/RNNLayoutProtocol.h Wyświetl plik

@@ -11,7 +11,9 @@
11 11
 @property (nonatomic, strong) RNNNavigationOptions* options;
12 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 18
 - (void)mergeOptions:(RNNNavigationOptions *)options;
17 19
 

+ 4
- 0
lib/ios/RNNNavigationController.m Wyświetl plik

@@ -97,6 +97,10 @@ const NSInteger TOP_BAR_TRANSPARENT_TAG = 78264803;
97 97
 	return ((UIViewController<RNNParentProtocol>*)self.topViewController);
98 98
 }
99 99
 
100
+- (UIViewController<RNNLeafProtocol> *)getCurrentLeaf {
101
+	return [[self getCurrentChild] getCurrentLeaf];
102
+}
103
+
100 104
 - (UIViewController *)childViewControllerForStatusBarStyle {
101 105
 	return self.topViewController;
102 106
 }

+ 4
- 0
lib/ios/RNNRootViewController.m Wyświetl plik

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

+ 1
- 1
lib/ios/RNNSideMenuChildVC.h Wyświetl plik

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

+ 7
- 3
lib/ios/RNNSideMenuChildVC.m Wyświetl plik

@@ -3,7 +3,7 @@
3 3
 @interface RNNSideMenuChildVC ()
4 4
 
5 5
 @property (readwrite) RNNSideMenuChildType type;
6
-@property (nonatomic, retain) UIViewController<RNNParentProtocol> *child;
6
+@property (nonatomic, retain) UIViewController<RNNLayoutProtocol> *child;
7 7
 
8 8
 @end
9 9
 
@@ -56,7 +56,7 @@
56 56
 	return self.child.tabBarItem;
57 57
 }
58 58
 
59
-- (void)bindChildViewController:(UIViewController<RNNParentProtocol>*)child {
59
+- (void)bindChildViewController:(UIViewController<RNNLayoutProtocol>*)child {
60 60
 	self.child = child;
61 61
 	[self addChildViewController:self.child];
62 62
 	[self.child.view setFrame:self.view.bounds];
@@ -65,7 +65,11 @@
65 65
 }
66 66
 
67 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 75
 - (UIStatusBarStyle)preferredStatusBarStyle {

+ 5
- 1
lib/ios/RNNSideMenuController.m Wyświetl plik

@@ -158,7 +158,11 @@
158 158
 }
159 159
 
160 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 168
 @end

+ 5
- 1
lib/ios/RNNSplitViewController.m Wyświetl plik

@@ -48,7 +48,11 @@
48 48
 }
49 49
 
50 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 58
 @end

+ 5
- 1
lib/ios/RNNTabBarController.m Wyświetl plik

@@ -79,7 +79,11 @@
79 79
 }
80 80
 
81 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 89
 - (UIStatusBarStyle)preferredStatusBarStyle {

+ 4
- 0
lib/ios/RNNTopTabsViewController.m Wyświetl plik

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

+ 12
- 0
lib/ios/ReactNativeNavigationTests/RNNNavigationControllerTest.m Wyświetl plik

@@ -11,6 +11,7 @@
11 11
 
12 12
 @implementation RNNNavigationControllerTest {
13 13
 	RNNRootViewController* _vc1;
14
+	id _vc2Mock;
14 15
 	RNNRootViewController* _vc2;
15 16
 	UIViewController* _vc3;
16 17
 	RNNNavigationOptions* _options;
@@ -21,6 +22,7 @@
21 22
 	
22 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 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 26
 	_vc3 = [UIViewController new];
25 27
 	_options = [OCMockObject partialMockForObject:[[RNNNavigationOptions alloc] initEmptyOptions]];
26 28
 	self.uut = [[RNNNavigationController alloc] initWithLayoutInfo:nil childViewControllers:@[_vc1, _vc2] options:_options defaultOptions:nil presenter:[OCMockObject partialMockForObject:[[RNNNavigationControllerPresenter alloc] init]]];
@@ -39,6 +41,16 @@
39 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 54
 - (void)testGetLeafViewController_shouldReturnTopViewController {
43 55
 	XCTAssertTrue(self.uut.getCurrentChild == self.uut.topViewController);
44 56
 }

+ 5
- 7
lib/ios/ReactNativeNavigationTests/RNNTabBarControllerTest.m Wyświetl plik

@@ -123,16 +123,14 @@
123 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 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 136
 - (void)testPreferredStatusBarStyle_shouldInvokeSelectedViewControllerPreferredStatusBarStyle {