Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add topBar.backButton.testID option #5993

Merged
merged 6 commits into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/ios/RNNBackButtonOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions lib/ios/RNNBackButtonOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"];

Expand Down
16 changes: 13 additions & 3 deletions lib/ios/TopBarPresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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];
}
}

Expand Down Expand Up @@ -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]
Expand Down
4 changes: 4 additions & 0 deletions lib/src/interfaces/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 13 additions & 1 deletion playground/ios/NavigationTests/TopBarAppearancePresenterTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#import <ReactNativeNavigation/TopBarAppearancePresenter.h>
#import "UIViewController+RNNOptions.h"
#import <ReactNativeNavigation/RNNStackController.h>
#import <ReactNativeNavigation/RNNComponentViewController.h>

@interface TopBarAppearancePresenterTest : XCTestCase

Expand All @@ -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];
}

Expand All @@ -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