diff --git a/lib/ios/RNNNavigationController.m b/lib/ios/RNNNavigationController.m index d7360da7a45..7a5d45b8662 100644 --- a/lib/ios/RNNNavigationController.m +++ b/lib/ios/RNNNavigationController.m @@ -59,16 +59,16 @@ - (UIViewController *)childViewControllerForStatusBarStyle { - (void)setViewControllers:(NSArray<__kindof UIViewController *> *)viewControllers { [super setViewControllers:viewControllers]; - for (UIViewController* viewController in viewControllers) { - if (viewController.layoutInfo.options) { - [viewController.layoutInfo.options mergeOptions:self.layoutInfo.options overrideOptions:NO]; - } - } + for (UIViewController* viewController in viewControllers) { + if ([viewController respondsToSelector:@selector(layoutInfo)]) { + [viewController.layoutInfo.options mergeOptions:self.layoutInfo.options overrideOptions:NO]; + } + } } - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated { [super pushViewController:viewController animated:animated]; - if (viewController.layoutInfo.options) { + if ([viewController respondsToSelector:@selector(layoutInfo)]) { [viewController.layoutInfo.options mergeOptions:self.layoutInfo.options overrideOptions:NO]; } } diff --git a/lib/ios/RNNOptions.m b/lib/ios/RNNOptions.m index 52aaac07e5d..df9793859d0 100644 --- a/lib/ios/RNNOptions.m +++ b/lib/ios/RNNOptions.m @@ -4,7 +4,7 @@ @implementation RNNOptions --(instancetype) initWithDict:(NSDictionary *)dict { +- (instancetype)initWithDict:(NSDictionary *)dict { self = [super init]; [self initializeOptionsPropertiesWithDict:dict]; diff --git a/lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj b/lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj index 8eaed6cbab1..bffef9b0b82 100644 --- a/lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj +++ b/lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj @@ -98,6 +98,7 @@ 50570B272061473D006A1B5C /* RNNTitleOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 50570B252061473D006A1B5C /* RNNTitleOptions.m */; }; 50570BEA2063E09B006A1B5C /* RNNTitleViewHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 50570BE82063E09B006A1B5C /* RNNTitleViewHelper.h */; }; 50570BEB2063E09B006A1B5C /* RNNTitleViewHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 50570BE92063E09B006A1B5C /* RNNTitleViewHelper.m */; }; + 505EDD32214E4BE80071C7DE /* RNNNavigationControllerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 505EDD31214E4BE80071C7DE /* RNNNavigationControllerTest.m */; }; 5064495D20DC62B90026709C /* RNNSideMenuSideOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 5064495B20DC62B90026709C /* RNNSideMenuSideOptions.h */; }; 5064495E20DC62B90026709C /* RNNSideMenuSideOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 5064495C20DC62B90026709C /* RNNSideMenuSideOptions.m */; }; 50644A2020E11A720026709C /* Constants.h in Headers */ = {isa = PBXBuildFile; fileRef = 50644A1E20E11A720026709C /* Constants.h */; }; @@ -329,6 +330,7 @@ 50570B252061473D006A1B5C /* RNNTitleOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNTitleOptions.m; sourceTree = ""; }; 50570BE82063E09B006A1B5C /* RNNTitleViewHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNTitleViewHelper.h; sourceTree = ""; }; 50570BE92063E09B006A1B5C /* RNNTitleViewHelper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNTitleViewHelper.m; sourceTree = ""; }; + 505EDD31214E4BE80071C7DE /* RNNNavigationControllerTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNNavigationControllerTest.m; sourceTree = ""; }; 5064495B20DC62B90026709C /* RNNSideMenuSideOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNSideMenuSideOptions.h; sourceTree = ""; }; 5064495C20DC62B90026709C /* RNNSideMenuSideOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNSideMenuSideOptions.m; sourceTree = ""; }; 50644A1E20E11A720026709C /* Constants.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Constants.h; sourceTree = ""; }; @@ -712,6 +714,7 @@ 7B49FEC91E95098500DEB3EA /* RNNCommandsHandlerTest.m */, 7B49FECA1E95098500DEB3EA /* RNNNavigationStackManagerTest.m */, 504753772109C13C00FFFBE6 /* RNNOverlayManagerTest.m */, + 505EDD31214E4BE80071C7DE /* RNNNavigationControllerTest.m */, 7B49FEBF1E95090800DEB3EA /* Info.plist */, E83BAD671F2734B500A9F3DD /* RNNNavigationOptionsTest.m */, E83BAD781F27416B00A9F3DD /* RNNRootViewControllerTest.m */, @@ -1026,6 +1029,7 @@ 504753782109C13C00FFFBE6 /* RNNOverlayManagerTest.m in Sources */, 7B49FECE1E95098500DEB3EA /* RNNCommandsHandlerTest.m in Sources */, E83BAD681F2734B500A9F3DD /* RNNNavigationOptionsTest.m in Sources */, + 505EDD32214E4BE80071C7DE /* RNNNavigationControllerTest.m in Sources */, 7B49FECF1E95098500DEB3EA /* RNNNavigationStackManagerTest.m in Sources */, 7B49FECB1E95098500DEB3EA /* RNNControllerFactoryTest.m in Sources */, 7B49FECD1E95098500DEB3EA /* RNNModalManagerTest.m in Sources */, diff --git a/lib/ios/ReactNativeNavigationTests/RNNNavigationControllerTest.m b/lib/ios/ReactNativeNavigationTests/RNNNavigationControllerTest.m new file mode 100644 index 00000000000..d87cb2bc85e --- /dev/null +++ b/lib/ios/ReactNativeNavigationTests/RNNNavigationControllerTest.m @@ -0,0 +1,68 @@ +#import +#import "RNNNavigationController.h" + +@interface RNNNavigationControllerTest : XCTestCase + +@property (nonatomic, strong) RNNNavigationController *uut; + +@end + +@implementation RNNNavigationControllerTest { + RNNRootViewController* _vc1; + RNNRootViewController* _vc2; + UIViewController* _vc3; +} + +- (void)setUp { + [super setUp]; + + self.uut = [[RNNNavigationController alloc] initWithLayoutInfo:[self createLayoutInfo]]; + _vc1 = [[RNNRootViewController alloc] init]; + _vc1.layoutInfo = [self createLayoutInfo]; + _vc2 = [[RNNRootViewController alloc] init]; + _vc2.layoutInfo = [self createLayoutInfo]; + _vc3 = [UIViewController new]; +} + +- (void)testSetViewControllers_shouldPropogateOptionsToViewController { + self.uut.layoutInfo.options.topBar.visible = @(1); + [self.uut setViewControllers:@[_vc1]]; + XCTAssertTrue(_vc1.layoutInfo.options.topBar.visible.boolValue == self.uut.layoutInfo.options.topBar.visible.boolValue); +} + +- (void)testSetViewControllers_externalViewControllerShouldNotCrash { + NSArray* viewControllers = @[_vc1, _vc3]; + XCTAssertNoThrow([self.uut setViewControllers:viewControllers]); +} + +- (void)testPushViewController_shouldPropogateOptionsToViewController { + self.uut.layoutInfo.options.topBar.visible = @(1); + [self.uut pushViewController:_vc2 animated:NO]; + XCTAssertTrue(_vc2.layoutInfo.options.topBar.visible.boolValue == self.uut.layoutInfo.options.topBar.visible.boolValue); +} + +- (void)testPushViewController_externalViewControllerShouldNotCrash { + XCTAssertNoThrow([self.uut pushViewController:_vc3 animated:NO]); +} + +- (void)testChildViewControllerForStatusBarStyle_shouldReturnTopViewController { + XCTAssertTrue(self.uut.childViewControllerForStatusBarStyle == self.uut.topViewController); +} + +- (void)testGetLeafViewController_shouldReturnTopViewController { + XCTAssertTrue(self.uut.getLeafViewController == self.uut.topViewController); +} + +- (void)testPreferredStatusBarStyle_shouldReturnLeafPreferredStatusBarStyle { + [self.uut setViewControllers:@[_vc1]]; + self.uut.getLeafViewController.layoutInfo.options.statusBar.style = @"dark"; + XCTAssertTrue(self.uut.preferredStatusBarStyle == self.uut.getLeafViewController.preferredStatusBarStyle); +} + +- (RNNLayoutInfo *)createLayoutInfo { + RNNLayoutInfo *layoutInfo = [RNNLayoutInfo new]; + layoutInfo.options = [[RNNNavigationOptions alloc] initWithDict:@{}]; + return layoutInfo; +} + +@end