Procházet zdrojové kódy

default topBar buttons options support

yogevbd před 6 roky
rodič
revize
26c72eaa4c

+ 10
- 0
lib/ios/RNNButtonOptions.h Zobrazit soubor

@@ -0,0 +1,10 @@
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 Zobrazit soubor

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

+ 2
- 1
lib/ios/RNNNavigationButtons.h Zobrazit soubor

@@ -1,12 +1,13 @@
1 1
 #import <Foundation/Foundation.h>
2 2
 #import <UIKit/UIKit.h>
3 3
 #import "RNNRootViewController.h"
4
+#import "RNNButtonOptions.h"
4 5
 
5 6
 @interface RNNNavigationButtons : NSObject
6 7
 
7 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 12
 @end
12 13
 

+ 37
- 7
lib/ios/RNNNavigationButtons.m Zobrazit soubor

@@ -8,6 +8,7 @@
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 12
 
12 13
 @end
13 14
 
@@ -21,7 +22,8 @@
21 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 27
 	if (leftButtons) {
26 28
 		[self setButtons:leftButtons side:@"left" animated:NO];
27 29
 	}
@@ -99,19 +101,19 @@
99 101
 	NSMutableDictionary* textAttributes = [[NSMutableDictionary alloc] init];
100 102
 	NSMutableDictionary* disabledTextAttributes = [[NSMutableDictionary alloc] init];
101 103
 	
102
-	id color = dictionary[@"color"];
104
+	UIColor* color = [self color:dictionary[@"color"] defaultColor:_defaultButtonStyle.color];
103 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 110
 	if (disabledColor) {
109
-		UIColor *color = [RCTConvert UIColor:disabledColor];
111
+		UIColor *color = disabledColor;
110 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 117
 	if (fontFamily) {
116 118
 		[textAttributes setObject:[UIFont fontWithName:fontFamily size:[fontSize floatValue]] forKey:NSFontAttributeName];
117 119
 	} else{
@@ -130,6 +132,34 @@
130 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 163
 -(void)onButtonPress:(RNNUIBarButtonItem*)barButtonItem {
134 164
 	[self.viewController.eventEmitter sendOnNavigationButtonPressed:self.viewController.componentId buttonId:barButtonItem.buttonId];
135 165
 }

+ 2
- 0
lib/ios/RNNTopBarOptions.h Zobrazit soubor

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

+ 1
- 1
lib/ios/RNNTopBarOptions.m Zobrazit soubor

@@ -149,7 +149,7 @@ extern const NSInteger BLUR_TOPBAR_TAG;
149 149
 	
150 150
 	if (self.rightButtons || self.leftButtons) {
151 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 Zobrazit soubor

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