yogevbd 6 years ago
parent
commit
78596d9332

+ 3
- 0
lib/ios/RNNButtonOptions.h View File

@@ -6,5 +6,8 @@
6 6
 @property (nonatomic, strong) NSNumber* fontSize;
7 7
 @property (nonatomic, strong) NSNumber* color;
8 8
 @property (nonatomic, strong) NSNumber* disabledColor;
9
+@property (nonatomic, strong) NSNumber* icon;
10
+@property (nonatomic, strong) NSString* text;
11
+@property (nonatomic, strong) NSNumber* enabled;
9 12
 
10 13
 @end

+ 1
- 1
lib/ios/RNNNavigationButtons.h View File

@@ -7,7 +7,7 @@
7 7
 
8 8
 -(instancetype)initWithViewController:(RNNRootViewController*)viewController;
9 9
 
10
--(void)applyLeftButtons:(NSArray*)leftButtons rightButtons:(NSArray*)rightButtons defaultButtonStyle:(RNNButtonOptions *)defaultButtonStyle;
10
+-(void)applyLeftButtons:(NSArray*)leftButtons rightButtons:(NSArray*)rightButtons defaultLeftButtonStyle:(RNNButtonOptions *)defaultLeftButtonStyle defaultRightButtonStyle:(RNNButtonOptions *)defaultRightButtonStyle;
11 11
 
12 12
 @end
13 13
 

+ 23
- 21
lib/ios/RNNNavigationButtons.m View File

@@ -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
 }

+ 2
- 1
lib/ios/RNNTopBarOptions.h View File

@@ -27,7 +27,8 @@
27 27
 @property (nonatomic, strong) RNNSubtitleOptions* subtitle;
28 28
 @property (nonatomic, strong) RNNBackgroundOptions* background;
29 29
 @property (nonatomic, strong) RNNBackButtonOptions* backButton;
30
-@property (nonatomic, strong) RNNButtonOptions* button;
30
+@property (nonatomic, strong) RNNButtonOptions* leftButtonStyle;
31
+@property (nonatomic, strong) RNNButtonOptions* rightButtonStyle;
31 32
 @property (nonatomic, strong) NSNumber* searchBar;
32 33
 @property (nonatomic, strong) NSNumber* searchBarHiddenWhenScrolling;
33 34
 @property (nonatomic, strong) NSString* searchBarPlaceholder;

+ 25
- 1
lib/ios/RNNTopBarOptions.m View File

@@ -158,7 +158,31 @@ extern const NSInteger BLUR_TOPBAR_TAG;
158 158
 	
159 159
 	if (self.rightButtons || self.leftButtons) {
160 160
 		_navigationButtons = [[RNNNavigationButtons alloc] initWithViewController:(RNNRootViewController*)viewController];
161
-		[_navigationButtons applyLeftButtons:self.leftButtons rightButtons:self.rightButtons defaultButtonStyle:_button];
161
+		[_navigationButtons applyLeftButtons:self.leftButtons rightButtons:self.rightButtons defaultLeftButtonStyle:self.leftButtonStyle defaultRightButtonStyle:self.rightButtonStyle];
162
+	}
163
+}
164
+
165
+- (void)setLeftButtons:(id)leftButtons {
166
+	if ([leftButtons isKindOfClass:[NSArray class]]) {
167
+		_leftButtons = leftButtons;
168
+	} else if ([leftButtons isKindOfClass:[NSDictionary class]]) {
169
+		if (leftButtons[@"id"]) {
170
+			_leftButtons = @[leftButtons];
171
+		} else {
172
+			[_leftButtonStyle mergeWith:leftButtons];
173
+		}
174
+	}
175
+}
176
+
177
+- (void)setRightButtons:(id)rightButtons {
178
+	if ([rightButtons isKindOfClass:[NSArray class]]) {
179
+		_rightButtons = rightButtons;
180
+	} else if ([rightButtons isKindOfClass:[NSDictionary class]]) {
181
+		if (rightButtons[@"id"]) {
182
+			_rightButtons = @[rightButtons];
183
+		} else {
184
+			[_rightButtonStyle mergeWith:rightButtons];
185
+		}
162 186
 	}
163 187
 }
164 188