yogevbd преди 6 години
родител
ревизия
fbf8ea1387

+ 12
- 8
lib/ios/RNNControllerFactory.m Целия файл

@@ -96,8 +96,7 @@
96 96
 
97 97
 - (UIViewController<RNNRootViewProtocol> *)createComponent:(RNNLayoutNode*)node {
98 98
 	NSString* name = node.data[@"name"];
99
-	RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:_defaultOptionsDict];
100
-	[options mergeWith:node.data[@"options"]];
99
+	RNNNavigationOptions* options = [self createOptions:node.data[@"options"]];
101 100
 
102 101
 	NSString* componentId = node.nodeId;
103 102
 	RNNRootViewController* component = [[RNNRootViewController alloc] initWithName:name withOptions:options withComponentId:componentId rootViewCreator:_creator eventEmitter:_eventEmitter isExternalComponent:NO];
@@ -113,8 +112,7 @@
113 112
 	NSDictionary* props = node.data[@"passProps"];
114 113
 	
115 114
 	UIViewController* externalVC = [_store getExternalComponent:name props:props bridge:_bridge];
116
-	RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:_defaultOptionsDict];
117
-	[options mergeWith:node.data[@"options"]];
115
+	RNNNavigationOptions* options = [self createOptions:node.data[@"options"]];
118 116
 	
119 117
 	NSString* componentId = node.nodeId;
120 118
 	RNNRootViewController* component = [[RNNRootViewController alloc] initWithName:name withOptions:options withComponentId:componentId rootViewCreator:_creator eventEmitter:_eventEmitter isExternalComponent:YES];
@@ -130,7 +128,7 @@
130 128
 - (UIViewController<RNNRootViewProtocol> *)createStack:(RNNLayoutNode*)node {
131 129
 	RNNNavigationController* vc = [[RNNNavigationController alloc] init];
132 130
 	[vc setComponentId:node.nodeId];
133
-	NSDictionary* options = node.data[@"options"];
131
+	RNNNavigationOptions* options = [self createOptions:node.data[@"options"]];
134 132
 	NSMutableArray* controllers = [NSMutableArray new];
135 133
 	for (NSDictionary* child in node.children) {
136 134
 		[controllers addObject:[self fromTree:child]];
@@ -143,7 +141,7 @@
143 141
 
144 142
 -(UIViewController<RNNRootViewProtocol> *)createTabs:(RNNLayoutNode*)node {
145 143
 	RNNTabBarController* vc = [[RNNTabBarController alloc] initWithEventEmitter:_eventEmitter];
146
-	NSDictionary* options = node.data[@"options"];
144
+	RNNNavigationOptions* options = [self createOptions:node.data[@"options"]];
147 145
 
148 146
 	NSMutableArray* controllers = [NSMutableArray new];
149 147
 	for (NSDictionary *child in node.children) {
@@ -178,18 +176,18 @@
178 176
 - (UIViewController<RNNRootViewProtocol> *)createSideMenu:(RNNLayoutNode*)node {
179 177
 	NSMutableArray* childrenVCs = [NSMutableArray new];
180 178
 	
181
-	
182 179
 	for (NSDictionary *child in node.children) {
183 180
 		UIViewController *vc = [self fromTree:child];
184 181
 		[childrenVCs addObject:vc];
185 182
 	}
186 183
 	RNNSideMenuController *sideMenu = [[RNNSideMenuController alloc] initWithControllers:childrenVCs];
184
+	[sideMenu mergeOptions:[self createOptions:node.data[@"options"]]];
187 185
 	return sideMenu;
188 186
 }
189 187
 
190 188
 
191 189
 - (UIViewController<RNNRootViewProtocol> *)createSideMenuChild:(RNNLayoutNode*)node type:(RNNSideMenuChildType)type {
192
-	UIViewController* child = (UIViewController*)[self fromTree:node.children[0]];
190
+	UIViewController<RNNRootViewProtocol>* child = [self fromTree:node.children[0]];
193 191
 	RNNSideMenuChildVC *sideMenuChild = [[RNNSideMenuChildVC alloc] initWithChild: child type:type];
194 192
 	
195 193
 	return sideMenuChild;
@@ -234,4 +232,10 @@
234 232
 	return svc;
235 233
 }
236 234
 
235
+- (RNNNavigationOptions *)createOptions:(NSDictionary *)optionsDict {
236
+	RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:_defaultOptionsDict];
237
+	[options mergeWith:optionsDict];
238
+	return options;
239
+}
240
+
237 241
 @end

+ 1
- 1
lib/ios/RNNNavigationController.m Целия файл

@@ -20,7 +20,7 @@
20 20
 	return [self.getTopViewController isCustomViewController];
21 21
 }
22 22
 
23
-- (void)mergeOptions:(NSDictionary *)options {
23
+- (void)mergeOptions:(RNNOptions *)options {
24 24
 	[self.getTopViewController mergeOptions:options];
25 25
 }
26 26
 

+ 2
- 1
lib/ios/RNNOptions.h Целия файл

@@ -16,8 +16,9 @@
16 16
 
17 17
 - (instancetype)initWithDict:(NSDictionary*)dict;
18 18
 - (void)mergeWith:(NSDictionary*)otherOptions;
19
-- (void)mergeIfEmptyWith:(NSDictionary*)otherOptions;
20 19
 - (void)applyOn:(UIViewController *)viewController defaultOptions:(RNNOptions*)defaultOptions;
21 20
 - (BOOL)hasProperty:(NSString*)propName;
21
+- (void)mergeOptions:(RNNOptions *)otherOptions;
22
+- (void)mergeOptions:(RNNOptions *)otherOptions overrideOptions:(BOOL)override;
22 23
 
23 24
 @end

+ 25
- 9
lib/ios/RNNOptions.m Целия файл

@@ -30,19 +30,21 @@
30 30
 	}
31 31
 }
32 32
 
33
--(void)mergeIfEmptyWith:(NSDictionary *)otherOptions {
34
-	for (id key in otherOptions) {
35
-		if ([self hasProperty:key]) {
36
-			if ([[self valueForKey:key] isKindOfClass:[RNNOptions class]]) {
37
-				RNNOptions* options = [self valueForKey:key];
38
-				[options mergeIfEmptyWith:[otherOptions objectForKey:key]];
39
-			} else if (![self valueForKey:key]) {
40
-				[self setValue:[otherOptions objectForKey:key] forKey:key];
41
-			}
33
+- (void)mergeOptions:(RNNOptions *)otherOptions overrideOptions:(BOOL)override {
34
+	for (id prop in [self objectProperties:otherOptions]) {
35
+		id value = [otherOptions valueForKey:prop];
36
+		if ([value isKindOfClass:[RNNOptions class]]) {
37
+			[[self valueForKey:prop] mergeOptions:value overrideOptions:override];
38
+		} else if (value && (override || ![self valueForKey:prop])) {
39
+			[self setValue:value forKey:prop];
42 40
 		}
43 41
 	}
44 42
 }
45 43
 
44
+- (void)mergeOptions:(RNNOptions *)otherOptions {
45
+	[self mergeOptions:otherOptions overrideOptions:YES];
46
+}
47
+
46 48
 - (BOOL)hasProperty:(NSString*)propName {
47 49
 	return [self respondsToSelector:NSSelectorFromString(propName)];
48 50
 }
@@ -71,4 +73,18 @@
71 73
 	free(props);
72 74
 }
73 75
 
76
+- (NSArray *)objectProperties:(NSObject *)object {
77
+	NSMutableArray* properties = [NSMutableArray new];
78
+	unsigned int count;
79
+	objc_property_t* props = class_copyPropertyList([object class], &count);
80
+	for (int i = 0; i < count; i++) {
81
+		objc_property_t property = props[i];
82
+		NSString *propertyName = [NSString stringWithCString:property_getName(property) encoding:NSUTF8StringEncoding];
83
+		[properties addObject:propertyName];
84
+	}
85
+	
86
+	free(props);
87
+	return properties;
88
+}
89
+
74 90
 @end

+ 2
- 2
lib/ios/RNNRootViewController.m Целия файл

@@ -124,8 +124,8 @@
124 124
 	[self.options applyModalOptions:self];
125 125
 }
126 126
 
127
-- (void)mergeOptions:(NSDictionary *)options {
128
-	[self.options mergeIfEmptyWith:options];
127
+- (void)mergeOptions:(RNNOptions *)options {
128
+	[self.options mergeOptions:options overrideOptions:NO];
129 129
 }
130 130
 
131 131
 - (void)setCustomNavigationTitleView {

+ 1
- 1
lib/ios/RNNRootViewProtocol.h Целия файл

@@ -3,7 +3,7 @@
3 3
 @protocol RNNRootViewProtocol <NSObject, UINavigationControllerDelegate, UIViewControllerTransitioningDelegate, UISplitViewControllerDelegate>
4 4
 
5 5
 @optional
6
-- (void)mergeOptions:(NSDictionary*)options;
6
+- (void)mergeOptions:(RNNOptions*)options;
7 7
 - (BOOL)isCustomViewController;
8 8
 - (void)performOnRotation:(void (^)(void))block;
9 9
 - (void)optionsUpdated;

+ 2
- 2
lib/ios/RNNSideMenuChildVC.h Целия файл

@@ -19,8 +19,8 @@ typedef NS_ENUM(NSInteger, RNNSideMenuChildType) {
19 19
 @interface RNNSideMenuChildVC : UIViewController <RNNRootViewProtocol>
20 20
 
21 21
 @property (readonly) RNNSideMenuChildType type;
22
-@property (readonly) UIViewController *child;
22
+@property (readonly) UIViewController<RNNRootViewProtocol> *child;
23 23
 
24
--(instancetype) initWithChild:(UIViewController*)child type:(RNNSideMenuChildType)type;
24
+-(instancetype) initWithChild:(UIViewController<RNNRootViewProtocol>*)child type:(RNNSideMenuChildType)type;
25 25
 
26 26
 @end

+ 4
- 0
lib/ios/RNNSideMenuChildVC.m Целия файл

@@ -31,6 +31,10 @@
31 31
 	return self;
32 32
 }
33 33
 
34
+- (void)mergeOptions:(RNNOptions *)options {
35
+	[self.child mergeOptions:options];
36
+}
37
+
34 38
 - (UIStatusBarStyle)preferredStatusBarStyle {
35 39
 	return self.child.preferredStatusBarStyle;
36 40
 }

+ 4
- 0
lib/ios/RNNSideMenuController.m Целия файл

@@ -89,6 +89,10 @@
89 89
 	}
90 90
 }
91 91
 
92
+- (void)mergeOptions:(RNNOptions *)options {
93
+	[self.center mergeOptions:options];
94
+}
95
+
92 96
 - (NSString *)componentId {
93 97
 	return _center.componentId;
94 98
 }

+ 3
- 4
lib/ios/RNNSideMenuOptions.h Целия файл

@@ -1,10 +1,9 @@
1 1
 #import "RNNOptions.h"
2
+#import "RNNSideMenuSideOptions.h"
2 3
 
3 4
 @interface RNNSideMenuOptions : RNNOptions
4 5
 
5
-@property (nonatomic, strong) NSNumber* leftSideVisible;
6
-@property (nonatomic, strong) NSNumber* rightSideVisible;
7
-@property (nonatomic, strong) NSNumber* rightSideEnabled;
8
-@property (nonatomic, strong) NSNumber* leftSideEnabled;
6
+@property (nonatomic, strong) RNNSideMenuSideOptions* left;
7
+@property (nonatomic, strong) RNNSideMenuSideOptions* right;
9 8
 
10 9
 @end

+ 2
- 42
lib/ios/RNNSideMenuOptions.m Целия файл

@@ -4,48 +4,8 @@
4 4
 @implementation RNNSideMenuOptions
5 5
 
6 6
 - (void)applyOn:(UIViewController *)viewController {
7
-	RNNSideMenuController* sideMenuController = (RNNSideMenuController*)UIApplication.sharedApplication.delegate.window.rootViewController;
8
-	if ([sideMenuController isKindOfClass:[RNNSideMenuController class]]) {
9
-		if (self.leftSideVisible) {
10
-			if (self.leftSideVisible.boolValue) {
11
-				[sideMenuController showSideMenu:MMDrawerSideLeft animated:YES];
12
-			} else {
13
-				[sideMenuController hideSideMenu:MMDrawerSideLeft animated:YES];
14
-			}
15
-		}
16
-		
17
-		if (self.rightSideVisible) {
18
-			if (self.rightSideVisible.boolValue) {
19
-				[sideMenuController showSideMenu:MMDrawerSideRight animated:YES];
20
-			} else {
21
-				[sideMenuController hideSideMenu:MMDrawerSideRight animated:YES];
22
-			}
23
-		}
24
-		
25
-		if (self.leftSideEnabled) {
26
-			sideMenuController.sideMenu.leftSideEnabled = [self.leftSideEnabled boolValue];
27
-		}
28
-		
29
-		if (self.rightSideEnabled) {
30
-			sideMenuController.sideMenu.rightSideEnabled = [self.rightSideEnabled boolValue];
31
-		}
32
-		
33
-		[self resetOptions];
34
-	}
35
-}
36
-
37
--(void)mergeWith:(NSDictionary *)otherOptions {
38
-	self.leftSideVisible = [[otherOptions valueForKey:@"left"] valueForKey:@"visible"];
39
-	self.rightSideVisible = [[otherOptions valueForKey:@"right"] valueForKey:@"visible"];
40
-	self.leftSideEnabled = [[otherOptions valueForKey:@"left"] valueForKey:@"enabled"];
41
-	self.rightSideEnabled = [[otherOptions valueForKey:@"right"] valueForKey:@"enabled"];
42
-}
43
-
44
--(void)resetOptions {
45
-	self.leftSideVisible = nil;
46
-	self.rightSideVisible = nil;
47
-	self.leftSideEnabled = nil;
48
-	self.rightSideEnabled = nil;
7
+	[self.left applyOnSide:MMDrawerSideLeft viewController:viewController];
8
+	[self.right applyOnSide:MMDrawerSideRight viewController:viewController];
49 9
 }
50 10
 
51 11
 @end

+ 11
- 0
lib/ios/RNNSideMenuSideOptions.h Целия файл

@@ -0,0 +1,11 @@
1
+#import "RNNOptions.h"
2
+#import "MMDrawerController.h"
3
+
4
+@interface RNNSideMenuSideOptions : RNNOptions
5
+
6
+- (void)applyOnSide:(MMDrawerSide)side viewController:(UIViewController *)viewController;
7
+
8
+@property (nonatomic, strong) NSNumber* visible;
9
+@property (nonatomic, strong) NSNumber* enabled;
10
+
11
+@end

+ 36
- 0
lib/ios/RNNSideMenuSideOptions.m Целия файл

@@ -0,0 +1,36 @@
1
+#import "RNNSideMenuSideOptions.h"
2
+#import "RNNSideMenuController.h"
3
+
4
+@implementation RNNSideMenuSideOptions
5
+
6
+- (void)applyOnSide:(MMDrawerSide)side viewController:(UIViewController *)viewController {
7
+	RNNSideMenuController* sideMenuController = (RNNSideMenuController*)UIApplication.sharedApplication.delegate.window.rootViewController;
8
+	if (self.enabled) {
9
+		switch (side) {
10
+			case MMDrawerSideRight:
11
+				sideMenuController.sideMenu.rightSideEnabled = [self.enabled boolValue];
12
+				break;
13
+			case MMDrawerSideLeft:
14
+				sideMenuController.sideMenu.leftSideEnabled = [self.enabled boolValue];
15
+			default:
16
+				break;
17
+		}
18
+	}
19
+	
20
+	if (self.visible) {
21
+		if (self.visible.boolValue) {
22
+			[sideMenuController showSideMenu:side animated:YES];
23
+		} else {
24
+			[sideMenuController hideSideMenu:side animated:YES];
25
+		}
26
+	}
27
+	
28
+	[self resetOptions];
29
+}
30
+
31
+- (void)resetOptions {
32
+	self.visible = nil;
33
+	self.enabled = nil;
34
+}
35
+
36
+@end

+ 2
- 2
lib/ios/RNNSplitViewController.m Целия файл

@@ -33,8 +33,8 @@
33 33
 - (void)optionsUpdated {
34 34
 }
35 35
 
36
-- (void)mergeOptions:(NSDictionary *)options {
37
-	[self.options mergeIfEmptyWith:options];
36
+- (void)mergeOptions:(RNNOptions *)options {
37
+	[self.options mergeOptions:options];
38 38
 }
39 39
 
40 40
 @end

+ 1
- 1
lib/ios/RNNTabBarController.m Целия файл

@@ -41,7 +41,7 @@
41 41
 	}
42 42
 }
43 43
 
44
-- (void)mergeOptions:(NSDictionary *)options {
44
+- (void)mergeOptions:(RNNOptions *)options {
45 45
 	[((UIViewController<RNNRootViewProtocol>*)self.selectedViewController) mergeOptions:options];
46 46
 }
47 47
 

+ 8
- 0
lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj Целия файл

@@ -89,6 +89,8 @@
89 89
 		50570B272061473D006A1B5C /* RNNTitleOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 50570B252061473D006A1B5C /* RNNTitleOptions.m */; };
90 90
 		50570BEA2063E09B006A1B5C /* RNNTitleViewHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 50570BE82063E09B006A1B5C /* RNNTitleViewHelper.h */; };
91 91
 		50570BEB2063E09B006A1B5C /* RNNTitleViewHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 50570BE92063E09B006A1B5C /* RNNTitleViewHelper.m */; };
92
+		5064495D20DC62B90026709C /* RNNSideMenuSideOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 5064495B20DC62B90026709C /* RNNSideMenuSideOptions.h */; };
93
+		5064495E20DC62B90026709C /* RNNSideMenuSideOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 5064495C20DC62B90026709C /* RNNSideMenuSideOptions.m */; };
92 94
 		506A2B1420973DFD00F43A95 /* RNNErrorHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 506A2B1220973DFD00F43A95 /* RNNErrorHandler.h */; };
93 95
 		506A2B1520973DFD00F43A95 /* RNNErrorHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 506A2B1320973DFD00F43A95 /* RNNErrorHandler.m */; };
94 96
 		50762D08205E96C200E3D18A /* RNNModalAnimation.h in Headers */ = {isa = PBXBuildFile; fileRef = 50762D06205E96C200E3D18A /* RNNModalAnimation.h */; };
@@ -301,6 +303,8 @@
301 303
 		50570B252061473D006A1B5C /* RNNTitleOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNTitleOptions.m; sourceTree = "<group>"; };
302 304
 		50570BE82063E09B006A1B5C /* RNNTitleViewHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNTitleViewHelper.h; sourceTree = "<group>"; };
303 305
 		50570BE92063E09B006A1B5C /* RNNTitleViewHelper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNTitleViewHelper.m; sourceTree = "<group>"; };
306
+		5064495B20DC62B90026709C /* RNNSideMenuSideOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNSideMenuSideOptions.h; sourceTree = "<group>"; };
307
+		5064495C20DC62B90026709C /* RNNSideMenuSideOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNSideMenuSideOptions.m; sourceTree = "<group>"; };
304 308
 		506A2B1220973DFD00F43A95 /* RNNErrorHandler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNErrorHandler.h; sourceTree = "<group>"; };
305 309
 		506A2B1320973DFD00F43A95 /* RNNErrorHandler.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNErrorHandler.m; sourceTree = "<group>"; };
306 310
 		50762D06205E96C200E3D18A /* RNNModalAnimation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNModalAnimation.h; sourceTree = "<group>"; };
@@ -564,6 +568,8 @@
564 568
 				504AFE731FFFF0540076E904 /* RNNTopTabsOptions.m */,
565 569
 				50CB3B671FDE911400AA153B /* RNNSideMenuOptions.h */,
566 570
 				50CB3B681FDE911400AA153B /* RNNSideMenuOptions.m */,
571
+				5064495B20DC62B90026709C /* RNNSideMenuSideOptions.h */,
572
+				5064495C20DC62B90026709C /* RNNSideMenuSideOptions.m */,
567 573
 				50A00C35200F84D6000F01A6 /* RNNOverlayOptions.h */,
568 574
 				50A00C36200F84D6000F01A6 /* RNNOverlayOptions.m */,
569 575
 				507E7D55201DDD3000444E6C /* RNNAnimationOptions.h */,
@@ -802,6 +808,7 @@
802 808
 				50A00C37200F84D6000F01A6 /* RNNOverlayOptions.h in Headers */,
803 809
 				7B4928081E70415400555040 /* RNNCommandsHandler.h in Headers */,
804 810
 				263905AE1E4C6F440023D7D3 /* MMDrawerBarButtonItem.h in Headers */,
811
+				5064495D20DC62B90026709C /* RNNSideMenuSideOptions.h in Headers */,
805 812
 				50F5DFC11F407A8C001A00BC /* RNNTabBarController.h in Headers */,
806 813
 				50CB3B691FDE911400AA153B /* RNNSideMenuOptions.h in Headers */,
807 814
 				263905BD1E4C6F440023D7D3 /* RCCDrawerProtocol.h in Headers */,
@@ -1022,6 +1029,7 @@
1022 1029
 				50EB4ED82068EBE000D6ED34 /* RNNBackgroundOptions.m in Sources */,
1023 1030
 				507F43CA1FF4F9CC00D9425B /* RNNTopTabOptions.m in Sources */,
1024 1031
 				26916C991E4B9E7700D13680 /* RNNReactRootViewCreator.m in Sources */,
1032
+				5064495E20DC62B90026709C /* RNNSideMenuSideOptions.m in Sources */,
1025 1033
 				214545251F4DC125006E8DA1 /* RNNUIBarButtonItem.m in Sources */,
1026 1034
 				263905B81E4C6F440023D7D3 /* UIViewController+MMDrawerController.m in Sources */,
1027 1035
 				263905CD1E4C6F440023D7D3 /* SidebarWunderlistAnimation.m in Sources */,