Преглед на файлове

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 години
родител
ревизия
115d5b8f54

+ 1
- 1
lib/ios/RNNComponentPresenter.m Целия файл

@@ -159,7 +159,7 @@
159 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 165
 - (void)renderComponents:(RNNNavigationOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock {

+ 4
- 4
lib/ios/RNNFontAttributesCreator.m Целия файл

@@ -20,13 +20,13 @@
20 20
 }
21 21
 
22 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 24
     UIFont* currentFont = attributesDictionary[NSFontAttributeName];
25 25
     
26 26
 	CGFloat resolvedFontSize = [self resolveFontSize:currentFont fontSize:fontSize];
27
-    if (color) {
28
-        titleTextAttributes[NSForegroundColorAttributeName] = color;
29
-    }
27
+    
28
+    titleTextAttributes[NSForegroundColorAttributeName] = color;
29
+    
30 30
     if (fontWeight) {
31 31
         titleTextAttributes[NSFontAttributeName] = [UIFont systemFontOfSize:resolvedFontSize weight:[RCTConvert UIFontWeight:fontWeight]];
32 32
     } else if (fontFamily){

+ 8
- 1
lib/ios/TopBarTitlePresenter.m Целия файл

@@ -24,7 +24,14 @@
24 24
 }
25 25
 
26 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 37
 - (void)setTitleViewWithSubtitle:(RNNTopBarOptions *)options {

+ 10
- 2
playground/ios/NavigationTests/RNNFontAttributesCreatorTest.m Целия файл

@@ -56,18 +56,26 @@
56 56
 	XCTAssertEqual(font.pointSize, fontSize.floatValue);
57 57
 }
58 58
 
59
-- (void)testcreateFromDictionary_shouldMergeWithDictionary {
59
+- (void)testCreateFromDictionary_shouldMergeWithDictionary {
60 60
 	NSString* familyName = @"Helvetica";
61 61
 	NSNumber* fontSize = @(20);
62 62
 	NSDictionary* dictionary = @{NSForegroundColorAttributeName: UIColor.redColor};
63 63
 	
64 64
 	NSDictionary* attributes = [RNNFontAttributesCreator createFromDictionary:dictionary fontFamily:familyName fontSize:fontSize defaultFontSize:nil fontWeight:nil color:nil defaultColor:nil];
65 65
 	UIFont* font = attributes[NSFontAttributeName];
66
-	XCTAssertEqual(attributes[NSForegroundColorAttributeName], UIColor.redColor);
67 66
     XCTAssertTrue([familyName isEqualToString:font.familyName]);
68 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 79
 - (void)testCreateWithFontFamily_shouldNotChangeFontFamilyWhenOnlySizeAvailable {
72 80
 	NSNumber* fontSize = @(20);
73 81
 	UIFont* initialFont = [UIFont systemFontOfSize:10 weight:UIFontWeightHeavy];