Selaa lähdekoodia

Merge options with correct child (#6041)

Co-authored-by: Guy Carmeli <guyca@users.noreply.github.com>
Yogev Ben David 4 vuotta sitten
vanhempi
commit
3c38c50a8b
No account linked to committer's email address

+ 2
- 2
lib/ios/RNNBottomTabsController.m Näytä tiedosto

@@ -38,8 +38,8 @@
38 38
 
39 39
 - (void)mergeChildOptions:(RNNNavigationOptions *)options child:(UIViewController *)child {
40 40
     [super mergeChildOptions:options child:child];
41
-    [_bottomTabPresenter mergeOptions:options resolvedOptions:self.resolveOptions child:[self findViewController:child]];
42
-    [_dotIndicatorPresenter mergeOptions:options resolvedOptions:self.resolveOptions child:[self findViewController:child]];
41
+    [_bottomTabPresenter mergeOptions:options resolvedOptions:child.resolveOptions child:[self findViewController:child]];
42
+    [_dotIndicatorPresenter mergeOptions:options resolvedOptions:child.resolveOptions child:[self findViewController:child]];
43 43
 }
44 44
 
45 45
 - (id<UITabBarControllerDelegate>)delegate {

+ 42
- 23
playground/ios/NavigationTests/RNNCommandsHandlerTest.m Näytä tiedosto

@@ -10,20 +10,8 @@
10 10
 #import "RNNLayoutManager.h"
11 11
 #import "RNNBottomTabsController.h"
12 12
 #import "BottomTabsAttachModeFactory.h"
13
-
14
-@interface MockUIApplication : NSObject
15
-
16
--(UIWindow *)keyWindow;
17
-
18
-@end
19
-
20
-@implementation MockUIApplication
21
-
22
-- (UIWindow *)keyWindow {
23
-	return [UIWindow new];
24
-}
25
-
26
-@end
13
+#import <ReactNativeNavigation/BottomTabPresenterCreator.h>
14
+#import "RNNComponentViewController+Utils.h"
27 15
 
28 16
 @interface MockUINavigationController : RNNStackController
29 17
 @property (nonatomic, strong) NSArray* willReturnVCs;
@@ -62,7 +50,6 @@
62 50
 
63 51
 - (void)setUp {
64 52
 	[super setUp];
65
-	self.sharedApplication = [OCMockObject mockForClass:[UIApplication class]];
66 53
 	self.creator = [OCMockObject partialMockForObject:[RNNTestRootViewCreator new]];
67 54
 	self.mainWindow = [OCMockObject partialMockForObject:[UIWindow new]];
68 55
 	self.eventEmmiter = [OCMockObject partialMockForObject:[RNNEventEmitter new]];
@@ -75,7 +62,12 @@
75 62
 	self.vc3 = [self generateComponentWithComponentId:@"3"];
76 63
 	_nvc = [[MockUINavigationController alloc] init];
77 64
 	[_nvc setViewControllers:@[self.vc1, self.vc2, self.vc3]];
78
-	OCMStub([self.sharedApplication keyWindow]).andReturn(self.mainWindow);
65
+	
66
+	UIApplication* sharedApplication = [OCMockObject niceMockForClass:[UIApplication class]];
67
+	id mockedApplicationClass = OCMClassMock([UIApplication class]);
68
+	OCMStub(ClassMethod([mockedApplicationClass sharedApplication])).andReturn(sharedApplication);
69
+	OCMStub(sharedApplication.keyWindow).andReturn(self.mainWindow);
70
+	OCMStub([sharedApplication windows]).andReturn(@[self.mainWindow]);
79 71
 }
80 72
 
81 73
 - (RNNComponentViewController *)generateComponentWithComponentId:(NSString *)componentId {
@@ -129,14 +121,11 @@
129 121
 -(void)testDynamicStylesMergeWithStaticStyles {
130 122
 	RNNNavigationOptions* initialOptions = [[RNNNavigationOptions alloc] initWithDict:@{}];
131 123
 	initialOptions.topBar.title.text = [[Text alloc] initWithValue:@"the title"];
132
-	RNNLayoutInfo* layoutInfo = [RNNLayoutInfo new];
133 124
 	RNNTestRootViewCreator* creator = [[RNNTestRootViewCreator alloc] init];
134
-	
135
-	RNNComponentPresenter* presenter = [[RNNComponentPresenter alloc] initWithComponentRegistry:nil defaultOptions:nil];
136
-	RNNComponentViewController* vc = [[RNNComponentViewController alloc] initWithLayoutInfo:layoutInfo rootViewCreator:creator eventEmitter:nil presenter:presenter options:initialOptions defaultOptions:nil];
125
+	RNNComponentViewController* vc = [RNNComponentViewController createWithComponentId:@"componentId" initialOptions:initialOptions];
137 126
 	
138 127
 	RNNStackController* nav = [[RNNStackController alloc] initWithLayoutInfo:nil creator:creator options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:[[RNNStackPresenter alloc] init] eventEmitter:nil childViewControllers:@[vc]];
139
-	
128
+	[self.mainWindow setRootViewController:nav];
140 129
 	[vc viewWillAppear:false];
141 130
 	XCTAssertTrue([vc.navigationItem.title isEqual:@"the title"]);
142 131
 	
@@ -146,9 +135,11 @@
146 135
 	UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
147 136
 	
148 137
 	[self.uut mergeOptions:@"componentId" options:dictFromJs completion:^{
149
-		XCTAssertTrue([vc.navigationItem.title isEqual:@"the title"]);
150
-		XCTAssertTrue([nav.navigationBar.barTintColor isEqual:expectedColor]);
138
+		
151 139
 	}];
140
+	
141
+	XCTAssertTrue([vc.navigationItem.title isEqual:@"the title"]);
142
+	XCTAssertTrue([vc.navigationItem.standardAppearance.backgroundColor isEqual:expectedColor]);
152 143
 }
153 144
 
154 145
 - (void)testMergeOptions_shouldOverrideOptions {
@@ -420,6 +411,34 @@
420 411
 	XCTAssertTrue(_vc2.isViewLoaded);
421 412
 }
422 413
 
414
+- (void)testMergeOptions_shouldMergeWithChildOnly {
415
+	[self.uut setReadyToReceiveCommands:true];
416
+	NSDictionary* mergeOptions = @{@"bottomTab": @{@"badge": @"Badge"}};
417
+	
418
+	RNNNavigationOptions* firstChildOptions = [RNNNavigationOptions emptyOptions];
419
+	firstChildOptions.bottomTab.text = [Text withValue:@"First"];
420
+	RNNNavigationOptions* secondChildOptions = [RNNNavigationOptions emptyOptions];
421
+	secondChildOptions.bottomTab.text = [Text withValue:@"Second"];
422
+	
423
+	RNNComponentViewController* firstChild = [RNNComponentViewController createWithComponentId:@"first" initialOptions:firstChildOptions];
424
+	RNNComponentViewController* secondChild = [RNNComponentViewController createWithComponentId:@"second" initialOptions:secondChildOptions];
425
+	
426
+	RNNBottomTabsController* tabBarController = [[RNNBottomTabsController alloc] initWithLayoutInfo:nil creator:nil options:[RNNNavigationOptions emptyOptions] defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions] presenter:[RNNBasePresenter new] bottomTabPresenter:[BottomTabPresenterCreator createWithDefaultOptions:[RNNNavigationOptions emptyOptions]] dotIndicatorPresenter:nil eventEmitter:_eventEmmiter childViewControllers:@[firstChild, secondChild] bottomTabsAttacher:nil];
427
+	
428
+	OCMStub([self.controllerFactory createLayout:[OCMArg any]]).andReturn(tabBarController);
429
+	[self.mainWindow setRootViewController:tabBarController];
430
+	[secondChild viewWillAppear:YES];
431
+	
432
+	[self.uut mergeOptions:secondChild.layoutInfo.componentId options:mergeOptions completion:^{
433
+		
434
+	}];
435
+	
436
+	XCTAssertTrue([secondChild.tabBarItem.badgeValue isEqualToString:@"Badge"]);
437
+	XCTAssertNil(firstChild.tabBarItem.badgeValue);
438
+	XCTAssertTrue([firstChild.tabBarItem.title isEqualToString:@"First"]);
439
+	XCTAssertTrue([secondChild.tabBarItem.title isEqualToString:@"Second"]);
440
+}
441
+
423 442
 - (void)testShowModal_shouldShowAnimated {
424 443
 	[self.uut setReadyToReceiveCommands:true];
425 444
 	self.vc1.options = [[RNNNavigationOptions alloc] initEmptyOptions];

+ 1
- 1
playground/ios/NavigationTests/RNNLayoutManagerTest.m Näytä tiedosto

@@ -26,7 +26,7 @@
26 26
 	_secondWindow = [[UIWindow alloc] init];
27 27
 	NSArray* windows = @[_firstWindow, _secondWindow];
28 28
 	
29
-	UIApplication* sharedApplication = [OCMockObject mockForClass:[UIApplication class]];
29
+	UIApplication* sharedApplication = [OCMockObject niceMockForClass:[UIApplication class]];
30 30
 	id mockedApplicationClass = OCMClassMock([UIApplication class]);
31 31
 	OCMStub(ClassMethod([mockedApplicationClass sharedApplication])).andReturn(sharedApplication);
32 32
 	OCMStub(sharedApplication.keyWindow).andReturn(_firstWindow);

+ 2
- 0
playground/ios/NavigationTests/utils/RNNComponentViewController+Utils.h Näytä tiedosto

@@ -5,4 +5,6 @@
5 5
 
6 6
 + (RNNComponentViewController *)createWithComponentId:(NSString *)componentId;
7 7
 
8
++ (RNNComponentViewController *)createWithComponentId:(NSString *)componentId initialOptions:(RNNNavigationOptions *)initialOptions;
9
+
8 10
 @end

+ 7
- 2
playground/ios/NavigationTests/utils/RNNComponentViewController+Utils.m Näytä tiedosto

@@ -1,11 +1,16 @@
1 1
 #import "RNNComponentViewController+Utils.h"
2
+#import "RNNTestRootViewCreator.h"
2 3
 
3 4
 @implementation RNNComponentViewController (Utils)
4 5
 
5
-+ (RNNComponentViewController *)createWithComponentId:(NSString *)componentId {
6
++ (RNNComponentViewController *)createWithComponentId:(NSString *)componentId initialOptions:(RNNNavigationOptions *)initialOptions {
6 7
 	RNNLayoutInfo* layoutInfo = [[RNNLayoutInfo alloc] init];
7 8
 	layoutInfo.componentId = componentId;
8
-	return [[RNNComponentViewController alloc] initWithLayoutInfo:layoutInfo rootViewCreator:nil eventEmitter:nil presenter:nil options:nil defaultOptions:nil];
9
+	return [[RNNComponentViewController alloc] initWithLayoutInfo:layoutInfo rootViewCreator:[[RNNTestRootViewCreator alloc] init] eventEmitter:nil presenter:[[RNNComponentPresenter alloc] initWithComponentRegistry:nil defaultOptions:nil] options:initialOptions defaultOptions:nil];
10
+}
11
+
12
++ (RNNComponentViewController *)createWithComponentId:(NSString *)componentId {
13
+	return [self createWithComponentId:componentId initialOptions:nil];
9 14
 }
10 15
 
11 16
 @end

+ 11
- 3
playground/ios/playground.xcodeproj/project.pbxproj Näytä tiedosto

@@ -21,8 +21,8 @@
21 21
 		50996C6923AA487800008F89 /* RNNTestRootViewCreator.m in Sources */ = {isa = PBXBuildFile; fileRef = E58D263D2385888C003F36BA /* RNNTestRootViewCreator.m */; };
22 22
 		50BCB27623F1A2B100D6C8E5 /* TopBarAppearancePresenterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 50BCB27523F1A26600D6C8E5 /* TopBarAppearancePresenterTest.m */; };
23 23
 		50C9A8D1240EB95F00BD699F /* RNNBottomTabsController+Helpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 50CF233C240695B10098042D /* RNNBottomTabsController+Helpers.m */; };
24
-		50CF233D240695B10098042D /* RNNBottomTabsController+Helpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 50CF233C240695B10098042D /* RNNBottomTabsController+Helpers.m */; };
25 24
 		50C9A8D4240FB9D000BD699F /* RNNComponentViewController+Utils.m in Sources */ = {isa = PBXBuildFile; fileRef = 50C9A8D3240FB9D000BD699F /* RNNComponentViewController+Utils.m */; };
25
+		50CF233D240695B10098042D /* RNNBottomTabsController+Helpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 50CF233C240695B10098042D /* RNNBottomTabsController+Helpers.m */; };
26 26
 		67C681D42B662A53F29C19DA /* Pods_NavigationIOS12Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DEE0B5D45FD34FBABC6586CF /* Pods_NavigationIOS12Tests.framework */; };
27 27
 		9D204F3DC4FBCD81583BF99F /* Pods_playground.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4A3340545EAAF11C1F146864 /* Pods_playground.framework */; };
28 28
 		E5046080227748EA00212BD8 /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E504607F227748EA00212BD8 /* JavaScriptCore.framework */; };
@@ -97,10 +97,10 @@
97 97
 		50996C6123AA46DD00008F89 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
98 98
 		50996C6723AA477400008F89 /* RNNRootViewControllerTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNRootViewControllerTest.m; sourceTree = "<group>"; };
99 99
 		50BCB27523F1A26600D6C8E5 /* TopBarAppearancePresenterTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TopBarAppearancePresenterTest.m; sourceTree = "<group>"; };
100
-		50CF233B240695B10098042D /* RNNBottomTabsController+Helpers.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RNNBottomTabsController+Helpers.h"; sourceTree = "<group>"; };
101
-		50CF233C240695B10098042D /* RNNBottomTabsController+Helpers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "RNNBottomTabsController+Helpers.m"; sourceTree = "<group>"; };
102 100
 		50C9A8D2240FB9D000BD699F /* RNNComponentViewController+Utils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RNNComponentViewController+Utils.h"; sourceTree = "<group>"; };
103 101
 		50C9A8D3240FB9D000BD699F /* RNNComponentViewController+Utils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "RNNComponentViewController+Utils.m"; sourceTree = "<group>"; };
102
+		50CF233B240695B10098042D /* RNNBottomTabsController+Helpers.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RNNBottomTabsController+Helpers.h"; sourceTree = "<group>"; };
103
+		50CF233C240695B10098042D /* RNNBottomTabsController+Helpers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "RNNBottomTabsController+Helpers.m"; sourceTree = "<group>"; };
104 104
 		7F8E255E2E08F6ECE7DF6FE3 /* Pods-playground.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-playground.release.xcconfig"; path = "Target Support Files/Pods-playground/Pods-playground.release.xcconfig"; sourceTree = "<group>"; };
105 105
 		84E32151E3A71C2B7328BCB4 /* Pods_NavigationTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_NavigationTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
106 106
 		B484A10A046B0046B98A76B5 /* Pods-playground.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-playground.debug.xcconfig"; path = "Target Support Files/Pods-playground/Pods-playground.debug.xcconfig"; sourceTree = "<group>"; };
@@ -399,11 +399,13 @@
399 399
 					50996C5C23AA46DD00008F89 = {
400 400
 						CreatedOnToolsVersion = 11.2.1;
401 401
 						ProvisioningStyle = Automatic;
402
+						TestTargetID = 13B07F861A680F5B00A75B9A;
402 403
 					};
403 404
 					E58D261A238587F4003F36BA = {
404 405
 						CreatedOnToolsVersion = 11.2.1;
405 406
 						DevelopmentTeam = S3GLW74Y8N;
406 407
 						ProvisioningStyle = Automatic;
408
+						TestTargetID = 13B07F861A680F5B00A75B9A;
407 409
 					};
408 410
 				};
409 411
 			};
@@ -892,6 +894,7 @@
892 894
 				PRODUCT_BUNDLE_IDENTIFIER = rn.NavigationIOS12Tests;
893 895
 				PRODUCT_NAME = "$(TARGET_NAME)";
894 896
 				TARGETED_DEVICE_FAMILY = "1,2";
897
+				TEST_HOST = "$(BUILT_PRODUCTS_DIR)/playground.app/playground";
895 898
 			};
896 899
 			name = Debug;
897 900
 		};
@@ -916,6 +919,7 @@
916 919
 				PRODUCT_BUNDLE_IDENTIFIER = rn.NavigationIOS12Tests;
917 920
 				PRODUCT_NAME = "$(TARGET_NAME)";
918 921
 				TARGETED_DEVICE_FAMILY = "1,2";
922
+				TEST_HOST = "$(BUILT_PRODUCTS_DIR)/playground.app/playground";
919 923
 			};
920 924
 			name = Release;
921 925
 		};
@@ -1026,6 +1030,7 @@
1026 1030
 			isa = XCBuildConfiguration;
1027 1031
 			baseConfigurationReference = 4259AF43A23D928FE78B4A3A /* Pods-NavigationTests.debug.xcconfig */;
1028 1032
 			buildSettings = {
1033
+				BUNDLE_LOADER = "$(TEST_HOST)";
1029 1034
 				CLANG_ANALYZER_NONNULL = YES;
1030 1035
 				CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
1031 1036
 				CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
@@ -1044,6 +1049,7 @@
1044 1049
 				PRODUCT_BUNDLE_IDENTIFIER = com.wix.NavigationTests;
1045 1050
 				PRODUCT_NAME = "$(TARGET_NAME)";
1046 1051
 				TARGETED_DEVICE_FAMILY = "1,2";
1052
+				TEST_HOST = "$(BUILT_PRODUCTS_DIR)/playground.app/playground";
1047 1053
 			};
1048 1054
 			name = Debug;
1049 1055
 		};
@@ -1051,6 +1057,7 @@
1051 1057
 			isa = XCBuildConfiguration;
1052 1058
 			baseConfigurationReference = D95A99C17C65D674BA9DF26B /* Pods-NavigationTests.release.xcconfig */;
1053 1059
 			buildSettings = {
1060
+				BUNDLE_LOADER = "$(TEST_HOST)";
1054 1061
 				CLANG_ANALYZER_NONNULL = YES;
1055 1062
 				CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
1056 1063
 				CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
@@ -1069,6 +1076,7 @@
1069 1076
 				PRODUCT_BUNDLE_IDENTIFIER = com.wix.NavigationTests;
1070 1077
 				PRODUCT_NAME = "$(TARGET_NAME)";
1071 1078
 				TARGETED_DEVICE_FAMILY = "1,2";
1079
+				TEST_HOST = "$(BUILT_PRODUCTS_DIR)/playground.app/playground";
1072 1080
 			};
1073 1081
 			name = Release;
1074 1082
 		};