Skip to content

Commit

Permalink
Merge options with correct child (#6041)
Browse files Browse the repository at this point in the history
Co-authored-by: Guy Carmeli <guyca@users.noreply.github.com>
  • Loading branch information
yogevbd and guyca authored Mar 16, 2020
1 parent ba12604 commit 3c38c50
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 31 deletions.
4 changes: 2 additions & 2 deletions lib/ios/RNNBottomTabsController.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ - (void)onChildAddToParent:(UIViewController *)child options:(RNNNavigationOptio

- (void)mergeChildOptions:(RNNNavigationOptions *)options child:(UIViewController *)child {
[super mergeChildOptions:options child:child];
[_bottomTabPresenter mergeOptions:options resolvedOptions:self.resolveOptions child:[self findViewController:child]];
[_dotIndicatorPresenter mergeOptions:options resolvedOptions:self.resolveOptions child:[self findViewController:child]];
[_bottomTabPresenter mergeOptions:options resolvedOptions:child.resolveOptions child:[self findViewController:child]];
[_dotIndicatorPresenter mergeOptions:options resolvedOptions:child.resolveOptions child:[self findViewController:child]];
}

- (id<UITabBarControllerDelegate>)delegate {
Expand Down
65 changes: 42 additions & 23 deletions playground/ios/NavigationTests/RNNCommandsHandlerTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,8 @@
#import "RNNLayoutManager.h"
#import "RNNBottomTabsController.h"
#import "BottomTabsAttachModeFactory.h"

@interface MockUIApplication : NSObject

-(UIWindow *)keyWindow;

@end

@implementation MockUIApplication

- (UIWindow *)keyWindow {
return [UIWindow new];
}

@end
#import <ReactNativeNavigation/BottomTabPresenterCreator.h>
#import "RNNComponentViewController+Utils.h"

@interface MockUINavigationController : RNNStackController
@property (nonatomic, strong) NSArray* willReturnVCs;
Expand Down Expand Up @@ -62,7 +50,6 @@ @implementation RNNCommandsHandlerTest

- (void)setUp {
[super setUp];
self.sharedApplication = [OCMockObject mockForClass:[UIApplication class]];
self.creator = [OCMockObject partialMockForObject:[RNNTestRootViewCreator new]];
self.mainWindow = [OCMockObject partialMockForObject:[UIWindow new]];
self.eventEmmiter = [OCMockObject partialMockForObject:[RNNEventEmitter new]];
Expand All @@ -75,7 +62,12 @@ - (void)setUp {
self.vc3 = [self generateComponentWithComponentId:@"3"];
_nvc = [[MockUINavigationController alloc] init];
[_nvc setViewControllers:@[self.vc1, self.vc2, self.vc3]];
OCMStub([self.sharedApplication keyWindow]).andReturn(self.mainWindow);

UIApplication* sharedApplication = [OCMockObject niceMockForClass:[UIApplication class]];
id mockedApplicationClass = OCMClassMock([UIApplication class]);
OCMStub(ClassMethod([mockedApplicationClass sharedApplication])).andReturn(sharedApplication);
OCMStub(sharedApplication.keyWindow).andReturn(self.mainWindow);
OCMStub([sharedApplication windows]).andReturn(@[self.mainWindow]);
}

- (RNNComponentViewController *)generateComponentWithComponentId:(NSString *)componentId {
Expand Down Expand Up @@ -129,14 +121,11 @@ - (NSArray*)getPublicMethodNamesForObject:(NSObject*)obj {
-(void)testDynamicStylesMergeWithStaticStyles {
RNNNavigationOptions* initialOptions = [[RNNNavigationOptions alloc] initWithDict:@{}];
initialOptions.topBar.title.text = [[Text alloc] initWithValue:@"the title"];
RNNLayoutInfo* layoutInfo = [RNNLayoutInfo new];
RNNTestRootViewCreator* creator = [[RNNTestRootViewCreator alloc] init];

RNNComponentPresenter* presenter = [[RNNComponentPresenter alloc] initWithComponentRegistry:nil defaultOptions:nil];
RNNComponentViewController* vc = [[RNNComponentViewController alloc] initWithLayoutInfo:layoutInfo rootViewCreator:creator eventEmitter:nil presenter:presenter options:initialOptions defaultOptions:nil];
RNNComponentViewController* vc = [RNNComponentViewController createWithComponentId:@"componentId" initialOptions:initialOptions];

RNNStackController* nav = [[RNNStackController alloc] initWithLayoutInfo:nil creator:creator options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:[[RNNStackPresenter alloc] init] eventEmitter:nil childViewControllers:@[vc]];

[self.mainWindow setRootViewController:nav];
[vc viewWillAppear:false];
XCTAssertTrue([vc.navigationItem.title isEqual:@"the title"]);

Expand All @@ -146,9 +135,11 @@ -(void)testDynamicStylesMergeWithStaticStyles {
UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];

[self.uut mergeOptions:@"componentId" options:dictFromJs completion:^{
XCTAssertTrue([vc.navigationItem.title isEqual:@"the title"]);
XCTAssertTrue([nav.navigationBar.barTintColor isEqual:expectedColor]);

}];

XCTAssertTrue([vc.navigationItem.title isEqual:@"the title"]);
XCTAssertTrue([vc.navigationItem.standardAppearance.backgroundColor isEqual:expectedColor]);
}

- (void)testMergeOptions_shouldOverrideOptions {
Expand Down Expand Up @@ -420,6 +411,34 @@ - (void)testSetRoot_withBottomTabsAttachModeAfterInitialTab {
XCTAssertTrue(_vc2.isViewLoaded);
}

- (void)testMergeOptions_shouldMergeWithChildOnly {
[self.uut setReadyToReceiveCommands:true];
NSDictionary* mergeOptions = @{@"bottomTab": @{@"badge": @"Badge"}};

RNNNavigationOptions* firstChildOptions = [RNNNavigationOptions emptyOptions];
firstChildOptions.bottomTab.text = [Text withValue:@"First"];
RNNNavigationOptions* secondChildOptions = [RNNNavigationOptions emptyOptions];
secondChildOptions.bottomTab.text = [Text withValue:@"Second"];

RNNComponentViewController* firstChild = [RNNComponentViewController createWithComponentId:@"first" initialOptions:firstChildOptions];
RNNComponentViewController* secondChild = [RNNComponentViewController createWithComponentId:@"second" initialOptions:secondChildOptions];

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];

OCMStub([self.controllerFactory createLayout:[OCMArg any]]).andReturn(tabBarController);
[self.mainWindow setRootViewController:tabBarController];
[secondChild viewWillAppear:YES];

[self.uut mergeOptions:secondChild.layoutInfo.componentId options:mergeOptions completion:^{

}];

XCTAssertTrue([secondChild.tabBarItem.badgeValue isEqualToString:@"Badge"]);
XCTAssertNil(firstChild.tabBarItem.badgeValue);
XCTAssertTrue([firstChild.tabBarItem.title isEqualToString:@"First"]);
XCTAssertTrue([secondChild.tabBarItem.title isEqualToString:@"Second"]);
}

- (void)testShowModal_shouldShowAnimated {
[self.uut setReadyToReceiveCommands:true];
self.vc1.options = [[RNNNavigationOptions alloc] initEmptyOptions];
Expand Down
2 changes: 1 addition & 1 deletion playground/ios/NavigationTests/RNNLayoutManagerTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ - (void)setUp {
_secondWindow = [[UIWindow alloc] init];
NSArray* windows = @[_firstWindow, _secondWindow];

UIApplication* sharedApplication = [OCMockObject mockForClass:[UIApplication class]];
UIApplication* sharedApplication = [OCMockObject niceMockForClass:[UIApplication class]];
id mockedApplicationClass = OCMClassMock([UIApplication class]);
OCMStub(ClassMethod([mockedApplicationClass sharedApplication])).andReturn(sharedApplication);
OCMStub(sharedApplication.keyWindow).andReturn(_firstWindow);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@

+ (RNNComponentViewController *)createWithComponentId:(NSString *)componentId;

+ (RNNComponentViewController *)createWithComponentId:(NSString *)componentId initialOptions:(RNNNavigationOptions *)initialOptions;

@end
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#import "RNNComponentViewController+Utils.h"
#import "RNNTestRootViewCreator.h"

@implementation RNNComponentViewController (Utils)

+ (RNNComponentViewController *)createWithComponentId:(NSString *)componentId {
+ (RNNComponentViewController *)createWithComponentId:(NSString *)componentId initialOptions:(RNNNavigationOptions *)initialOptions {
RNNLayoutInfo* layoutInfo = [[RNNLayoutInfo alloc] init];
layoutInfo.componentId = componentId;
return [[RNNComponentViewController alloc] initWithLayoutInfo:layoutInfo rootViewCreator:nil eventEmitter:nil presenter:nil options:nil defaultOptions:nil];
return [[RNNComponentViewController alloc] initWithLayoutInfo:layoutInfo rootViewCreator:[[RNNTestRootViewCreator alloc] init] eventEmitter:nil presenter:[[RNNComponentPresenter alloc] initWithComponentRegistry:nil defaultOptions:nil] options:initialOptions defaultOptions:nil];
}

+ (RNNComponentViewController *)createWithComponentId:(NSString *)componentId {
return [self createWithComponentId:componentId initialOptions:nil];
}

@end
14 changes: 11 additions & 3 deletions playground/ios/playground.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
50996C6923AA487800008F89 /* RNNTestRootViewCreator.m in Sources */ = {isa = PBXBuildFile; fileRef = E58D263D2385888C003F36BA /* RNNTestRootViewCreator.m */; };
50BCB27623F1A2B100D6C8E5 /* TopBarAppearancePresenterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 50BCB27523F1A26600D6C8E5 /* TopBarAppearancePresenterTest.m */; };
50C9A8D1240EB95F00BD699F /* RNNBottomTabsController+Helpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 50CF233C240695B10098042D /* RNNBottomTabsController+Helpers.m */; };
50CF233D240695B10098042D /* RNNBottomTabsController+Helpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 50CF233C240695B10098042D /* RNNBottomTabsController+Helpers.m */; };
50C9A8D4240FB9D000BD699F /* RNNComponentViewController+Utils.m in Sources */ = {isa = PBXBuildFile; fileRef = 50C9A8D3240FB9D000BD699F /* RNNComponentViewController+Utils.m */; };
50CF233D240695B10098042D /* RNNBottomTabsController+Helpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 50CF233C240695B10098042D /* RNNBottomTabsController+Helpers.m */; };
67C681D42B662A53F29C19DA /* Pods_NavigationIOS12Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DEE0B5D45FD34FBABC6586CF /* Pods_NavigationIOS12Tests.framework */; };
9D204F3DC4FBCD81583BF99F /* Pods_playground.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4A3340545EAAF11C1F146864 /* Pods_playground.framework */; };
E5046080227748EA00212BD8 /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E504607F227748EA00212BD8 /* JavaScriptCore.framework */; };
Expand Down Expand Up @@ -97,10 +97,10 @@
50996C6123AA46DD00008F89 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
50996C6723AA477400008F89 /* RNNRootViewControllerTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNRootViewControllerTest.m; sourceTree = "<group>"; };
50BCB27523F1A26600D6C8E5 /* TopBarAppearancePresenterTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TopBarAppearancePresenterTest.m; sourceTree = "<group>"; };
50CF233B240695B10098042D /* RNNBottomTabsController+Helpers.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RNNBottomTabsController+Helpers.h"; sourceTree = "<group>"; };
50CF233C240695B10098042D /* RNNBottomTabsController+Helpers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "RNNBottomTabsController+Helpers.m"; sourceTree = "<group>"; };
50C9A8D2240FB9D000BD699F /* RNNComponentViewController+Utils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RNNComponentViewController+Utils.h"; sourceTree = "<group>"; };
50C9A8D3240FB9D000BD699F /* RNNComponentViewController+Utils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "RNNComponentViewController+Utils.m"; sourceTree = "<group>"; };
50CF233B240695B10098042D /* RNNBottomTabsController+Helpers.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RNNBottomTabsController+Helpers.h"; sourceTree = "<group>"; };
50CF233C240695B10098042D /* RNNBottomTabsController+Helpers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "RNNBottomTabsController+Helpers.m"; sourceTree = "<group>"; };
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>"; };
84E32151E3A71C2B7328BCB4 /* Pods_NavigationTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_NavigationTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
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>"; };
Expand Down Expand Up @@ -399,11 +399,13 @@
50996C5C23AA46DD00008F89 = {
CreatedOnToolsVersion = 11.2.1;
ProvisioningStyle = Automatic;
TestTargetID = 13B07F861A680F5B00A75B9A;
};
E58D261A238587F4003F36BA = {
CreatedOnToolsVersion = 11.2.1;
DevelopmentTeam = S3GLW74Y8N;
ProvisioningStyle = Automatic;
TestTargetID = 13B07F861A680F5B00A75B9A;
};
};
};
Expand Down Expand Up @@ -892,6 +894,7 @@
PRODUCT_BUNDLE_IDENTIFIER = rn.NavigationIOS12Tests;
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/playground.app/playground";
};
name = Debug;
};
Expand All @@ -916,6 +919,7 @@
PRODUCT_BUNDLE_IDENTIFIER = rn.NavigationIOS12Tests;
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/playground.app/playground";
};
name = Release;
};
Expand Down Expand Up @@ -1026,6 +1030,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 4259AF43A23D928FE78B4A3A /* Pods-NavigationTests.debug.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
Expand All @@ -1044,13 +1049,15 @@
PRODUCT_BUNDLE_IDENTIFIER = com.wix.NavigationTests;
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/playground.app/playground";
};
name = Debug;
};
E58D2623238587F4003F36BA /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = D95A99C17C65D674BA9DF26B /* Pods-NavigationTests.release.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
Expand All @@ -1069,6 +1076,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.wix.NavigationTests;
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/playground.app/playground";
};
name = Release;
};
Expand Down

0 comments on commit 3c38c50

Please sign in to comment.