diff --git a/lib/ios/RNNBackButtonOptions.h b/lib/ios/RNNBackButtonOptions.h index 3022e4c59e3..184ee6e8149 100644 --- a/lib/ios/RNNBackButtonOptions.h +++ b/lib/ios/RNNBackButtonOptions.h @@ -7,6 +7,7 @@ @property (nonatomic, strong) Text* fontFamily; @property (nonatomic, strong) Number* fontSize; @property (nonatomic, strong) Text* transition; +@property (nonatomic, strong) Text* testID; @property (nonatomic, strong) Color* color; @property (nonatomic, strong) Bool* showTitle; @property (nonatomic, strong) Bool* visible; diff --git a/lib/ios/RNNBackButtonOptions.m b/lib/ios/RNNBackButtonOptions.m index 44ca09a42da..5737d2a7383 100644 --- a/lib/ios/RNNBackButtonOptions.m +++ b/lib/ios/RNNBackButtonOptions.m @@ -11,6 +11,7 @@ - (instancetype)initWithDict:(NSDictionary *)dict { self.color = [ColorParser parse:dict key:@"color"]; self.showTitle = [BoolParser parse:dict key:@"showTitle"]; self.visible = [BoolParser parse:dict key:@"visible"]; + self.testID = [TextParser parse:dict key:@"testID"]; self.fontFamily = [TextParser parse:dict key:@"fontFamily"]; self.fontSize = [NumberParser parse:dict key:@"fontSize"]; diff --git a/lib/ios/TopBarPresenter.m b/lib/ios/TopBarPresenter.m index f79aba56796..c94443c63e1 100644 --- a/lib/ios/TopBarPresenter.m +++ b/lib/ios/TopBarPresenter.m @@ -16,7 +16,7 @@ - (void)applyOptions:(RNNTopBarOptions *)options { [self setTitleAttributes:options.title]; [self setLargeTitleAttributes:options.largeTitle]; [self showBorder:![options.noBorder getWithDefaultValue:NO]]; - [self setBackButtonOptions:[options.backButton.icon getWithDefaultValue:nil] withColor:[options.backButton.color getWithDefaultValue:nil] title:[options.backButton.title getWithDefaultValue:nil] showTitle:[options.backButton.showTitle getWithDefaultValue:YES] fontFamily:[options.backButton.fontFamily getWithDefaultValue:nil] fontSize:[options.backButton.fontSize getWithDefaultValue:nil]]; + [self setBackButtonOptions:options.backButton]; } - (void)applyOptionsBeforePopping:(RNNTopBarOptions *)options { @@ -48,7 +48,7 @@ - (void)mergeOptions:(RNNTopBarOptions *)options withDefault:(RNNTopBarOptions * } if (options.backButton.hasValue) { - [self setBackButtonOptions:[withDefault.backButton.icon getWithDefaultValue:nil] withColor:[withDefault.backButton.color getWithDefaultValue:nil] title:[withDefault.backButton.title getWithDefaultValue:nil] showTitle:[withDefault.backButton.showTitle getWithDefaultValue:YES] fontFamily:[withDefault.backButton.fontFamily getWithDefaultValue:nil] fontSize:[options.backButton.fontSize getWithDefaultValue:nil]]; + [self setBackButtonOptions:withDefault.backButton]; } } @@ -111,8 +111,18 @@ - (void)setLargeTitleAttributes:(RNNLargeTitleOptions *)largeTitleOptions { } } -- (void)setBackButtonOptions:(UIImage *)icon withColor:(UIColor *)color title:(NSString *)title showTitle:(BOOL)showTitle fontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize { +- (void)setBackButtonOptions:(RNNBackButtonOptions *)backButtonOptions { + UIImage* icon = [backButtonOptions.icon getWithDefaultValue:nil]; + UIColor* color = [backButtonOptions.color getWithDefaultValue:nil]; + NSString* title = [backButtonOptions.title getWithDefaultValue:nil]; + BOOL showTitle = [backButtonOptions.showTitle getWithDefaultValue:YES]; + NSString* fontFamily = [backButtonOptions.fontFamily getWithDefaultValue:nil]; + NSNumber* fontSize = [backButtonOptions.fontSize getWithDefaultValue:nil]; + NSString* testID = [backButtonOptions.testID getWithDefaultValue:nil]; + UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init]; + backItem.accessibilityIdentifier = testID; + NSArray* stackChildren = self.navigationController.viewControllers; icon = color ? [[icon withTintColor:color] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] diff --git a/lib/src/interfaces/Options.ts b/lib/src/interfaces/Options.ts index faf0e63390e..1db7168e90c 100644 --- a/lib/src/interfaces/Options.ts +++ b/lib/src/interfaces/Options.ts @@ -272,6 +272,10 @@ export interface OptionsTopBarBackButton { * Set subtitle font family */ fontFamily?: FontFamily; + /** + * Set testID for reference in E2E tests + */ + testID?: string; } export interface OptionsTopBarBackground { diff --git a/playground/ios/NavigationTests/TopBarAppearancePresenterTest.m b/playground/ios/NavigationTests/TopBarAppearancePresenterTest.m index 0639deb292b..8716046f9ed 100644 --- a/playground/ios/NavigationTests/TopBarAppearancePresenterTest.m +++ b/playground/ios/NavigationTests/TopBarAppearancePresenterTest.m @@ -3,6 +3,7 @@ #import #import "UIViewController+RNNOptions.h" #import +#import @interface TopBarAppearancePresenterTest : XCTestCase @@ -11,11 +12,13 @@ @interface TopBarAppearancePresenterTest : XCTestCase @implementation TopBarAppearancePresenterTest { TopBarAppearancePresenter* _uut; RNNStackController* _stack; + RNNComponentViewController* _componentViewController; } - (void)setUp { [super setUp]; - _stack = [[RNNStackController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions] presenter:_uut eventEmitter:nil childViewControllers:@[]]; + _componentViewController = [[RNNComponentViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil]; + _stack = [[RNNStackController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions] presenter:_uut eventEmitter:nil childViewControllers:@[_componentViewController]]; _uut = [[TopBarAppearancePresenter alloc] initWithNavigationController:_stack]; } @@ -32,5 +35,14 @@ - (void)testMergeOptions_shouldMergeWithDefault { XCTAssertEqual(font.pointSize, 21); } +- (void)testApplyOptions_shouldSetBackButtonTestID { + RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions]; + options.topBar.backButton.testID = [Text withValue:@"TestID"]; + + [_uut applyOptions:options.topBar]; + XCTAssertTrue([_componentViewController.navigationItem.backBarButtonItem.accessibilityIdentifier isEqualToString:@"TestID"]); +} + + @end