Skip to content

Commit

Permalink
Allow reset topBar.title.color when color isn't provided (#5910)
Browse files Browse the repository at this point in the history
* Allow topBar.title.color reset when color isn't provided

* Reset to nil color

* Merge topBar options with default

* Fix topBar options merging

Co-authored-by: Guy Carmeli <guyca@users.noreply.github.com>
  • Loading branch information
yogevbd and guyca committed Feb 9, 2020
1 parent 0ee3145 commit d0149a1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/ios/RNNComponentPresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ - (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigat
rootView.passThroughTouches = !options.overlay.interceptTouchOutside.get;
}

[_topBarTitlePresenter mergeOptions:options.topBar resolvedOptions:currentOptions.topBar];
[_topBarTitlePresenter mergeOptions:options.topBar resolvedOptions:withDefault.topBar];
}

- (void)renderComponents:(RNNNavigationOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock {
Expand Down
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
9 changes: 8 additions & 1 deletion lib/ios/TopBarTitlePresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ - (void)updateTitleWithOptions:(RNNTopBarOptions *)options {
}

- (void)mergeOptions:(RNNTopBarOptions *)options resolvedOptions:(RNNTopBarOptions *)resolvedOptions {
[self updateTitleWithOptions:options];
if (options.title.component.hasValue) {
[self setCustomNavigationTitleView:resolvedOptions perform:nil];
} else if (options.subtitle.text.hasValue) {
[self setTitleViewWithSubtitle:resolvedOptions];
} else if (options.title.text.hasValue) {
[self removeTitleComponents];
self.boundViewController.navigationItem.title = resolvedOptions.title.text.get;
}
}

- (void)setTitleViewWithSubtitle:(RNNTopBarOptions *)options {
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

0 comments on commit d0149a1

Please sign in to comment.