|
@@ -8,7 +8,8 @@
|
8
|
8
|
@property (weak, nonatomic) RNNRootViewController* viewController;
|
9
|
9
|
@property (strong, nonatomic) NSArray* rightButtons;
|
10
|
10
|
@property (strong, nonatomic) NSArray* leftButtons;
|
11
|
|
-@property (strong, nonatomic) RNNButtonOptions* defaultButtonStyle;
|
|
11
|
+@property (strong, nonatomic) RNNButtonOptions* defaultLeftButtonStyle;
|
|
12
|
+@property (strong, nonatomic) RNNButtonOptions* defaultRightButtonStyle;
|
12
|
13
|
|
13
|
14
|
@end
|
14
|
15
|
|
|
@@ -22,22 +23,23 @@
|
22
|
23
|
return self;
|
23
|
24
|
}
|
24
|
25
|
|
25
|
|
--(void)applyLeftButtons:(NSArray*)leftButtons rightButtons:(NSArray*)rightButtons defaultButtonStyle:(RNNButtonOptions *)defaultButtonStyle {
|
26
|
|
- _defaultButtonStyle = defaultButtonStyle;
|
|
26
|
+- (void)applyLeftButtons:(NSArray *)leftButtons rightButtons:(NSArray *)rightButtons defaultLeftButtonStyle:(RNNButtonOptions *)defaultLeftButtonStyle defaultRightButtonStyle:(RNNButtonOptions *)defaultRightButtonStyle {
|
|
27
|
+ _defaultLeftButtonStyle = defaultLeftButtonStyle;
|
|
28
|
+ _defaultRightButtonStyle = defaultRightButtonStyle;
|
27
|
29
|
if (leftButtons) {
|
28
|
|
- [self setButtons:leftButtons side:@"left" animated:NO];
|
|
30
|
+ [self setButtons:leftButtons side:@"left" animated:NO defaultStyle:_defaultLeftButtonStyle];
|
29
|
31
|
}
|
30
|
32
|
|
31
|
33
|
if (rightButtons) {
|
32
|
|
- [self setButtons:rightButtons side:@"right" animated:NO];
|
|
34
|
+ [self setButtons:rightButtons side:@"right" animated:NO defaultStyle:_defaultRightButtonStyle];
|
33
|
35
|
}
|
34
|
36
|
}
|
35
|
37
|
|
36
|
|
--(void)setButtons:(NSArray*)buttons side:(NSString*)side animated:(BOOL)animated {
|
|
38
|
+-(void)setButtons:(NSArray*)buttons side:(NSString*)side animated:(BOOL)animated defaultStyle:(RNNButtonOptions *)defaultStyle {
|
37
|
39
|
NSMutableArray *barButtonItems = [NSMutableArray new];
|
38
|
40
|
NSArray* resolvedButtons = [self resolveButtons:buttons];
|
39
|
41
|
for (NSDictionary *button in resolvedButtons) {
|
40
|
|
- RNNUIBarButtonItem* barButtonItem = [self buildButton:button];
|
|
42
|
+ RNNUIBarButtonItem* barButtonItem = [self buildButton:button defaultStyle:defaultStyle];
|
41
|
43
|
if(barButtonItem) {
|
42
|
44
|
[barButtonItems addObject:barButtonItem];
|
43
|
45
|
}
|
|
@@ -62,9 +64,9 @@
|
62
|
64
|
}
|
63
|
65
|
}
|
64
|
66
|
|
65
|
|
--(RNNUIBarButtonItem*)buildButton: (NSDictionary*)dictionary {
|
|
67
|
+-(RNNUIBarButtonItem*)buildButton: (NSDictionary*)dictionary defaultStyle:(RNNButtonOptions *)defaultStyle {
|
66
|
68
|
NSString* buttonId = dictionary[@"id"];
|
67
|
|
- NSString* title = dictionary[@"text"];
|
|
69
|
+ NSString* title = [self getValue:dictionary[@"text"] withDefault:defaultStyle.text];
|
68
|
70
|
NSDictionary* component = dictionary[@"component"];
|
69
|
71
|
|
70
|
72
|
if (!buttonId) {
|
|
@@ -72,7 +74,7 @@
|
72
|
74
|
}
|
73
|
75
|
|
74
|
76
|
UIImage* iconImage = nil;
|
75
|
|
- id icon = dictionary[@"icon"];
|
|
77
|
+ id icon = [self getValue:dictionary[@"icon"] withDefault:defaultStyle.icon];
|
76
|
78
|
if (icon) {
|
77
|
79
|
iconImage = [RCTConvert UIImage:icon];
|
78
|
80
|
}
|
|
@@ -97,32 +99,28 @@
|
97
|
99
|
barButtonItem.target = self;
|
98
|
100
|
barButtonItem.action = @selector(onButtonPress:);
|
99
|
101
|
|
100
|
|
- NSNumber *enabled = dictionary[@"enabled"];
|
|
102
|
+ NSNumber *enabled = [self getValue:dictionary[@"enabled"] withDefault:defaultStyle.enabled];
|
101
|
103
|
BOOL enabledBool = enabled ? [enabled boolValue] : YES;
|
102
|
104
|
[barButtonItem setEnabled:enabledBool];
|
103
|
105
|
|
104
|
|
- NSNumber *disableIconTintString = dictionary[@"disableIconTint"];
|
105
|
|
- BOOL disableIconTint = disableIconTintString ? [disableIconTintString boolValue] : NO;
|
106
|
|
- if (disableIconTint) {
|
107
|
|
- [barButtonItem setImage:[barButtonItem.image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
|
108
|
|
- }
|
109
|
|
-
|
110
|
106
|
NSMutableDictionary* textAttributes = [[NSMutableDictionary alloc] init];
|
111
|
107
|
NSMutableDictionary* disabledTextAttributes = [[NSMutableDictionary alloc] init];
|
112
|
108
|
|
113
|
|
- UIColor* color = [self color:dictionary[@"color"] defaultColor:_defaultButtonStyle.color];
|
|
109
|
+ UIColor* color = [self color:dictionary[@"color"] defaultColor:defaultStyle.color];
|
114
|
110
|
if (color) {
|
115
|
111
|
[textAttributes setObject:color forKey:NSForegroundColorAttributeName];
|
|
112
|
+ [barButtonItem setImage:[iconImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
|
|
113
|
+ [barButtonItem setTintColor:color];
|
116
|
114
|
}
|
117
|
115
|
|
118
|
|
- UIColor* disabledColor = [self color:dictionary[@"disabledColor"] defaultColor:_defaultButtonStyle.disabledColor];;
|
|
116
|
+ UIColor* disabledColor = [self color:dictionary[@"disabledColor"] defaultColor:defaultStyle.disabledColor];;
|
119
|
117
|
if (disabledColor) {
|
120
|
118
|
UIColor *color = disabledColor;
|
121
|
119
|
[disabledTextAttributes setObject:color forKey:NSForegroundColorAttributeName];
|
122
|
120
|
}
|
123
|
121
|
|
124
|
|
- NSNumber* fontSize = [self fontSize:dictionary[@"fontSize"] defaultFontSize:_defaultButtonStyle.fontSize];
|
125
|
|
- NSString* fontFamily = [self fontFamily:dictionary[@"fontFamily"] defaultFontFamily:_defaultButtonStyle.fontFamily];
|
|
122
|
+ NSNumber* fontSize = [self fontSize:dictionary[@"fontSize"] defaultFontSize:defaultStyle.fontSize];
|
|
123
|
+ NSString* fontFamily = [self fontFamily:dictionary[@"fontFamily"] defaultFontFamily:defaultStyle.fontFamily];
|
126
|
124
|
UIFont *font = nil;
|
127
|
125
|
if (fontFamily) {
|
128
|
126
|
font = [UIFont fontWithName:fontFamily size:[fontSize floatValue]];
|
|
@@ -173,6 +171,10 @@
|
173
|
171
|
}
|
174
|
172
|
}
|
175
|
173
|
|
|
174
|
+- (id)getValue:(id)value withDefault:(id)defaultValue {
|
|
175
|
+ return value ? value : defaultValue;
|
|
176
|
+}
|
|
177
|
+
|
176
|
178
|
-(void)onButtonPress:(RNNUIBarButtonItem*)barButtonItem {
|
177
|
179
|
[self.viewController.eventEmitter sendOnNavigationButtonPressed:self.viewController.componentId buttonId:barButtonItem.buttonId];
|
178
|
180
|
}
|