Browse Source

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

* 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>
Yogev Ben David 5 years ago
parent
commit
115d5b8f54

+ 1
- 1
lib/ios/RNNComponentPresenter.m View File

159
 		rootView.passThroughTouches = !options.overlay.interceptTouchOutside.get;
159
 		rootView.passThroughTouches = !options.overlay.interceptTouchOutside.get;
160
 	}
160
 	}
161
 	
161
 	
162
-	[_topBarTitlePresenter mergeOptions:options.topBar resolvedOptions:currentOptions.topBar];
162
+	[_topBarTitlePresenter mergeOptions:options.topBar resolvedOptions:withDefault.topBar];
163
 }
163
 }
164
 
164
 
165
 - (void)renderComponents:(RNNNavigationOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock {
165
 - (void)renderComponents:(RNNNavigationOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock {

+ 4
- 4
lib/ios/RNNFontAttributesCreator.m View File

20
 }
20
 }
21
 
21
 
22
 + (NSDictionary *)createFromDictionary:(NSDictionary *)attributesDictionary fontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize fontWeight:(NSString *)fontWeight color:(UIColor *)color {
22
 + (NSDictionary *)createFromDictionary:(NSDictionary *)attributesDictionary fontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize fontWeight:(NSString *)fontWeight color:(UIColor *)color {
23
-	NSMutableDictionary* titleTextAttributes = [NSMutableDictionary dictionaryWithDictionary:attributesDictionary];\
23
+	NSMutableDictionary* titleTextAttributes = [NSMutableDictionary dictionaryWithDictionary:attributesDictionary];
24
     UIFont* currentFont = attributesDictionary[NSFontAttributeName];
24
     UIFont* currentFont = attributesDictionary[NSFontAttributeName];
25
     
25
     
26
 	CGFloat resolvedFontSize = [self resolveFontSize:currentFont fontSize:fontSize];
26
 	CGFloat resolvedFontSize = [self resolveFontSize:currentFont fontSize:fontSize];
27
-    if (color) {
28
-        titleTextAttributes[NSForegroundColorAttributeName] = color;
29
-    }
27
+    
28
+    titleTextAttributes[NSForegroundColorAttributeName] = color;
29
+    
30
     if (fontWeight) {
30
     if (fontWeight) {
31
         titleTextAttributes[NSFontAttributeName] = [UIFont systemFontOfSize:resolvedFontSize weight:[RCTConvert UIFontWeight:fontWeight]];
31
         titleTextAttributes[NSFontAttributeName] = [UIFont systemFontOfSize:resolvedFontSize weight:[RCTConvert UIFontWeight:fontWeight]];
32
     } else if (fontFamily){
32
     } else if (fontFamily){

+ 8
- 1
lib/ios/TopBarTitlePresenter.m View File

24
 }
24
 }
25
 
25
 
26
 - (void)mergeOptions:(RNNTopBarOptions *)options resolvedOptions:(RNNTopBarOptions *)resolvedOptions {
26
 - (void)mergeOptions:(RNNTopBarOptions *)options resolvedOptions:(RNNTopBarOptions *)resolvedOptions {
27
-    [self updateTitleWithOptions:options];
27
+    if (options.title.component.hasValue) {
28
+        [self setCustomNavigationTitleView:resolvedOptions perform:nil];
29
+    } else if (options.subtitle.text.hasValue) {
30
+        [self setTitleViewWithSubtitle:resolvedOptions];
31
+    } else if (options.title.text.hasValue) {
32
+        [self removeTitleComponents];
33
+        self.boundViewController.navigationItem.title = resolvedOptions.title.text.get;
34
+    }
28
 }
35
 }
29
 
36
 
30
 - (void)setTitleViewWithSubtitle:(RNNTopBarOptions *)options {
37
 - (void)setTitleViewWithSubtitle:(RNNTopBarOptions *)options {

+ 10
- 2
playground/ios/NavigationTests/RNNFontAttributesCreatorTest.m View File

56
 	XCTAssertEqual(font.pointSize, fontSize.floatValue);
56
 	XCTAssertEqual(font.pointSize, fontSize.floatValue);
57
 }
57
 }
58
 
58
 
59
-- (void)testcreateFromDictionary_shouldMergeWithDictionary {
59
+- (void)testCreateFromDictionary_shouldMergeWithDictionary {
60
 	NSString* familyName = @"Helvetica";
60
 	NSString* familyName = @"Helvetica";
61
 	NSNumber* fontSize = @(20);
61
 	NSNumber* fontSize = @(20);
62
 	NSDictionary* dictionary = @{NSForegroundColorAttributeName: UIColor.redColor};
62
 	NSDictionary* dictionary = @{NSForegroundColorAttributeName: UIColor.redColor};
63
 	
63
 	
64
 	NSDictionary* attributes = [RNNFontAttributesCreator createFromDictionary:dictionary fontFamily:familyName fontSize:fontSize defaultFontSize:nil fontWeight:nil color:nil defaultColor:nil];
64
 	NSDictionary* attributes = [RNNFontAttributesCreator createFromDictionary:dictionary fontFamily:familyName fontSize:fontSize defaultFontSize:nil fontWeight:nil color:nil defaultColor:nil];
65
 	UIFont* font = attributes[NSFontAttributeName];
65
 	UIFont* font = attributes[NSFontAttributeName];
66
-	XCTAssertEqual(attributes[NSForegroundColorAttributeName], UIColor.redColor);
67
     XCTAssertTrue([familyName isEqualToString:font.familyName]);
66
     XCTAssertTrue([familyName isEqualToString:font.familyName]);
68
 	XCTAssertEqual(font.pointSize, fontSize.floatValue);
67
 	XCTAssertEqual(font.pointSize, fontSize.floatValue);
69
 }
68
 }
70
 
69
 
70
+- (void)testCreateFromDictionary_shouldOverrideColor {
71
+	NSString* familyName = @"Helvetica";
72
+	NSNumber* fontSize = @(20);
73
+	NSDictionary* dictionary = @{NSForegroundColorAttributeName: UIColor.redColor};
74
+	
75
+	NSDictionary* attributes = [RNNFontAttributesCreator createFromDictionary:dictionary fontFamily:familyName fontSize:fontSize defaultFontSize:nil fontWeight:nil color:nil defaultColor:nil];
76
+	XCTAssertEqual(attributes[NSForegroundColorAttributeName], nil);
77
+}
78
+
71
 - (void)testCreateWithFontFamily_shouldNotChangeFontFamilyWhenOnlySizeAvailable {
79
 - (void)testCreateWithFontFamily_shouldNotChangeFontFamilyWhenOnlySizeAvailable {
72
 	NSNumber* fontSize = @(20);
80
 	NSNumber* fontSize = @(20);
73
 	UIFont* initialFont = [UIFont systemFontOfSize:10 weight:UIFontWeightHeavy];
81
 	UIFont* initialFont = [UIFont systemFontOfSize:10 weight:UIFontWeightHeavy];