Browse Source

default topBar buttons options support

yogevbd 6 years ago
parent
commit
26c72eaa4c

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

1
+#import "RNNOptions.h"
2
+
3
+@interface RNNButtonOptions : RNNOptions
4
+
5
+@property (nonatomic, strong) NSString* fontFamily;
6
+@property (nonatomic, strong) NSNumber* fontSize;
7
+@property (nonatomic, strong) NSNumber* color;
8
+@property (nonatomic, strong) NSNumber* disabledColor;
9
+
10
+@end

+ 5
- 0
lib/ios/RNNButtonOptions.m View File

1
+#import "RNNButtonOptions.h"
2
+
3
+@implementation RNNButtonOptions
4
+
5
+@end

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

1
 #import <Foundation/Foundation.h>
1
 #import <Foundation/Foundation.h>
2
 #import <UIKit/UIKit.h>
2
 #import <UIKit/UIKit.h>
3
 #import "RNNRootViewController.h"
3
 #import "RNNRootViewController.h"
4
+#import "RNNButtonOptions.h"
4
 
5
 
5
 @interface RNNNavigationButtons : NSObject
6
 @interface RNNNavigationButtons : NSObject
6
 
7
 
7
 -(instancetype)initWithViewController:(RNNRootViewController*)viewController;
8
 -(instancetype)initWithViewController:(RNNRootViewController*)viewController;
8
 
9
 
9
--(void)applyLeftButtons:(NSArray*)leftButtons rightButtons:(NSArray*)rightButtons;
10
+-(void)applyLeftButtons:(NSArray*)leftButtons rightButtons:(NSArray*)rightButtons defaultButtonStyle:(RNNButtonOptions *)defaultButtonStyle;
10
 
11
 
11
 @end
12
 @end
12
 
13
 

+ 37
- 7
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
 
12
 
12
 @end
13
 @end
13
 
14
 
21
 	return self;
22
 	return self;
22
 }
23
 }
23
 
24
 
24
--(void)applyLeftButtons:(NSArray*)leftButtons rightButtons:(NSArray*)rightButtons {
25
+-(void)applyLeftButtons:(NSArray*)leftButtons rightButtons:(NSArray*)rightButtons defaultButtonStyle:(RNNButtonOptions *)defaultButtonStyle {
26
+	_defaultButtonStyle = defaultButtonStyle;
25
 	if (leftButtons) {
27
 	if (leftButtons) {
26
 		[self setButtons:leftButtons side:@"left" animated:NO];
28
 		[self setButtons:leftButtons side:@"left" animated:NO];
27
 	}
29
 	}
99
 	NSMutableDictionary* textAttributes = [[NSMutableDictionary alloc] init];
101
 	NSMutableDictionary* textAttributes = [[NSMutableDictionary alloc] init];
100
 	NSMutableDictionary* disabledTextAttributes = [[NSMutableDictionary alloc] init];
102
 	NSMutableDictionary* disabledTextAttributes = [[NSMutableDictionary alloc] init];
101
 	
103
 	
102
-	id color = dictionary[@"color"];
104
+	UIColor* color = [self color:dictionary[@"color"] defaultColor:_defaultButtonStyle.color];
103
 	if (color) {
105
 	if (color) {
104
-		[textAttributes setObject:[RCTConvert UIColor:color] forKey:NSForegroundColorAttributeName];
106
+		[textAttributes setObject:color forKey:NSForegroundColorAttributeName];
105
 	}
107
 	}
106
 	
108
 	
107
-	NSNumber* disabledColor = dictionary[@"disabledColor"];
109
+	UIColor* disabledColor = [self color:dictionary[@"disabledColor"] defaultColor:_defaultButtonStyle.disabledColor];;
108
 	if (disabledColor) {
110
 	if (disabledColor) {
109
-		UIColor *color = [RCTConvert UIColor:disabledColor];
111
+		UIColor *color = disabledColor;
110
 		[disabledTextAttributes setObject:color forKey:NSForegroundColorAttributeName];
112
 		[disabledTextAttributes setObject:color forKey:NSForegroundColorAttributeName];
111
 	}
113
 	}
112
 	
114
 	
113
-	NSNumber* fontSize = dictionary[@"fontSize"] ? dictionary[@"fontSize"] : @(17);
114
-	NSString* fontFamily = dictionary[@"fontFamily"];
115
+	NSNumber* fontSize = [self fontSize:dictionary[@"fontSize"] defaultFontSize:_defaultButtonStyle.fontSize];
116
+	NSString* fontFamily = [self fontFamily:dictionary[@"fontFamily"] defaultFontFamily:_defaultButtonStyle.fontFamily];
115
 	if (fontFamily) {
117
 	if (fontFamily) {
116
 		[textAttributes setObject:[UIFont fontWithName:fontFamily size:[fontSize floatValue]] forKey:NSFontAttributeName];
118
 		[textAttributes setObject:[UIFont fontWithName:fontFamily size:[fontSize floatValue]] forKey:NSFontAttributeName];
117
 	} else{
119
 	} else{
130
 	return barButtonItem;
132
 	return barButtonItem;
131
 }
133
 }
132
 
134
 
135
+- (UIColor *)color:(NSNumber *)color defaultColor:(NSNumber *)defaultColor {
136
+	if (color) {
137
+		return [RCTConvert UIColor:color];
138
+	} else if (defaultColor) {
139
+		return [RCTConvert UIColor:defaultColor];
140
+	}
141
+		
142
+	return nil;
143
+}
144
+
145
+- (NSNumber *)fontSize:(NSNumber *)fontSize defaultFontSize:(NSNumber *)defaultFontSize {
146
+	if (fontSize) {
147
+		return fontSize;
148
+	} else if (defaultFontSize) {
149
+		return defaultFontSize;
150
+	}
151
+	
152
+	return @(17);
153
+}
154
+
155
+- (NSString *)fontFamily:(NSString *)fontFamily defaultFontFamily:(NSString *)defaultFontFamily {
156
+	if (fontFamily) {
157
+		return fontFamily;
158
+	} else {
159
+		return defaultFontFamily;
160
+	}
161
+}
162
+
133
 -(void)onButtonPress:(RNNUIBarButtonItem*)barButtonItem {
163
 -(void)onButtonPress:(RNNUIBarButtonItem*)barButtonItem {
134
 	[self.viewController.eventEmitter sendOnNavigationButtonPressed:self.viewController.componentId buttonId:barButtonItem.buttonId];
164
 	[self.viewController.eventEmitter sendOnNavigationButtonPressed:self.viewController.componentId buttonId:barButtonItem.buttonId];
135
 }
165
 }

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

5
 #import "RNNBackgroundOptions.h"
5
 #import "RNNBackgroundOptions.h"
6
 #import "RNNComponentOptions.h"
6
 #import "RNNComponentOptions.h"
7
 #import "RNNBackButtonOptions.h"
7
 #import "RNNBackButtonOptions.h"
8
+#import "RNNButtonOptions.h"
8
 
9
 
9
 @interface RNNTopBarOptions : RNNOptions
10
 @interface RNNTopBarOptions : RNNOptions
10
 
11
 
25
 @property (nonatomic, strong) RNNSubtitleOptions* subtitle;
26
 @property (nonatomic, strong) RNNSubtitleOptions* subtitle;
26
 @property (nonatomic, strong) RNNBackgroundOptions* background;
27
 @property (nonatomic, strong) RNNBackgroundOptions* background;
27
 @property (nonatomic, strong) RNNBackButtonOptions* backButton;
28
 @property (nonatomic, strong) RNNBackButtonOptions* backButton;
29
+@property (nonatomic, strong) RNNButtonOptions* button;
28
 @property (nonatomic, strong) NSNumber* searchBar;
30
 @property (nonatomic, strong) NSNumber* searchBar;
29
 @property (nonatomic, strong) NSNumber* searchBarHiddenWhenScrolling;
31
 @property (nonatomic, strong) NSNumber* searchBarHiddenWhenScrolling;
30
 @property (nonatomic, strong) NSString* searchBarPlaceholder;
32
 @property (nonatomic, strong) NSString* searchBarPlaceholder;

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

149
 	
149
 	
150
 	if (self.rightButtons || self.leftButtons) {
150
 	if (self.rightButtons || self.leftButtons) {
151
 		_navigationButtons = [[RNNNavigationButtons alloc] initWithViewController:(RNNRootViewController*)viewController];
151
 		_navigationButtons = [[RNNNavigationButtons alloc] initWithViewController:(RNNRootViewController*)viewController];
152
-		[_navigationButtons applyLeftButtons:self.leftButtons rightButtons:self.rightButtons];
152
+		[_navigationButtons applyLeftButtons:self.leftButtons rightButtons:self.rightButtons defaultButtonStyle:_button];
153
 	}
153
 	}
154
 }
154
 }
155
 
155
 

+ 8
- 0
lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj View File

110
 		507F43F81FF525B500D9425B /* RNNSegmentedControl.h in Headers */ = {isa = PBXBuildFile; fileRef = 507F43F61FF525B500D9425B /* RNNSegmentedControl.h */; };
110
 		507F43F81FF525B500D9425B /* RNNSegmentedControl.h in Headers */ = {isa = PBXBuildFile; fileRef = 507F43F61FF525B500D9425B /* RNNSegmentedControl.h */; };
111
 		507F43F91FF525B500D9425B /* RNNSegmentedControl.m in Sources */ = {isa = PBXBuildFile; fileRef = 507F43F71FF525B500D9425B /* RNNSegmentedControl.m */; };
111
 		507F43F91FF525B500D9425B /* RNNSegmentedControl.m in Sources */ = {isa = PBXBuildFile; fileRef = 507F43F71FF525B500D9425B /* RNNSegmentedControl.m */; };
112
 		507F44201FFA8A8800D9425B /* RNNRootViewProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 507F441F1FFA8A8800D9425B /* RNNRootViewProtocol.h */; };
112
 		507F44201FFA8A8800D9425B /* RNNRootViewProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 507F441F1FFA8A8800D9425B /* RNNRootViewProtocol.h */; };
113
+		50887C1520ECC5C200D06111 /* RNNButtonOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 50887C1320ECC5C200D06111 /* RNNButtonOptions.h */; };
114
+		50887C1620ECC5C200D06111 /* RNNButtonOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 50887C1420ECC5C200D06111 /* RNNButtonOptions.m */; };
113
 		50A00C37200F84D6000F01A6 /* RNNOverlayOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 50A00C35200F84D6000F01A6 /* RNNOverlayOptions.h */; };
115
 		50A00C37200F84D6000F01A6 /* RNNOverlayOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 50A00C35200F84D6000F01A6 /* RNNOverlayOptions.h */; };
114
 		50A00C38200F84D6000F01A6 /* RNNOverlayOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 50A00C36200F84D6000F01A6 /* RNNOverlayOptions.m */; };
116
 		50A00C38200F84D6000F01A6 /* RNNOverlayOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 50A00C36200F84D6000F01A6 /* RNNOverlayOptions.m */; };
115
 		50BE951220B5A787004F5DF5 /* RNNStatusBarOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 50BE951020B5A787004F5DF5 /* RNNStatusBarOptions.m */; };
117
 		50BE951220B5A787004F5DF5 /* RNNStatusBarOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 50BE951020B5A787004F5DF5 /* RNNStatusBarOptions.m */; };
328
 		507F43F61FF525B500D9425B /* RNNSegmentedControl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNSegmentedControl.h; sourceTree = "<group>"; };
330
 		507F43F61FF525B500D9425B /* RNNSegmentedControl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNSegmentedControl.h; sourceTree = "<group>"; };
329
 		507F43F71FF525B500D9425B /* RNNSegmentedControl.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNSegmentedControl.m; sourceTree = "<group>"; };
331
 		507F43F71FF525B500D9425B /* RNNSegmentedControl.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNSegmentedControl.m; sourceTree = "<group>"; };
330
 		507F441F1FFA8A8800D9425B /* RNNRootViewProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNNRootViewProtocol.h; sourceTree = "<group>"; };
332
 		507F441F1FFA8A8800D9425B /* RNNRootViewProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNNRootViewProtocol.h; sourceTree = "<group>"; };
333
+		50887C1320ECC5C200D06111 /* RNNButtonOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNButtonOptions.h; sourceTree = "<group>"; };
334
+		50887C1420ECC5C200D06111 /* RNNButtonOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNButtonOptions.m; sourceTree = "<group>"; };
331
 		50A00C35200F84D6000F01A6 /* RNNOverlayOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNOverlayOptions.h; sourceTree = "<group>"; };
335
 		50A00C35200F84D6000F01A6 /* RNNOverlayOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNOverlayOptions.h; sourceTree = "<group>"; };
332
 		50A00C36200F84D6000F01A6 /* RNNOverlayOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNOverlayOptions.m; sourceTree = "<group>"; };
336
 		50A00C36200F84D6000F01A6 /* RNNOverlayOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNOverlayOptions.m; sourceTree = "<group>"; };
333
 		50BE951020B5A787004F5DF5 /* RNNStatusBarOptions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNStatusBarOptions.m; sourceTree = "<group>"; };
337
 		50BE951020B5A787004F5DF5 /* RNNStatusBarOptions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNStatusBarOptions.m; sourceTree = "<group>"; };
558
 				50175CD0207A2AA1004FE91B /* RNNComponentOptions.m */,
562
 				50175CD0207A2AA1004FE91B /* RNNComponentOptions.m */,
559
 				A7626BFE1FC2FB6700492FB8 /* RNNTopBarOptions.h */,
563
 				A7626BFE1FC2FB6700492FB8 /* RNNTopBarOptions.h */,
560
 				A7626BFC1FC2FB2C00492FB8 /* RNNTopBarOptions.m */,
564
 				A7626BFC1FC2FB2C00492FB8 /* RNNTopBarOptions.m */,
565
+				50887C1320ECC5C200D06111 /* RNNButtonOptions.h */,
566
+				50887C1420ECC5C200D06111 /* RNNButtonOptions.m */,
561
 				502CB46C20CD1DDA0019B2FE /* RNNBackButtonOptions.h */,
567
 				502CB46C20CD1DDA0019B2FE /* RNNBackButtonOptions.h */,
562
 				502CB46D20CD1DDA0019B2FE /* RNNBackButtonOptions.m */,
568
 				502CB46D20CD1DDA0019B2FE /* RNNBackButtonOptions.m */,
563
 				50570B242061473D006A1B5C /* RNNTitleOptions.h */,
569
 				50570B242061473D006A1B5C /* RNNTitleOptions.h */,
850
 				50D031342005149000386B3D /* RNNOverlayManager.h in Headers */,
856
 				50D031342005149000386B3D /* RNNOverlayManager.h in Headers */,
851
 				7B1126A71E2D2B6C00F9B03B /* RNNEventEmitter.h in Headers */,
857
 				7B1126A71E2D2B6C00F9B03B /* RNNEventEmitter.h in Headers */,
852
 				E8A430111F9CB87B00B61A20 /* RNNAnimatedView.h in Headers */,
858
 				E8A430111F9CB87B00B61A20 /* RNNAnimatedView.h in Headers */,
859
+				50887C1520ECC5C200D06111 /* RNNButtonOptions.h in Headers */,
853
 				50C4A496206BDDBB00DB292E /* RNNSubtitleOptions.h in Headers */,
860
 				50C4A496206BDDBB00DB292E /* RNNSubtitleOptions.h in Headers */,
854
 				268692821E5054F800E2C612 /* RNNStore.h in Headers */,
861
 				268692821E5054F800E2C612 /* RNNStore.h in Headers */,
855
 				E8AEDB3C1F55A1C2000F5A6A /* RNNElementView.h in Headers */,
862
 				E8AEDB3C1F55A1C2000F5A6A /* RNNElementView.h in Headers */,
1064
 				263905AF1E4C6F440023D7D3 /* MMDrawerBarButtonItem.m in Sources */,
1071
 				263905AF1E4C6F440023D7D3 /* MMDrawerBarButtonItem.m in Sources */,
1065
 				E8AEDB4B1F5C0BAF000F5A6A /* RNNInteractivePopAnimator.m in Sources */,
1072
 				E8AEDB4B1F5C0BAF000F5A6A /* RNNInteractivePopAnimator.m in Sources */,
1066
 				7B4928091E70415400555040 /* RNNCommandsHandler.m in Sources */,
1073
 				7B4928091E70415400555040 /* RNNCommandsHandler.m in Sources */,
1074
+				50887C1620ECC5C200D06111 /* RNNButtonOptions.m in Sources */,
1067
 				268692831E5054F800E2C612 /* RNNStore.m in Sources */,
1075
 				268692831E5054F800E2C612 /* RNNStore.m in Sources */,
1068
 				7BC9346E1E26886E00EFA125 /* RNNControllerFactory.m in Sources */,
1076
 				7BC9346E1E26886E00EFA125 /* RNNControllerFactory.m in Sources */,
1069
 				507F43F91FF525B500D9425B /* RNNSegmentedControl.m in Sources */,
1077
 				507F43F91FF525B500D9425B /* RNNSegmentedControl.m in Sources */,