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

Allow reset topBar.title.color when color isn't provided #5910

Merged
merged 6 commits into from
Feb 9, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 4 additions & 4 deletions lib/ios/RNNFontAttributesCreator.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ + (NSDictionary *)createFromDictionary:(NSDictionary *)attributesDictionary font
}

+ (NSDictionary *)createFromDictionary:(NSDictionary *)attributesDictionary fontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize fontWeight:(NSString *)fontWeight color:(UIColor *)color {
NSMutableDictionary* titleTextAttributes = [NSMutableDictionary dictionaryWithDictionary:attributesDictionary];\
NSMutableDictionary* titleTextAttributes = [NSMutableDictionary dictionaryWithDictionary:attributesDictionary];
UIFont* currentFont = attributesDictionary[NSFontAttributeName];

CGFloat resolvedFontSize = [self resolveFontSize:currentFont fontSize:fontSize];
if (color) {
titleTextAttributes[NSForegroundColorAttributeName] = color;
}

titleTextAttributes[NSForegroundColorAttributeName] = color;

if (fontWeight) {
titleTextAttributes[NSFontAttributeName] = [UIFont systemFontOfSize:resolvedFontSize weight:[RCTConvert UIFontWeight:fontWeight]];
} else if (fontFamily){
Expand Down
12 changes: 10 additions & 2 deletions playground/ios/NavigationTests/RNNFontAttributesCreatorTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,26 @@ - (void)testcreateFromDictionary_shouldCreateAttributes {
XCTAssertEqual(font.pointSize, fontSize.floatValue);
}

- (void)testcreateFromDictionary_shouldMergeWithDictionary {
- (void)testCreateFromDictionary_shouldMergeWithDictionary {
NSString* familyName = @"Helvetica";
NSNumber* fontSize = @(20);
NSDictionary* dictionary = @{NSForegroundColorAttributeName: UIColor.redColor};

NSDictionary* attributes = [RNNFontAttributesCreator createFromDictionary:dictionary fontFamily:familyName fontSize:fontSize defaultFontSize:nil fontWeight:nil color:nil defaultColor:nil];
UIFont* font = attributes[NSFontAttributeName];
XCTAssertEqual(attributes[NSForegroundColorAttributeName], UIColor.redColor);
XCTAssertTrue([familyName isEqualToString:font.familyName]);
XCTAssertEqual(font.pointSize, fontSize.floatValue);
}

- (void)testCreateFromDictionary_shouldOverrideColor {
NSString* familyName = @"Helvetica";
NSNumber* fontSize = @(20);
NSDictionary* dictionary = @{NSForegroundColorAttributeName: UIColor.redColor};

NSDictionary* attributes = [RNNFontAttributesCreator createFromDictionary:dictionary fontFamily:familyName fontSize:fontSize defaultFontSize:nil fontWeight:nil color:nil defaultColor:nil];
XCTAssertEqual(attributes[NSForegroundColorAttributeName], nil);
}

- (void)testCreateWithFontFamily_shouldNotChangeFontFamilyWhenOnlySizeAvailable {
NSNumber* fontSize = @(20);
UIFont* initialFont = [UIFont systemFontOfSize:10 weight:UIFontWeightHeavy];
Expand Down