Bladeren bron

Font weight option support for iOS (#5490)

* Add fontWeight support on iOS

* Add tests

* Fix tests
Yogev Ben David 5 jaren geleden
bovenliggende
commit
6ab2345ad6
No account linked to committer's email address

+ 5
- 1
docs/docs/styling.md Bestand weergeven

@@ -82,6 +82,7 @@ Navigation.mergeOptions(this.props.componentId, {
82 82
       fontSize: 14,
83 83
       color: 'red',
84 84
       fontFamily: 'Helvetica',
85
+      fontWeight: 'regular', // Available on iOS only, will ignore fontFamily style and use the iOS system fonts instead. Supported weights are: 'regular', 'bold', 'thin', 'ultraLight', 'light', 'medium', 'semibold', 'heavy' and 'black'.
85 86
       component: {
86 87
         name: 'example.CustomTopBarTitle',
87 88
         alignment: 'center'
@@ -92,6 +93,7 @@ Navigation.mergeOptions(this.props.componentId, {
92 93
       fontSize: 14,
93 94
       color: 'red',
94 95
       fontFamily: 'Helvetica',
96
+      fontWeight: 'regular', // Available on iOS only, will ignore fontFamily style and use the iOS system fonts instead. Supported weights are: 'regular', 'bold', 'thin', 'ultraLight', 'light', 'medium', 'semibold', 'heavy' and 'black'.
95 97
       alignment: 'center'
96 98
     },
97 99
     backButton: {
@@ -130,6 +132,7 @@ Navigation.mergeOptions(this.props.componentId, {
130 132
     textColor: 'red',
131 133
     selectedTextColor: 'blue',
132 134
     fontFamily: 'Helvetica',
135
+    fontWeight: 'regular', // Available on iOS only, will ignore fontFamily style and use the iOS system fonts instead. Supported weights are: 'regular', 'bold', 'thin', 'ultraLight', 'light', 'medium', 'semibold', 'heavy' and 'black'.
133 136
     fontSize: 10
134 137
   },
135 138
   sideMenu: {
@@ -216,7 +219,8 @@ Navigation.mergeOptions(this.props.componentId, {
216 219
       visible: true,
217 220
       fontSize: 30,
218 221
       color: 'red',
219
-      fontFamily: 'Helvetica'
222
+      fontFamily: 'Helvetica',
223
+      fontWeight: 'regular' // Available on iOS only, will ignore fontFamily style and use the iOS system fonts instead. Supported weights are: 'regular', 'bold', 'thin', 'ultraLight', 'light', 'medium', 'semibold', 'heavy' and 'black'.
220 224
     },
221 225
   },
222 226
   sideMenu: {

+ 3
- 0
docs/docs/topBar-buttons.md Bestand weergeven

@@ -15,6 +15,9 @@ The following options can be used to customise buttons.
15 15
   color: 'red',
16 16
   disabledColor: 'black',
17 17
   testID: 'buttonOneTestID',
18
+  fontFamily: 'Helvetica',
19
+  fontSize: 10
20
+  fontWeight: 'regular', // Available on iOS only, will ignore fontFamily style and use the iOS system fonts instead. Supported weights are: 'regular', 'bold', 'thin', 'ultraLight', 'light', 'medium', 'semibold', 'heavy' and 'black'.
18 21
   // Android only
19 22
   showAsAction: 'ifRoom', // See below for details.
20 23
   // iOS only

+ 21
- 0
lib/ios/RCTConvert+UIFontWeight.h Bestand weergeven

@@ -0,0 +1,21 @@
1
+#import <React/RCTConvert.h>
2
+
3
+@interface RCTConvert (UIFontWeight)
4
+
5
+@end
6
+
7
+@implementation RCTConvert (UIFontWeight)
8
+
9
+RCT_ENUM_CONVERTER(UIFontWeight,
10
+				   (@{@"ultraLight": @(UIFontWeightUltraLight),
11
+					  @"thin": @(UIFontWeightThin),
12
+					  @"light": @(UIFontWeightLight),
13
+					  @"regular": @(UIFontWeightRegular),
14
+					  @"medium": @(UIFontWeightMedium),
15
+					  @"semibold": @(UIFontWeightSemibold),
16
+					  @"bold": @(UIFontWeightBold),
17
+					  @"heavy": @(UIFontWeightHeavy),
18
+					  @"black": @(UIFontWeightBlack)
19
+					  }), UIFontWeightRegular, floatValue)
20
+
21
+@end

+ 1
- 0
lib/ios/RNNBottomTabOptions.h Bestand weergeven

@@ -10,6 +10,7 @@
10 10
 @property(nonatomic, strong) Color *badgeColor;
11 11
 @property(nonatomic, strong) DotIndicatorOptions *dotIndicator;
12 12
 @property(nonatomic, strong) Text *fontFamily;
13
+@property(nonatomic, strong) Text *fontWeight;
13 14
 @property(nonatomic, strong) Text *testID;
14 15
 @property(nonatomic, strong) Image *icon;
15 16
 @property(nonatomic, strong) Image *selectedIcon;

+ 1
- 0
lib/ios/RNNBottomTabOptions.m Bestand weergeven

@@ -12,6 +12,7 @@
12 12
     self.badge = [TextParser parse:dict key:@"badge"];
13 13
     self.badgeColor = [ColorParser parse:dict key:@"badgeColor"];
14 14
     self.fontFamily = [TextParser parse:dict key:@"fontFamily"];
15
+	self.fontWeight = [TextParser parse:dict key:@"fontWeight"];
15 16
     self.testID = [TextParser parse:dict key:@"testID"];
16 17
 
17 18
     self.dotIndicator = [DotIndicatorParser parse:dict];

+ 5
- 1
lib/ios/RNNFontAttributesCreator.h Bestand weergeven

@@ -3,6 +3,10 @@
3 3
 
4 4
 @interface RNNFontAttributesCreator : NSObject
5 5
 
6
-+ (NSDictionary *)createFontAttributesWithFontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize color:(UIColor *)color;
6
++ (NSDictionary *)createWithFontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize defaultFontSize:(NSNumber *)defaultFontSize fontWeight:(NSString *)fontWeight color:(UIColor *)color defaultColor:(UIColor *)defaultColor;
7
+
8
++ (NSDictionary *)createWithFontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize fontWeight:(NSString *)fontWeight color:(UIColor *)color;
9
+
10
++ (NSDictionary *)createWithDictionary:(NSDictionary *)attributesDictionary fontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize defaultFontSize:(NSNumber *)defaultFontSize fontWeight:(NSString *)fontWeight color:(UIColor *)color defaultColor:(UIColor *)defaultColor;
7 11
 
8 12
 @end

+ 24
- 10
lib/ios/RNNFontAttributesCreator.m Bestand weergeven

@@ -1,21 +1,35 @@
1 1
 #import "RNNFontAttributesCreator.h"
2
+#import "RCTConvert+UIFontWeight.h"
2 3
 
3 4
 @implementation RNNFontAttributesCreator
4 5
 
5
-+ (NSDictionary *)createFontAttributesWithFontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize color:(UIColor *)color {
6
++ (NSDictionary *)createWithFontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize defaultFontSize:(NSNumber *)defaultFontSize fontWeight:(NSString *)fontWeight color:(UIColor *)color defaultColor:(UIColor *)defaultColor {
6 7
 	NSMutableDictionary* titleTextAttributes = [NSMutableDictionary new];
7
-	if (fontFamily || fontSize || color) {
8
+	return [self createWithDictionary:titleTextAttributes fontFamily:fontFamily fontSize:fontSize defaultFontSize:defaultFontSize fontWeight:fontWeight color:color defaultColor:defaultColor];
9
+}
10
+
11
++ (NSDictionary *)createWithFontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize fontWeight:(NSString *)fontWeight color:(UIColor *)color {
12
+	NSMutableDictionary* titleTextAttributes = [NSMutableDictionary new];
13
+	return [self createWithDictionary:titleTextAttributes fontFamily:fontFamily fontSize:fontSize fontWeight:fontWeight color:color];
14
+}
15
+
16
++ (NSDictionary *)createWithDictionary:(NSDictionary *)attributesDictionary fontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize defaultFontSize:(NSNumber *)defaultFontSize fontWeight:(NSString *)fontWeight color:(UIColor *)color defaultColor:(UIColor *)defaultColor {
17
+	return [self createWithDictionary:attributesDictionary fontFamily:fontFamily fontSize:fontSize ?: defaultFontSize fontWeight:fontWeight color:color ?: defaultColor];
18
+}
19
+
20
++ (NSDictionary *)createWithDictionary:(NSDictionary *)attributesDictionary fontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize fontWeight:(NSString *)fontWeight color:(UIColor *)color {
21
+	NSMutableDictionary* titleTextAttributes = [NSMutableDictionary dictionaryWithDictionary:attributesDictionary];
22
+	if (fontFamily || fontSize || color || fontWeight) {
23
+		CGFloat resolvedFontSize = fontSize ? fontSize.floatValue : 17;
8 24
 		if (color) {
9 25
 			titleTextAttributes[NSForegroundColorAttributeName] = color;
10 26
 		}
11
-		if (fontFamily){
12
-			if (fontSize) {
13
-				titleTextAttributes[NSFontAttributeName] = [UIFont fontWithName:fontFamily size:[fontSize floatValue]];
14
-			} else {
15
-				titleTextAttributes[NSFontAttributeName] = [UIFont fontWithName:fontFamily size:17];
16
-			}
17
-		} else if (fontSize) {
18
-			titleTextAttributes[NSFontAttributeName] = [UIFont systemFontOfSize:[fontSize floatValue]];
27
+		if (fontWeight) {
28
+			titleTextAttributes[NSFontAttributeName] = [UIFont systemFontOfSize:resolvedFontSize weight:[RCTConvert UIFontWeight:fontWeight]];
29
+		} else if (fontFamily){
30
+			titleTextAttributes[NSFontAttributeName] = [UIFont fontWithName:fontFamily size:resolvedFontSize];
31
+		} else {
32
+			titleTextAttributes[NSFontAttributeName] = [UIFont systemFontOfSize:resolvedFontSize];
19 33
 		}
20 34
 	}
21 35
 	

+ 1
- 0
lib/ios/RNNLargeTitleOptions.h Bestand weergeven

@@ -7,5 +7,6 @@
7 7
 @property (nonatomic, strong) Bool* visible;
8 8
 @property (nonatomic, strong) Color* color;
9 9
 @property (nonatomic, strong) Text* fontFamily;
10
+@property (nonatomic, strong) Text* fontWeight;
10 11
 
11 12
 @end

+ 1
- 0
lib/ios/RNNLargeTitleOptions.m Bestand weergeven

@@ -9,6 +9,7 @@
9 9
 	self.visible = [BoolParser parse:dict key:@"visible"];
10 10
 	self.color = [ColorParser parse:dict key:@"color"];
11 11
 	self.fontFamily = [TextParser parse:dict key:@"fontFamily"];
12
+	self.fontWeight = [TextParser parse:dict key:@"fontWeight"];
12 13
 	
13 14
 	return self;
14 15
 }

+ 4
- 32
lib/ios/RNNNavigationButtons.m Bestand weergeven

@@ -6,6 +6,7 @@
6 6
 #import "RNNComponentViewController.h"
7 7
 #import "UIImage+insets.h"
8 8
 #import "UIViewController+LayoutProtocol.h"
9
+#import "RNNFontAttributesCreator.h"
9 10
 
10 11
 @interface RNNNavigationButtons()
11 12
 
@@ -126,8 +127,8 @@
126 127
 	BOOL enabledBool = enabled ? [enabled boolValue] : YES;
127 128
 	[barButtonItem setEnabled:enabledBool];
128 129
 	
129
-	NSMutableDictionary* textAttributes = [[NSMutableDictionary alloc] init];
130
-	NSMutableDictionary* disabledTextAttributes = [[NSMutableDictionary alloc] init];
130
+	NSMutableDictionary* textAttributes = [NSMutableDictionary dictionaryWithDictionary:[RNNFontAttributesCreator createWithFontFamily:dictionary[@"fontFamily"] ?: [defaultStyle.fontFamily getWithDefaultValue:nil] fontSize:dictionary[@"fontSize"] defaultFontSize:[defaultStyle.fontSize getWithDefaultValue:@(17)] fontWeight:dictionary[@"fontWeight"] color:nil defaultColor:nil]];
131
+	NSMutableDictionary* disabledTextAttributes = [NSMutableDictionary dictionaryWithDictionary:[RNNFontAttributesCreator createWithFontFamily:dictionary[@"fontFamily"] ?: [defaultStyle.fontFamily getWithDefaultValue:nil] fontSize:dictionary[@"fontSize"] defaultFontSize:[defaultStyle.fontSize getWithDefaultValue:@(17)] fontWeight:dictionary[@"fontWeight"] color:nil defaultColor:nil]];
131 132
 	
132 133
 	if (!enabledBool && disabledColor) {
133 134
 		color = disabledColor;
@@ -139,18 +140,7 @@
139 140
 		[barButtonItem setImage:[[iconImage withTintColor:color] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
140 141
 		barButtonItem.tintColor = color;
141 142
 	}
142
-	
143
-	NSNumber* fontSize = [self fontSize:dictionary[@"fontSize"] defaultFontSize:[defaultStyle.fontSize getWithDefaultValue:nil]];
144
-	NSString* fontFamily = [self fontFamily:dictionary[@"fontFamily"] defaultFontFamily:[defaultStyle.fontFamily getWithDefaultValue:nil]];
145
-	UIFont *font = nil;
146
-	if (fontFamily) {
147
-		font = [UIFont fontWithName:fontFamily size:[fontSize floatValue]];
148
-	} else {
149
-		font = [UIFont systemFontOfSize:[fontSize floatValue]];
150
-	}
151
-	[textAttributes setObject:font forKey:NSFontAttributeName];
152
-	[disabledTextAttributes setObject:font forKey:NSFontAttributeName];
153
-	
143
+
154 144
 	[barButtonItem setTitleTextAttributes:textAttributes forState:UIControlStateNormal];
155 145
 	[barButtonItem setTitleTextAttributes:textAttributes forState:UIControlStateHighlighted];
156 146
 	[barButtonItem setTitleTextAttributes:disabledTextAttributes forState:UIControlStateDisabled];
@@ -174,24 +164,6 @@
174 164
 	return nil;
175 165
 }
176 166
 
177
-- (NSNumber *)fontSize:(NSNumber *)fontSize defaultFontSize:(NSNumber *)defaultFontSize {
178
-	if (fontSize) {
179
-		return fontSize;
180
-	} else if (defaultFontSize) {
181
-		return defaultFontSize;
182
-	}
183
-	
184
-	return @(17);
185
-}
186
-
187
-- (NSString *)fontFamily:(NSString *)fontFamily defaultFontFamily:(NSString *)defaultFontFamily {
188
-	if (fontFamily) {
189
-		return fontFamily;
190
-	} else {
191
-		return defaultFontFamily;
192
-	}
193
-}
194
-
195 167
 - (id)getValue:(id)value withDefault:(id)defaultValue {
196 168
 	return value ? value : defaultValue;
197 169
 }

+ 5
- 4
lib/ios/RNNStackPresenter.m Bestand weergeven

@@ -41,8 +41,8 @@
41 41
 	[stack setNavigationBarBlur:[withDefault.topBar.background.blur getWithDefaultValue:NO]];
42 42
 	[stack setTopBarBackgroundColor:[withDefault.topBar.background.color getWithDefaultValue:nil]];
43 43
 	[stack setNavigationBarLargeTitleVisible:[withDefault.topBar.largeTitle.visible getWithDefaultValue:NO]];
44
-	[stack setNavigationBarLargeTitleFontFamily:[withDefault.topBar.largeTitle.fontFamily getWithDefaultValue:nil] fontSize:[withDefault.topBar.largeTitle.fontSize getWithDefaultValue:nil] color:[withDefault.topBar.largeTitle.color getWithDefaultValue:nil]];
45
-	[stack setNavigationBarFontFamily:[withDefault.topBar.title.fontFamily getWithDefaultValue:nil] fontSize:[withDefault.topBar.title.fontSize getWithDefaultValue:nil] color:[withDefault.topBar.title.color getWithDefaultValue:nil]];
44
+	[stack setNavigationBarLargeTitleFontFamily:[withDefault.topBar.largeTitle.fontFamily getWithDefaultValue:nil] fontSize:[withDefault.topBar.largeTitle.fontSize getWithDefaultValue:nil] fontWeight:[withDefault.topBar.largeTitle.fontWeight getWithDefaultValue:nil] color:[withDefault.topBar.largeTitle.color getWithDefaultValue:nil]];
45
+	[stack setNavigationBarFontFamily:[withDefault.topBar.title.fontFamily getWithDefaultValue:nil] fontSize:[withDefault.topBar.title.fontSize getWithDefaultValue:nil] fontWeight:[withDefault.topBar.title.fontWeight getWithDefaultValue:nil] color:[withDefault.topBar.title.color getWithDefaultValue:nil]];
46 46
 	[stack setBackButtonColor:[withDefault.topBar.backButton.color getWithDefaultValue:nil]];
47 47
 }
48 48
 
@@ -57,7 +57,7 @@
57 57
 	RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
58 58
 	RNNStackController* navigationController = self.boundViewController;
59 59
 	[navigationController setTopBarBackgroundColor:[withDefault.topBar.background.color getWithDefaultValue:nil]];
60
-	[navigationController setNavigationBarFontFamily:[withDefault.topBar.title.fontFamily getWithDefaultValue:nil] fontSize:[withDefault.topBar.title.fontSize getWithDefaultValue:nil] color:[withDefault.topBar.title.color getWithDefaultValue:[UIColor blackColor]]];
60
+	[navigationController setNavigationBarFontFamily:[withDefault.topBar.title.fontFamily getWithDefaultValue:nil] fontSize:[withDefault.topBar.title.fontSize getWithDefaultValue:nil] fontWeight:[withDefault.topBar.title.fontWeight getWithDefaultValue:nil] color:[withDefault.topBar.title.color getWithDefaultValue:[UIColor blackColor]]];
61 61
 	[navigationController setNavigationBarLargeTitleVisible:[withDefault.topBar.largeTitle.visible getWithDefaultValue:NO]];
62 62
 }
63 63
 
@@ -119,12 +119,13 @@
119 119
 
120 120
 	RNNLargeTitleOptions *largeTitleOptions = options.topBar.largeTitle;
121 121
 	if (largeTitleOptions.color.hasValue || largeTitleOptions.fontSize.hasValue || largeTitleOptions.fontFamily.hasValue) {
122
-		[stack setNavigationBarLargeTitleFontFamily:[options.topBar.largeTitle.fontFamily getWithDefaultValue:nil] fontSize:[options.topBar.largeTitle.fontSize getWithDefaultValue:nil] color:[options.topBar.largeTitle.color getWithDefaultValue:nil]];
122
+		[stack setNavigationBarLargeTitleFontFamily:[options.topBar.largeTitle.fontFamily getWithDefaultValue:nil] fontSize:[options.topBar.largeTitle.fontSize getWithDefaultValue:nil] fontWeight:[options.topBar.largeTitle.fontWeight getWithDefaultValue:nil] color:[options.topBar.largeTitle.color getWithDefaultValue:nil]];
123 123
 	}
124 124
 
125 125
 	RNNNavigationOptions * withDefault = (RNNNavigationOptions *) [[options mergeInOptions:resolvedOptions] withDefault:[self defaultOptions]];
126 126
 	[stack setNavigationBarFontFamily:[withDefault.topBar.title.fontFamily getWithDefaultValue:nil]
127 127
 							 fontSize:[withDefault.topBar.title.fontSize getWithDefaultValue:nil]
128
+						   fontWeight:[withDefault.topBar.title.fontWeight getWithDefaultValue:nil]
128 129
 								color:[withDefault.topBar.title.color getWithDefaultValue:nil]];
129 130
 	
130 131
 	if (options.topBar.component.name.hasValue) {

+ 1
- 0
lib/ios/RNNSubtitleOptions.h Bestand weergeven

@@ -6,6 +6,7 @@
6 6
 @property (nonatomic, strong) Number* fontSize;
7 7
 @property (nonatomic, strong) Color* color;
8 8
 @property (nonatomic, strong) Text* fontFamily;
9
+@property (nonatomic, strong) Text* fontWeight;
9 10
 @property (nonatomic, strong) Text* alignment;
10 11
 
11 12
 @end

+ 1
- 0
lib/ios/RNNSubtitleOptions.m Bestand weergeven

@@ -9,6 +9,7 @@
9 9
 	self.alignment = [TextParser parse:dict key:@"alignment"];
10 10
 	self.fontFamily = [TextParser parse:dict key:@"fontFamily"];
11 11
 	self.fontSize = [NumberParser parse:dict key:@"fontSize"];
12
+	self.fontWeight = [TextParser parse:dict key:@"fontWeight"];
12 13
 	self.color = [ColorParser parse:dict key:@"color"];
13 14
 	
14 15
 	return self;

+ 5
- 34
lib/ios/RNNTabBarItemCreator.m Bestand weergeven

@@ -1,5 +1,6 @@
1 1
 #import "RNNTabBarItemCreator.h"
2 2
 #import "UIImage+tint.h"
3
+#import "RNNFontAttributesCreator.h"
3 4
 
4 5
 @implementation RNNTabBarItemCreator
5 6
 
@@ -32,7 +33,7 @@
32 33
 	
33 34
 	
34 35
 	
35
-	[self appendTitleAttributes:tabItem textColor:[bottomTabOptions.textColor getWithDefaultValue:nil] selectedTextColor:[bottomTabOptions.selectedTextColor getWithDefaultValue:nil] fontFamily:[bottomTabOptions.fontFamily getWithDefaultValue:nil] fontSize:[bottomTabOptions.fontSize getWithDefaultValue:nil]];
36
+	[self appendTitleAttributes:tabItem textColor:[bottomTabOptions.textColor getWithDefaultValue:nil] selectedTextColor:[bottomTabOptions.selectedTextColor getWithDefaultValue:nil] fontFamily:[bottomTabOptions.fontFamily getWithDefaultValue:nil] fontSize:[bottomTabOptions.fontSize getWithDefaultValue:nil] fontWeight:[bottomTabOptions.fontWeight getWithDefaultValue:nil]];
36 37
 	
37 38
 	return tabItem;
38 39
 }
@@ -61,43 +62,13 @@
61 62
 	return nil;
62 63
 }
63 64
 
64
-+ (void)appendTitleAttributes:(UITabBarItem *)tabItem textColor:(UIColor *)textColor selectedTextColor:(UIColor *)selectedTextColor fontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize {
65
-	NSMutableDictionary* selectedAttributes = [NSMutableDictionary dictionaryWithDictionary:[tabItem titleTextAttributesForState:UIControlStateNormal]];
66
-	if (selectedTextColor) {
67
-		selectedAttributes[NSForegroundColorAttributeName] = selectedTextColor;
68
-	} else {
69
-		selectedAttributes[NSForegroundColorAttributeName] = [UIColor blackColor];
70
-	}
71
-	
72
-	selectedAttributes[NSFontAttributeName] = [self tabBarTextFont:fontFamily fontSize:fontSize];
65
++ (void)appendTitleAttributes:(UITabBarItem *)tabItem textColor:(UIColor *)textColor selectedTextColor:(UIColor *)selectedTextColor fontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize fontWeight:(NSString *)fontWeight {
66
+	NSDictionary* selectedAttributes = [RNNFontAttributesCreator createWithDictionary:[tabItem titleTextAttributesForState:UIControlStateSelected] fontFamily:fontFamily fontSize:fontSize defaultFontSize:@(10) fontWeight:fontWeight color:selectedTextColor defaultColor:[UIColor blackColor]];
73 67
 	[tabItem setTitleTextAttributes:selectedAttributes forState:UIControlStateSelected];
74 68
 	
75 69
 	
76
-	NSMutableDictionary* normalAttributes = [NSMutableDictionary dictionaryWithDictionary:[tabItem titleTextAttributesForState:UIControlStateNormal]];
77
-	if (textColor) {
78
-		normalAttributes[NSForegroundColorAttributeName] = textColor;
79
-	} else {
80
-		normalAttributes[NSForegroundColorAttributeName] = [UIColor blackColor];
81
-	}
82
-	
83
-	normalAttributes[NSFontAttributeName] = [self tabBarTextFont:fontFamily fontSize:fontSize];
70
+	NSDictionary* normalAttributes = [RNNFontAttributesCreator createWithDictionary:[tabItem titleTextAttributesForState:UIControlStateNormal] fontFamily:fontFamily fontSize:fontSize defaultFontSize:@(10) fontWeight:fontWeight color:textColor defaultColor:[UIColor blackColor]];
84 71
 	[tabItem setTitleTextAttributes:normalAttributes forState:UIControlStateNormal];
85 72
 }
86 73
 
87
-+(UIFont *)tabBarTextFont:(NSString *)fontFamily fontSize:(NSNumber *)fontSize {
88
-	if (fontFamily) {
89
-		return [UIFont fontWithName:fontFamily size:[self fontSize:fontSize]];
90
-	}
91
-	else if (fontSize) {
92
-		return [UIFont systemFontOfSize:[self fontSize:fontSize]];
93
-	}
94
-	else {
95
-		return nil;
96
-	}
97
-}
98
-
99
-+ (CGFloat)fontSize:(NSNumber *)fontSize {
100
-	return fontSize ? [fontSize floatValue] : 10;
101
-}
102
-
103 74
 @end

+ 1
- 0
lib/ios/RNNTitleOptions.h Bestand weergeven

@@ -8,6 +8,7 @@
8 8
 @property (nonatomic, strong) Number* fontSize;
9 9
 @property (nonatomic, strong) Color* color;
10 10
 @property (nonatomic, strong) Text* fontFamily;
11
+@property (nonatomic, strong) Text* fontWeight;
11 12
 
12 13
 @property (nonatomic, strong) RNNComponentOptions* component;
13 14
 @property (nonatomic, strong) Text* componentAlignment;

+ 1
- 0
lib/ios/RNNTitleOptions.m Bestand weergeven

@@ -8,6 +8,7 @@
8 8
 	self.text = [TextParser parse:dict key:@"text"];
9 9
 	self.fontFamily = [TextParser parse:dict key:@"fontFamily"];
10 10
 	self.fontSize = [NumberParser parse:dict key:@"fontSize"];
11
+	self.fontWeight = [TextParser parse:dict key:@"fontWeight"];
11 12
 	self.color = [ColorParser parse:dict key:@"color"];
12 13
 	
13 14
 	self.component = [[RNNComponentOptions alloc] initWithDict:dict[@"component"]];

+ 2
- 2
lib/ios/RNNTitleViewHelper.m Bestand weergeven

@@ -96,7 +96,7 @@
96 96
 	subtitleLabel.backgroundColor = [UIColor clearColor];
97 97
 	subtitleLabel.autoresizingMask = self.titleView.autoresizingMask;
98 98
 	
99
-	NSDictionary* fontAttributes = [RNNFontAttributesCreator createFontAttributesWithFontFamily:[_subtitleOptions.fontFamily getWithDefaultValue:nil] fontSize:[_subtitleOptions.fontSize getWithDefaultValue:nil] color:[_subtitleOptions.color getWithDefaultValue:nil]];
99
+	NSDictionary* fontAttributes = [RNNFontAttributesCreator createWithFontFamily:[_subtitleOptions.fontFamily getWithDefaultValue:nil] fontSize:[_subtitleOptions.fontSize getWithDefaultValue:nil] fontWeight:[_subtitleOptions.fontWeight getWithDefaultValue:nil] color:[_subtitleOptions.color getWithDefaultValue:nil]];
100 100
 	[subtitleLabel setAttributedText:[[NSAttributedString alloc] initWithString:self.subtitle attributes:fontAttributes]];
101 101
 	
102 102
 	
@@ -128,7 +128,7 @@
128 128
 	
129 129
 	titleLabel.autoresizingMask = self.titleView.autoresizingMask;
130 130
 	
131
-	NSDictionary* fontAttributes = [RNNFontAttributesCreator createFontAttributesWithFontFamily:[_titleOptions.fontFamily getWithDefaultValue:nil] fontSize:[_titleOptions.fontSize getWithDefaultValue:nil] color:[_subtitleOptions.color getWithDefaultValue:nil]];
131
+	NSDictionary* fontAttributes = [RNNFontAttributesCreator createWithFontFamily:[_titleOptions.fontFamily getWithDefaultValue:nil] fontSize:[_titleOptions.fontSize getWithDefaultValue:nil] fontWeight:[_titleOptions.fontWeight getWithDefaultValue:nil] color:[_subtitleOptions.color getWithDefaultValue:nil]];
132 132
 	[titleLabel setAttributedText:[[NSAttributedString alloc] initWithString:self.title attributes:fontAttributes]];
133 133
 	
134 134
 	CGSize labelSize = [titleLabel.text sizeWithAttributes:fontAttributes];

+ 6
- 0
lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj Bestand weergeven

@@ -202,6 +202,7 @@
202 202
 		50887CA920F26BFE00D06111 /* RNNOverlayWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 50887CA720F26BFD00D06111 /* RNNOverlayWindow.m */; };
203 203
 		50887CAA20F26BFE00D06111 /* RNNOverlayWindow.h in Headers */ = {isa = PBXBuildFile; fileRef = 50887CA820F26BFE00D06111 /* RNNOverlayWindow.h */; };
204 204
 		508EBDBD2278746400BEC144 /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 508EBDBA2278742700BEC144 /* JavaScriptCore.framework */; };
205
+		50967F5B232FC2C200BEEA92 /* RNNFontAttributesCreatorTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 50967F5A232FC2C200BEEA92 /* RNNFontAttributesCreatorTest.m */; };
205 206
 		509B2480217873FF00C83C23 /* UINavigationController+RNNOptionsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 509B247F217873FF00C83C23 /* UINavigationController+RNNOptionsTest.m */; };
206 207
 		509B258F2178BE7A00C83C23 /* RNNStackPresenterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 509B258E2178BE7A00C83C23 /* RNNStackPresenterTest.m */; };
207 208
 		50A00C37200F84D6000F01A6 /* RNNOverlayOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 50A00C35200F84D6000F01A6 /* RNNOverlayOptions.h */; };
@@ -549,6 +550,7 @@
549 550
 		50887CA720F26BFD00D06111 /* RNNOverlayWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNOverlayWindow.m; sourceTree = "<group>"; };
550 551
 		50887CA820F26BFE00D06111 /* RNNOverlayWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNNOverlayWindow.h; sourceTree = "<group>"; };
551 552
 		508EBDBA2278742700BEC144 /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
553
+		50967F5A232FC2C200BEEA92 /* RNNFontAttributesCreatorTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNFontAttributesCreatorTest.m; sourceTree = "<group>"; };
552 554
 		509B247F217873FF00C83C23 /* UINavigationController+RNNOptionsTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UINavigationController+RNNOptionsTest.m"; sourceTree = "<group>"; };
553 555
 		509B258E2178BE7A00C83C23 /* RNNStackPresenterTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNStackPresenterTest.m; sourceTree = "<group>"; };
554 556
 		50A00C35200F84D6000F01A6 /* RNNOverlayOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNOverlayOptions.h; sourceTree = "<group>"; };
@@ -565,6 +567,7 @@
565 567
 		50CE8502217C6C9B00084EBF /* RNNSideMenuPresenterTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNSideMenuPresenterTest.m; sourceTree = "<group>"; };
566 568
 		50D031322005149000386B3D /* RNNOverlayManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNOverlayManager.h; sourceTree = "<group>"; };
567 569
 		50D031332005149000386B3D /* RNNOverlayManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNOverlayManager.m; sourceTree = "<group>"; };
570
+		50DA74CF232F80FE004A00C1 /* RCTConvert+UIFontWeight.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RCTConvert+UIFontWeight.h"; sourceTree = "<group>"; };
568 571
 		50E02BD521A6E54B00A43942 /* RCTConvert+SideMenuOpenGestureMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RCTConvert+SideMenuOpenGestureMode.h"; sourceTree = "<group>"; };
569 572
 		50E02BD621A6EE0F00A43942 /* SideMenuOpenMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SideMenuOpenMode.h; sourceTree = "<group>"; };
570 573
 		50E02BD721A6EE0F00A43942 /* SideMenuOpenMode.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SideMenuOpenMode.m; sourceTree = "<group>"; };
@@ -735,6 +738,7 @@
735 738
 				5038A3BF216E1E66009280BC /* RNNFontAttributesCreator.h */,
736 739
 				5038A3C0216E1E66009280BC /* RNNFontAttributesCreator.m */,
737 740
 				505EDD48214FDA800071C7DE /* RCTConvert+Modal.h */,
741
+				50DA74CF232F80FE004A00C1 /* RCTConvert+UIFontWeight.h */,
738 742
 				50E02BD521A6E54B00A43942 /* RCTConvert+SideMenuOpenGestureMode.h */,
739 743
 				7365070F21E4B16F004E020F /* RCTConvert+UIBarButtonSystemItem.h */,
740 744
 				7365071021E4B16F004E020F /* RCTConvert+UIBarButtonSystemItem.m */,
@@ -1034,6 +1038,7 @@
1034 1038
 			children = (
1035 1039
 				E5F6C3BC22DB51E00093C2CE /* utils */,
1036 1040
 				7B49FEC61E95098500DEB3EA /* RNNControllerFactoryTest.m */,
1041
+				50967F5A232FC2C200BEEA92 /* RNNFontAttributesCreatorTest.m */,
1037 1042
 				7B49FEC71E95098500DEB3EA /* RNNExternalComponentStoreTest.m */,
1038 1043
 				7B49FEC81E95098500DEB3EA /* RNNModalManagerTest.m */,
1039 1044
 				7B49FEC91E95098500DEB3EA /* RNNCommandsHandlerTest.m */,
@@ -1475,6 +1480,7 @@
1475 1480
 				506F630D216A599300AD0D0A /* RNNTabBarControllerTest.m in Sources */,
1476 1481
 				7B49FECB1E95098500DEB3EA /* RNNControllerFactoryTest.m in Sources */,
1477 1482
 				50206A6D21AFE75400B7BB1A /* RNNSideMenuParserTest.m in Sources */,
1483
+				50967F5B232FC2C200BEEA92 /* RNNFontAttributesCreatorTest.m in Sources */,
1478 1484
 				509B258F2178BE7A00C83C23 /* RNNStackPresenterTest.m in Sources */,
1479 1485
 				7B49FECD1E95098500DEB3EA /* RNNModalManagerTest.m in Sources */,
1480 1486
 				5085DD2D21DCF75A0032E64B /* RNNSideMenuControllerTest.m in Sources */,

+ 82
- 0
lib/ios/ReactNativeNavigationTests/RNNFontAttributesCreatorTest.m Bestand weergeven

@@ -0,0 +1,82 @@
1
+#import <XCTest/XCTest.h>
2
+#import "RNNFontAttributesCreator.h"
3
+
4
+@interface RNNFontAttributesCreatorTest : XCTestCase
5
+
6
+@end
7
+
8
+@implementation RNNFontAttributesCreatorTest
9
+
10
+- (void)testCreateWithFontFamily_shouldCreateAttributes {
11
+	NSString* familyName = @"Helvetica";
12
+	NSNumber* fontSize = @(20);
13
+	UIColor* fontColor = UIColor.blueColor;
14
+	
15
+	NSDictionary* attributes = [RNNFontAttributesCreator createWithFontFamily:familyName fontSize:fontSize fontWeight:nil color:fontColor];
16
+	UIFont* font = attributes[NSFontAttributeName];
17
+	XCTAssertEqual(attributes[NSForegroundColorAttributeName], fontColor);
18
+    XCTAssertTrue([familyName isEqualToString:font.familyName]);
19
+	XCTAssertEqual(font.pointSize, fontSize.floatValue);
20
+}
21
+
22
+- (void)testCreateWithFontFamily_shouldIgnoreFontFamilyWhenFontWeightIsNotNil {
23
+	NSString* familyName = @"Helvetica";
24
+	NSString* fontWeight = @"bold";
25
+	NSNumber* fontSize = @(20);
26
+	UIColor* fontColor = UIColor.blueColor;
27
+	
28
+	NSDictionary* attributes = [RNNFontAttributesCreator createWithFontFamily:familyName fontSize:fontSize fontWeight:fontWeight color:fontColor];
29
+	UIFont* font = attributes[NSFontAttributeName];
30
+	XCTAssertEqual(attributes[NSForegroundColorAttributeName], fontColor);
31
+    XCTAssertFalse([familyName isEqualToString:font.familyName]);
32
+	XCTAssertEqual(font.pointSize, fontSize.floatValue);
33
+}
34
+
35
+- (void)testCreateWithFontFamilyWithDefault_shouldCreateDefaultAttributes {
36
+	NSString* familyName = @"Helvetica";
37
+	NSNumber* defaultFontSize = @(20);
38
+	UIColor* defaultFontColor = UIColor.blueColor;
39
+	
40
+	NSDictionary* attributes = [RNNFontAttributesCreator createWithFontFamily:familyName fontSize:nil defaultFontSize:defaultFontSize fontWeight:nil color:nil defaultColor:defaultFontColor];
41
+	UIFont* font = attributes[NSFontAttributeName];
42
+	XCTAssertEqual(attributes[NSForegroundColorAttributeName], defaultFontColor);
43
+    XCTAssertTrue([familyName isEqualToString:font.familyName]);
44
+	XCTAssertEqual(font.pointSize, defaultFontSize.floatValue);
45
+}
46
+
47
+- (void)testCreateWithDictionary_shouldCreateAttributes {
48
+	NSString* familyName = @"Helvetica";
49
+	NSNumber* fontSize = @(20);
50
+	UIColor* fontColor = UIColor.blueColor;
51
+	
52
+	NSDictionary* attributes = [RNNFontAttributesCreator createWithDictionary:@{} fontFamily:familyName fontSize:fontSize defaultFontSize:nil fontWeight:nil color:fontColor defaultColor:nil];
53
+	UIFont* font = attributes[NSFontAttributeName];
54
+	XCTAssertEqual(attributes[NSForegroundColorAttributeName], fontColor);
55
+    XCTAssertTrue([familyName isEqualToString:font.familyName]);
56
+	XCTAssertEqual(font.pointSize, fontSize.floatValue);
57
+}
58
+
59
+- (void)testCreateWithDictionary_shouldMergeWithDictionary {
60
+	NSString* familyName = @"Helvetica";
61
+	NSNumber* fontSize = @(20);
62
+	NSDictionary* dictionary = @{NSForegroundColorAttributeName: UIColor.redColor};
63
+	
64
+	NSDictionary* attributes = [RNNFontAttributesCreator createWithDictionary:dictionary fontFamily:familyName fontSize:fontSize defaultFontSize:nil fontWeight:nil color:nil defaultColor:nil];
65
+	UIFont* font = attributes[NSFontAttributeName];
66
+	XCTAssertEqual(attributes[NSForegroundColorAttributeName], UIColor.redColor);
67
+    XCTAssertTrue([familyName isEqualToString:font.familyName]);
68
+	XCTAssertEqual(font.pointSize, fontSize.floatValue);
69
+}
70
+
71
+- (void)testCreateWithFontFamily_shouldCreateSystemFontWhenOnlySizeAvailable {
72
+	NSNumber* fontSize = @(20);
73
+	
74
+	NSDictionary* attributes = [RNNFontAttributesCreator createWithFontFamily:nil fontSize:fontSize fontWeight:nil color:nil];
75
+	UIFont* font = attributes[NSFontAttributeName];
76
+	NSString* systemFontFamilyName = [[UIFont systemFontOfSize:20] familyName];
77
+	XCTAssertEqual(font.pointSize, fontSize.floatValue);
78
+	XCTAssertTrue([font.familyName isEqualToString:systemFontFamilyName]);
79
+}
80
+
81
+
82
+@end

+ 2
- 2
lib/ios/UINavigationController+RNNOptions.h Bestand weergeven

@@ -16,7 +16,7 @@
16 16
 
17 17
 - (void)setBarStyle:(UIBarStyle)barStyle;
18 18
 
19
-- (void)setNavigationBarFontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize color:(UIColor *)color;
19
+- (void)setNavigationBarFontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize fontWeight:(NSString *)fontWeight color:(UIColor *)color;
20 20
 
21 21
 - (void)setNavigationBarTranslucent:(BOOL)translucent;
22 22
 
@@ -26,7 +26,7 @@
26 26
 
27 27
 - (void)setNavigationBarLargeTitleVisible:(BOOL)visible;
28 28
 
29
-- (void)setNavigationBarLargeTitleFontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize color:(UIColor *)color;
29
+- (void)setNavigationBarLargeTitleFontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize fontWeight:(NSString *)fontWeight color:(UIColor *)color;
30 30
 
31 31
 - (void)setBackButtonColor:(UIColor *)color;
32 32
 

+ 4
- 4
lib/ios/UINavigationController+RNNOptions.m Bestand weergeven

@@ -45,8 +45,8 @@ const NSInteger BLUR_TOPBAR_TAG = 78264802;
45 45
 	self.navigationBar.barStyle = barStyle;
46 46
 }
47 47
 
48
-- (void)setNavigationBarFontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize color:(UIColor *)color {
49
-	NSDictionary* fontAttributes = [RNNFontAttributesCreator createFontAttributesWithFontFamily:fontFamily fontSize:fontSize color:color];
48
+- (void)setNavigationBarFontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize fontWeight:(NSString *)fontWeight color:(UIColor *)color {
49
+	NSDictionary* fontAttributes = [RNNFontAttributesCreator createWithFontFamily:fontFamily fontSize:fontSize fontWeight:fontWeight color:color];
50 50
 	
51 51
 	if (fontAttributes.allKeys.count > 0) {
52 52
 		self.navigationBar.titleTextAttributes = fontAttributes;
@@ -63,9 +63,9 @@ const NSInteger BLUR_TOPBAR_TAG = 78264802;
63 63
 	}
64 64
 }
65 65
 
66
-- (void)setNavigationBarLargeTitleFontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize color:(UIColor *)color {
66
+- (void)setNavigationBarLargeTitleFontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize fontWeight:(NSString *)fontWeight color:(UIColor *)color {
67 67
 	if (@available(iOS 11.0, *)) {
68
-		NSDictionary* fontAttributes = [RNNFontAttributesCreator createFontAttributesWithFontFamily:fontFamily fontSize:fontSize color:color];
68
+		NSDictionary* fontAttributes = [RNNFontAttributesCreator createWithFontFamily:fontFamily fontSize:fontSize fontWeight:fontWeight color:color];
69 69
 		self.navigationBar.largeTitleTextAttributes = fontAttributes;
70 70
 	}
71 71
 }

+ 26
- 0
lib/src/interfaces/Options.ts Bestand weergeven

@@ -3,6 +3,7 @@ import { ImageRequireSource, Insets } from 'react-native';
3 3
 
4 4
 type Color = string;
5 5
 type FontFamily = string;
6
+type FontWeight = 'regular' | 'bold' | 'thin' | 'ultraLight' | 'light' | 'medium' | 'semibold' | 'heavy' | 'black';
6 7
 type LayoutOrientation = 'portrait' | 'landscape';
7 8
 type AndroidDensityNumber = number;
8 9
 type SystemItemIcon = 'done' | 'cancel' | 'edit'
@@ -119,6 +120,11 @@ export interface OptionsTopBarLargeTitle {
119 120
    * Set the font family of large title's text
120 121
    */
121 122
   fontFamily?: FontFamily;
123
+  /**
124
+   * Set the font weight, ignore fontFamily and use the iOS system fonts instead
125
+   * #### (iOS specific)
126
+   */
127
+  fontWeight?: FontWeight;
122 128
 }
123 129
 
124 130
 export interface OptionsTopBarTitle {
@@ -140,6 +146,11 @@ export interface OptionsTopBarTitle {
140 146
    * Make sure that the font is available
141 147
    */
142 148
   fontFamily?: FontFamily;
149
+  /**
150
+   * Set the font weight, ignore fontFamily and use the iOS system fonts instead
151
+   * #### (iOS specific)
152
+   */
153
+  fontWeight?: FontWeight;
143 154
   /**
144 155
    * Custom component as the title view
145 156
    */
@@ -190,6 +201,11 @@ export interface OptionsTopBarSubtitle {
190 201
    * Set subtitle font family
191 202
    */
192 203
   fontFamily?: FontFamily;
204
+  /**
205
+   * Set the font weight, ignore fontFamily and use the iOS system fonts instead
206
+   * #### (iOS specific)
207
+   */
208
+  fontWeight?: FontWeight;
193 209
   /**
194 210
    * Set subtitle alignment
195 211
    */
@@ -289,6 +305,11 @@ export interface OptionsTopBarButton {
289 305
    * Set the button font family
290 306
    */
291 307
   fontFamily?: string;
308
+  /**
309
+   * Set the font weight, ignore fontFamily and use the iOS system fonts instead
310
+   * #### (iOS specific)
311
+   */
312
+  fontWeight?: FontWeight;
292 313
   /**
293 314
    * Set the button enabled or disabled
294 315
    * @default true
@@ -565,6 +586,11 @@ export interface OptionsBottomTab {
565 586
    * Set the text font family
566 587
    */
567 588
   fontFamily?: FontFamily;
589
+    /**
590
+   * Set the font weight, ignore fontFamily and use the iOS system fonts instead
591
+   * #### (iOS specific)
592
+   */
593
+  fontWeight?: FontWeight;
568 594
   /**
569 595
    * Set the text font size
570 596
    */