Browse Source

Back button font family and font size (#5957)

* adding fontFamily to backButton Object

* hiding font button for android

* remove podfile.lock

* refactor uicontrolstate

* resolve backButton mergeOptions withDefault

* Add fontSize support

* Reset Podfile.lock

* Update OptionsScreen.js

* Update Options.ts

Co-authored-by: Andy <53788738+Andy40au@users.noreply.github.com>
Co-authored-by: Guy Carmeli <guyca@users.noreply.github.com>
Yogev Ben David 4 years ago
parent
commit
b4385883de
No account linked to committer's email address

+ 2
- 0
lib/ios/RNNBackButtonOptions.h View File

4
 
4
 
5
 @property (nonatomic, strong) Image* icon;
5
 @property (nonatomic, strong) Image* icon;
6
 @property (nonatomic, strong) Text* title;
6
 @property (nonatomic, strong) Text* title;
7
+@property (nonatomic, strong) Text* fontFamily;
8
+@property (nonatomic, strong) Number* fontSize;
7
 @property (nonatomic, strong) Text* transition;
9
 @property (nonatomic, strong) Text* transition;
8
 @property (nonatomic, strong) Color* color;
10
 @property (nonatomic, strong) Color* color;
9
 @property (nonatomic, strong) Bool* showTitle;
11
 @property (nonatomic, strong) Bool* showTitle;

+ 18
- 14
lib/ios/RNNBackButtonOptions.m View File

3
 @implementation RNNBackButtonOptions
3
 @implementation RNNBackButtonOptions
4
 
4
 
5
 - (instancetype)initWithDict:(NSDictionary *)dict {
5
 - (instancetype)initWithDict:(NSDictionary *)dict {
6
-	self = [super init];
7
-	
8
-	self.icon = [ImageParser parse:dict key:@"icon"];
9
-	self.title = [TextParser parse:dict key:@"title"];
10
-	self.transition = [TextParser parse:dict key:@"transition"];
11
-	self.color = [ColorParser parse:dict key:@"color"];
12
-	self.showTitle = [BoolParser parse:dict key:@"showTitle"];
13
-	self.visible = [BoolParser parse:dict key:@"visible"];
14
-	
15
-	return self;
6
+    self = [super init];
7
+    
8
+    self.icon = [ImageParser parse:dict key:@"icon"];
9
+    self.title = [TextParser parse:dict key:@"title"];
10
+    self.transition = [TextParser parse:dict key:@"transition"];
11
+    self.color = [ColorParser parse:dict key:@"color"];
12
+    self.showTitle = [BoolParser parse:dict key:@"showTitle"];
13
+    self.visible = [BoolParser parse:dict key:@"visible"];
14
+    self.fontFamily = [TextParser parse:dict key:@"fontFamily"];
15
+    self.fontSize = [NumberParser parse:dict key:@"fontSize"];
16
+    
17
+    return self;
16
 }
18
 }
17
 
19
 
18
 - (BOOL)hasValue {
20
 - (BOOL)hasValue {
19
-	return self.icon.hasValue ||
20
-			self.showTitle.hasValue ||
21
-			self.color.hasValue ||
22
-			self.title.hasValue;
21
+    return self.icon.hasValue ||
22
+    self.showTitle.hasValue ||
23
+    self.color.hasValue ||
24
+    self.fontFamily.hasValue ||
25
+    self.fontSize.hasValue ||
26
+    self.title.hasValue;
23
 }
27
 }
24
 
28
 
25
 
29
 

+ 12
- 6
lib/ios/TopBarPresenter.m View File

16
     [self setTitleAttributes:options.title];
16
     [self setTitleAttributes:options.title];
17
     [self setLargeTitleAttributes:options.largeTitle];
17
     [self setLargeTitleAttributes:options.largeTitle];
18
     [self showBorder:![options.noBorder getWithDefaultValue:NO]];
18
     [self showBorder:![options.noBorder getWithDefaultValue:NO]];
19
-    [self setBackButtonIcon:[options.backButton.icon getWithDefaultValue:nil] withColor:[options.backButton.color getWithDefaultValue:nil] title:[options.backButton.title getWithDefaultValue:nil] showTitle:[options.backButton.showTitle getWithDefaultValue:YES]];
19
+    [self setBackButtonOptions:[options.backButton.icon getWithDefaultValue:nil] withColor:[options.backButton.color getWithDefaultValue:nil] title:[options.backButton.title getWithDefaultValue:nil] showTitle:[options.backButton.showTitle getWithDefaultValue:YES] fontFamily:[options.backButton.fontFamily getWithDefaultValue:nil] fontSize:[options.backButton.fontSize getWithDefaultValue:nil]];
20
 }
20
 }
21
 
21
 
22
 - (void)applyOptionsBeforePopping:(RNNTopBarOptions *)options {
22
 - (void)applyOptionsBeforePopping:(RNNTopBarOptions *)options {
48
     }
48
     }
49
     
49
     
50
     if (options.backButton.hasValue) {
50
     if (options.backButton.hasValue) {
51
-        [self setBackButtonIcon:[withDefault.backButton.icon getWithDefaultValue:nil] withColor:[withDefault.backButton.color getWithDefaultValue:nil] title:[withDefault.backButton.title getWithDefaultValue:nil] showTitle:[withDefault.backButton.showTitle getWithDefaultValue:YES]];
51
+        [self setBackButtonOptions:[withDefault.backButton.icon getWithDefaultValue:nil] withColor:[withDefault.backButton.color getWithDefaultValue:nil] title:[withDefault.backButton.title getWithDefaultValue:nil] showTitle:[withDefault.backButton.showTitle getWithDefaultValue:YES] fontFamily:[withDefault.backButton.fontFamily getWithDefaultValue:nil] fontSize:[options.backButton.fontSize getWithDefaultValue:nil]];
52
     }
52
     }
53
 }
53
 }
54
 
54
 
111
     }
111
     }
112
 }
112
 }
113
 
113
 
114
-- (void)setBackButtonIcon:(UIImage *)icon withColor:(UIColor *)color title:(NSString *)title showTitle:(BOOL)showTitle {
115
-    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
114
+- (void)setBackButtonOptions:(UIImage *)icon withColor:(UIColor *)color title:(NSString *)title showTitle:(BOOL)showTitle fontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize {
115
+	UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
116
     NSArray* stackChildren = self.navigationController.viewControllers;
116
     NSArray* stackChildren = self.navigationController.viewControllers;
117
     icon = color
117
     icon = color
118
     ? [[icon withTintColor:color] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
118
     ? [[icon withTintColor:color] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
119
     : icon;
119
     : icon;
120
     [self setBackIndicatorImage:icon withColor:color];
120
     [self setBackIndicatorImage:icon withColor:color];
121
-
121
+    
122
     UIViewController *lastViewControllerInStack = stackChildren.count > 1 ? stackChildren[stackChildren.count - 2] : self.navigationController.topViewController;
122
     UIViewController *lastViewControllerInStack = stackChildren.count > 1 ? stackChildren[stackChildren.count - 2] : self.navigationController.topViewController;
123
 
123
 
124
     if (showTitle) {
124
     if (showTitle) {
125
         backItem.title = title ? title : lastViewControllerInStack.navigationItem.title;
125
         backItem.title = title ? title : lastViewControllerInStack.navigationItem.title;
126
     }
126
     }
127
     backItem.tintColor = color;
127
     backItem.tintColor = color;
128
-
128
+	
129
+    if (fontFamily) {
130
+        CGFloat resolvedFontSize = fontSize ? fontSize.floatValue : 17.0;
131
+        [backItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIFont fontWithName:fontFamily size:resolvedFontSize], NSFontAttributeName, nil] forState:UIControlStateNormal];
132
+        [backItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIFont fontWithName:fontFamily size:resolvedFontSize], NSFontAttributeName, nil] forState:UIControlStateHighlighted];
133
+    }
134
+    
129
     lastViewControllerInStack.navigationItem.backBarButtonItem = backItem;
135
     lastViewControllerInStack.navigationItem.backBarButtonItem = backItem;
130
 }
136
 }
131
 
137
 

+ 8
- 0
lib/src/interfaces/Options.ts View File

264
    * Back button icon and text color
264
    * Back button icon and text color
265
    */
265
    */
266
   color?: Color;
266
   color?: Color;
267
+  /**
268
+   * Set subtitle font size
269
+   */
270
+  fontSize?: number;
271
+  /**
272
+   * Set subtitle font family
273
+   */
274
+  fontFamily?: FontFamily;
267
 }
275
 }
268
 
276
 
269
 export interface OptionsTopBarBackground {
277
 export interface OptionsTopBarBackground {

+ 5
- 0
playground/ios/NavigationTests/RNNNavigationOptionsTest.m View File

20
 	XCTAssertTrue(options.topBar.background.color);
20
 	XCTAssertTrue(options.topBar.background.color);
21
 }
21
 }
22
 
22
 
23
+- (void)testAddsFontToBackButtonOptions {
24
+	RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{@"topBar": @{@"backButton" : @{@"fontFamily" : @"HelveticaNeue"}}}];
25
+	XCTAssertTrue([options.topBar.backButton.fontFamily.get isEqual:@"HelveticaNeue"]);
26
+}
27
+
23
 - (void)testChangeRNNNavigationOptionsDynamically {
28
 - (void)testChangeRNNNavigationOptionsDynamically {
24
 	RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{@"topBar": @{@"background" : @{@"color" : @(0xff0000ff)}}}];
29
 	RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{@"topBar": @{@"background" : @{@"color" : @(0xff0000ff)}}}];
25
 	NSDictionary* dynamicOptionsDict = @{@"topBar": @{@"textColor" : @(0xffff00ff), @"title" : @{@"text": @"hello"}}};
30
 	NSDictionary* dynamicOptionsDict = @{@"topBar": @{@"textColor" : @(0xffff00ff), @"title" : @{@"text": @"hello"}}};