yogevbd 6 years ago
parent
commit
78596d9332

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

6
 @property (nonatomic, strong) NSNumber* fontSize;
6
 @property (nonatomic, strong) NSNumber* fontSize;
7
 @property (nonatomic, strong) NSNumber* color;
7
 @property (nonatomic, strong) NSNumber* color;
8
 @property (nonatomic, strong) NSNumber* disabledColor;
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
 @end
13
 @end

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

7
 
7
 
8
 -(instancetype)initWithViewController:(RNNRootViewController*)viewController;
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
 @end
12
 @end
13
 
13
 

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

8
 @property (weak, nonatomic) RNNRootViewController* viewController;
8
 @property (weak, nonatomic) RNNRootViewController* viewController;
9
 @property (strong, nonatomic) NSArray* rightButtons;
9
 @property (strong, nonatomic) NSArray* rightButtons;
10
 @property (strong, nonatomic) NSArray* leftButtons;
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
 @end
14
 @end
14
 
15
 
22
 	return self;
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
 	if (leftButtons) {
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
 	if (rightButtons) {
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
 	NSMutableArray *barButtonItems = [NSMutableArray new];
39
 	NSMutableArray *barButtonItems = [NSMutableArray new];
38
 	NSArray* resolvedButtons = [self resolveButtons:buttons];
40
 	NSArray* resolvedButtons = [self resolveButtons:buttons];
39
 	for (NSDictionary *button in resolvedButtons) {
41
 	for (NSDictionary *button in resolvedButtons) {
40
-		RNNUIBarButtonItem* barButtonItem = [self buildButton:button];
42
+		RNNUIBarButtonItem* barButtonItem = [self buildButton:button defaultStyle:defaultStyle];
41
 		if(barButtonItem) {
43
 		if(barButtonItem) {
42
 			[barButtonItems addObject:barButtonItem];
44
 			[barButtonItems addObject:barButtonItem];
43
 		}
45
 		}
62
 	}
64
 	}
63
 }
65
 }
64
 
66
 
65
--(RNNUIBarButtonItem*)buildButton: (NSDictionary*)dictionary {
67
+-(RNNUIBarButtonItem*)buildButton: (NSDictionary*)dictionary defaultStyle:(RNNButtonOptions *)defaultStyle {
66
 	NSString* buttonId = dictionary[@"id"];
68
 	NSString* buttonId = dictionary[@"id"];
67
-	NSString* title = dictionary[@"text"];
69
+	NSString* title = [self getValue:dictionary[@"text"] withDefault:defaultStyle.text];
68
 	NSDictionary* component = dictionary[@"component"];
70
 	NSDictionary* component = dictionary[@"component"];
69
 	
71
 	
70
 	if (!buttonId) {
72
 	if (!buttonId) {
72
 	}
74
 	}
73
 	
75
 	
74
 	UIImage* iconImage = nil;
76
 	UIImage* iconImage = nil;
75
-	id icon = dictionary[@"icon"];
77
+	id icon = [self getValue:dictionary[@"icon"] withDefault:defaultStyle.icon];
76
 	if (icon) {
78
 	if (icon) {
77
 		iconImage = [RCTConvert UIImage:icon];
79
 		iconImage = [RCTConvert UIImage:icon];
78
 	}
80
 	}
97
 	barButtonItem.target = self;
99
 	barButtonItem.target = self;
98
 	barButtonItem.action = @selector(onButtonPress:);
100
 	barButtonItem.action = @selector(onButtonPress:);
99
 	
101
 	
100
-	NSNumber *enabled = dictionary[@"enabled"];
102
+	NSNumber *enabled = [self getValue:dictionary[@"enabled"] withDefault:defaultStyle.enabled];
101
 	BOOL enabledBool = enabled ? [enabled boolValue] : YES;
103
 	BOOL enabledBool = enabled ? [enabled boolValue] : YES;
102
 	[barButtonItem setEnabled:enabledBool];
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
 	NSMutableDictionary* textAttributes = [[NSMutableDictionary alloc] init];
106
 	NSMutableDictionary* textAttributes = [[NSMutableDictionary alloc] init];
111
 	NSMutableDictionary* disabledTextAttributes = [[NSMutableDictionary alloc] init];
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
 	if (color) {
110
 	if (color) {
115
 		[textAttributes setObject:color forKey:NSForegroundColorAttributeName];
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
 	if (disabledColor) {
117
 	if (disabledColor) {
120
 		UIColor *color = disabledColor;
118
 		UIColor *color = disabledColor;
121
 		[disabledTextAttributes setObject:color forKey:NSForegroundColorAttributeName];
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
 	UIFont *font = nil;
124
 	UIFont *font = nil;
127
 	if (fontFamily) {
125
 	if (fontFamily) {
128
 		font = [UIFont fontWithName:fontFamily size:[fontSize floatValue]];
126
 		font = [UIFont fontWithName:fontFamily size:[fontSize floatValue]];
173
 	}
171
 	}
174
 }
172
 }
175
 
173
 
174
+- (id)getValue:(id)value withDefault:(id)defaultValue {
175
+	return value ? value : defaultValue;
176
+}
177
+
176
 -(void)onButtonPress:(RNNUIBarButtonItem*)barButtonItem {
178
 -(void)onButtonPress:(RNNUIBarButtonItem*)barButtonItem {
177
 	[self.viewController.eventEmitter sendOnNavigationButtonPressed:self.viewController.componentId buttonId:barButtonItem.buttonId];
179
 	[self.viewController.eventEmitter sendOnNavigationButtonPressed:self.viewController.componentId buttonId:barButtonItem.buttonId];
178
 }
180
 }

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

27
 @property (nonatomic, strong) RNNSubtitleOptions* subtitle;
27
 @property (nonatomic, strong) RNNSubtitleOptions* subtitle;
28
 @property (nonatomic, strong) RNNBackgroundOptions* background;
28
 @property (nonatomic, strong) RNNBackgroundOptions* background;
29
 @property (nonatomic, strong) RNNBackButtonOptions* backButton;
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
 @property (nonatomic, strong) NSNumber* searchBar;
32
 @property (nonatomic, strong) NSNumber* searchBar;
32
 @property (nonatomic, strong) NSNumber* searchBarHiddenWhenScrolling;
33
 @property (nonatomic, strong) NSNumber* searchBarHiddenWhenScrolling;
33
 @property (nonatomic, strong) NSString* searchBarPlaceholder;
34
 @property (nonatomic, strong) NSString* searchBarPlaceholder;

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

158
 	
158
 	
159
 	if (self.rightButtons || self.leftButtons) {
159
 	if (self.rightButtons || self.leftButtons) {
160
 		_navigationButtons = [[RNNNavigationButtons alloc] initWithViewController:(RNNRootViewController*)viewController];
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