diff --git a/lib/ios/RNNStackController.m b/lib/ios/RNNStackController.m index 8bb188abc32..61eac7c931e 100644 --- a/lib/ios/RNNStackController.m +++ b/lib/ios/RNNStackController.m @@ -12,6 +12,7 @@ - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo creator:(id 1 ? stackChildren[stackChildren.count - 2] : self.navigationController.topViewController; + UIBarButtonItem *backItem = lastViewControllerInStack.navigationItem.backBarButtonItem ?: [UIBarButtonItem new]; + backItem.accessibilityIdentifier = testID; + icon = color ? [[icon withTintColor:color] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] : icon; [self setBackIndicatorImage:icon withColor:color]; - UIViewController *lastViewControllerInStack = stackChildren.count > 1 ? stackChildren[stackChildren.count - 2] : self.navigationController.topViewController; - if (showTitle) { backItem.title = title ? title : lastViewControllerInStack.navigationItem.title; + } else { + backItem.title = @""; } + backItem.tintColor = color; if (fontFamily) { diff --git a/lib/ios/UINavigationController+RNNOptions.h b/lib/ios/UINavigationController+RNNOptions.h index 629361baf24..a928789231f 100644 --- a/lib/ios/UINavigationController+RNNOptions.h +++ b/lib/ios/UINavigationController+RNNOptions.h @@ -16,8 +16,6 @@ - (void)setNavigationBarClipsToBounds:(BOOL)clipsToBounds; -- (void)setNavigationBarLargeTitleVisible:(BOOL)visible; - - (void)setBackButtonColor:(UIColor *)color; @end diff --git a/lib/ios/UINavigationController+RNNOptions.m b/lib/ios/UINavigationController+RNNOptions.m index d48d3491254..863cdaa7eef 100644 --- a/lib/ios/UINavigationController+RNNOptions.m +++ b/lib/ios/UINavigationController+RNNOptions.m @@ -33,16 +33,6 @@ - (void)setBarStyle:(UIBarStyle)barStyle { self.navigationBar.barStyle = barStyle; } -- (void)setNavigationBarLargeTitleVisible:(BOOL)visible { - if (@available(iOS 11.0, *)) { - if (visible){ - self.navigationBar.prefersLargeTitles = YES; - } else { - self.navigationBar.prefersLargeTitles = NO; - } - } -} - - (void)setNavigationBarBlur:(BOOL)blur { if (blur && ![self.navigationBar viewWithTag:BLUR_TOPBAR_TAG]) { [self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; diff --git a/playground/ios/NavigationTests/RNNStackControllerTest.m b/playground/ios/NavigationTests/RNNStackControllerTest.m index 3e7805ee718..b62a02caeab 100644 --- a/playground/ios/NavigationTests/RNNStackControllerTest.m +++ b/playground/ios/NavigationTests/RNNStackControllerTest.m @@ -38,6 +38,10 @@ - (void)testInitWithLayoutInfo_shouldBindPresenter { XCTAssertNotNil(self.uut.presenter); } +- (void)testInitWithLayoutInfo_shouldPreferLargeTitle { + XCTAssertTrue(self.uut.navigationBar.prefersLargeTitles); +} + - (void)testInitWithLayoutInfo_shouldSetMultipleViewControllers { self.uut = [[RNNStackController alloc] initWithLayoutInfo:nil creator:_creator options:[[RNNNavigationOptions alloc] initWithDict:@{}] defaultOptions:nil presenter:[[RNNComponentPresenter alloc] init] eventEmitter:nil childViewControllers:@[_vc1, _vc2]]; XCTAssertTrue(self.uut.viewControllers.count == 2); diff --git a/playground/ios/NavigationTests/RNNStackPresenterTest.m b/playground/ios/NavigationTests/RNNStackPresenterTest.m index 21f01335e81..e4e955d082d 100644 --- a/playground/ios/NavigationTests/RNNStackPresenterTest.m +++ b/playground/ios/NavigationTests/RNNStackPresenterTest.m @@ -44,19 +44,13 @@ - (void)testApplyOptionsBeforePoppingShouldSetTopBarBackgroundForPoppingViewCont XCTAssertTrue([_boundViewController.navigationBar.standardAppearance.backgroundColor isEqual:[UIColor redColor]]); } -- (void)testApplyOptionsBeforePoppingShouldSetLargeTitleForPoppingViewController { +- (void)testApplyOptionsShouldSetLargeTitleVisible { _options.topBar.largeTitle.visible = [[Bool alloc] initWithBOOL:YES]; - [self.uut applyOptionsBeforePopping:self.options]; + [self.uut applyOptions:self.options]; XCTAssertTrue([[_boundViewController navigationBar] prefersLargeTitles]); } -- (void)testApplyOptionsBeforePoppingShouldSetDefaultLargeTitleFalseForPoppingViewController { - _options.topBar.largeTitle.visible = nil; - [self.uut applyOptionsBeforePopping:self.options]; - XCTAssertFalse([[_boundViewController navigationBar] prefersLargeTitles]); -} - - (void)testApplyOptions_shouldSetBackButtonOnBoundViewController_withTitle { Text* title = [[Text alloc] initWithValue:@"Title"]; self.options.topBar.backButton.title = title; @@ -69,7 +63,8 @@ - (void)testApplyOptions_shouldSetBackButtonOnBoundViewController_withHideTitle self.options.topBar.backButton.title = title; self.options.topBar.backButton.showTitle = [[Bool alloc] initWithValue:@(0)]; [self.uut applyOptions:self.options]; - XCTAssertNil(self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.title); + NSLog(@"%@", self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.title); + XCTAssertTrue([self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.title isEqualToString:@""]); } - (void)testApplyOptions_shouldSetBackButtonOnBoundViewController_withDefaultValues { diff --git a/playground/ios/playground.xcodeproj/project.pbxproj b/playground/ios/playground.xcodeproj/project.pbxproj index 2e87bb296e8..483f18bc33f 100644 --- a/playground/ios/playground.xcodeproj/project.pbxproj +++ b/playground/ios/playground.xcodeproj/project.pbxproj @@ -815,6 +815,7 @@ DEAD_CODE_STRIPPING = NO; DEVELOPMENT_TEAM = XPHGA2FMQQ; INFOPLIST_FILE = playground/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; OTHER_LDFLAGS = ( "$(inherited)", @@ -838,6 +839,7 @@ CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = XPHGA2FMQQ; INFOPLIST_FILE = playground/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; OTHER_LDFLAGS = ( "$(inherited)",