瀏覽代碼

Model splitView after the other presenter options (#4647)

Seems like RNNSplitViewOptions wasn't updated to use the presenters, so
the options were going nowhere.
Daniel Salinas 5 年之前
父節點
當前提交
00d5e313f8

+ 2
- 1
lib/ios/RNNControllerFactory.m 查看文件

@@ -14,6 +14,7 @@
14 14
 #import "RNNNavigationControllerPresenter.h"
15 15
 #import "RNNTabBarPresenter.h"
16 16
 #import "RNNSideMenuPresenter.h"
17
+#import "RNNSplitViewControllerPresenter.h"
17 18
 
18 19
 @implementation RNNControllerFactory {
19 20
 	id<RNNRootViewCreator> _creator;
@@ -204,7 +205,7 @@
204 205
 - (UIViewController<RNNParentProtocol> *)createSplitView:(RNNLayoutNode*)node {
205 206
 	RNNLayoutInfo* layoutInfo = [[RNNLayoutInfo alloc] initWithNode:node];
206 207
 	RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:node.data[@"options"]];;
207
-	RNNViewControllerPresenter* presenter = [[RNNViewControllerPresenter alloc] init];
208
+	RNNSplitViewControllerPresenter* presenter = [[RNNSplitViewControllerPresenter alloc] init];
208 209
 
209 210
 	NSArray *childViewControllers = [self extractChildrenViewControllersFromNode:node];
210 211
 

+ 3
- 9
lib/ios/RNNSplitViewController.h 查看文件

@@ -1,19 +1,13 @@
1
-#import <Foundation/Foundation.h>
2 1
 #import <UIKit/UIKit.h>
3
-#import "RNNLayoutNode.h"
4
-#import "RNNRootViewCreator.h"
5
-#import "RNNEventEmitter.h"
6
-#import "RNNNavigationOptions.h"
7
-#import "RNNSplitViewOptions.h"
8
-#import "RNNAnimator.h"
9
-#import "RNNTopTabsViewController.h"
10 2
 #import "RNNParentProtocol.h"
3
+#import "RNNSplitViewControllerPresenter.h"
4
+#import "UISplitViewController+RNNOptions.h"
11 5
 
12 6
 @interface RNNSplitViewController : UISplitViewController <RNNParentProtocol>
13 7
 
14 8
 @property (nonatomic, strong) RNNNavigationOptions* options;
15 9
 @property (nonatomic, strong) RNNNavigationOptions* defaultOptions;
16 10
 @property (nonatomic, retain) RNNLayoutInfo* layoutInfo;
17
-@property (nonatomic, retain) RNNViewControllerPresenter* presenter;
11
+@property (nonatomic, retain) RNNSplitViewControllerPresenter* presenter;
18 12
 
19 13
 @end

+ 11
- 8
lib/ios/RNNSplitViewController.m 查看文件

@@ -2,20 +2,22 @@
2 2
 
3 3
 @implementation RNNSplitViewController
4 4
 
5
-- (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo childViewControllers:(NSArray *)childViewControllers options:(RNNNavigationOptions *)options defaultOptions:(RNNNavigationOptions *)defaultOptions presenter:(RNNViewControllerPresenter *)presenter {
5
+- (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo childViewControllers:(NSArray *)childViewControllers options:(RNNNavigationOptions *)options defaultOptions:(RNNNavigationOptions *)defaultOptions presenter:(RNNSplitViewControllerPresenter *)presenter {
6 6
 	self = [super init];
7
-	
8
-	self.presenter = presenter;
9
-	[self.presenter bindViewController:self];
10
-	
7
+
11 8
 	self.defaultOptions = defaultOptions;
12 9
 	self.options = options;
10
+
11
+	self.presenter = presenter;
12
+	[self.presenter bindViewController:self];
13
+	[self.presenter applyOptionsOnInit:self.options];
14
+
13 15
 	self.layoutInfo = layoutInfo;
14 16
 	
15 17
 	self.navigationController.delegate = self;
16 18
 	
17 19
 	[self bindChildViewControllers:childViewControllers];
18
-	
20
+
19 21
 	return self;
20 22
 }
21 23
 
@@ -27,7 +29,7 @@
27 29
 
28 30
 - (void)onChildWillAppear {
29 31
 	[_presenter applyOptions:self.resolveOptions];
30
-	[((UIViewController<RNNParentProtocol> *)self.parentViewController) onChildWillAppear];
32
+	[((UISplitViewController<RNNParentProtocol> *)self.parentViewController) onChildWillAppear];
31 33
 }
32 34
 
33 35
 - (RNNNavigationOptions *)resolveOptions {
@@ -36,7 +38,7 @@
36 38
 
37 39
 - (void)mergeOptions:(RNNNavigationOptions *)options {
38 40
 	[_presenter mergeOptions:options currentOptions:self.options defaultOptions:self.defaultOptions];
39
-	[((UIViewController<RNNLayoutProtocol> *)self.parentViewController) mergeOptions:options];
41
+	[((UISplitViewController<RNNLayoutProtocol> *)self.parentViewController) mergeOptions:options];
40 42
 }
41 43
 
42 44
 - (void)overrideOptions:(RNNNavigationOptions *)options {
@@ -61,4 +63,5 @@
61 63
 	return [[self getCurrentChild] getCurrentLeaf];
62 64
 }
63 65
 
66
+
64 67
 @end

+ 5
- 0
lib/ios/RNNSplitViewControllerPresenter.h 查看文件

@@ -0,0 +1,5 @@
1
+#import "RNNViewControllerPresenter.h"
2
+
3
+@interface RNNSplitViewControllerPresenter : RNNViewControllerPresenter
4
+
5
+@end

+ 52
- 0
lib/ios/RNNSplitViewControllerPresenter.m 查看文件

@@ -0,0 +1,52 @@
1
+#import "RNNSplitViewControllerPresenter.h"
2
+#import "UISplitViewController+RNNOptions.h"
3
+#import "RCTConvert+Modal.h"
4
+#import "RNNSplitViewController.h"
5
+
6
+@implementation RNNSplitViewControllerPresenter
7
+
8
+- (void)bindViewController:(UISplitViewController *)bindedViewController viewCreator:(id<RNNRootViewCreator>)creator {
9
+	self.bindedViewController = bindedViewController;
10
+}
11
+
12
+- (void)applyOptions:(RNNNavigationOptions *)options {
13
+	[super applyOptions:options];
14
+	
15
+	UISplitViewController* splitViewController = self.bindedViewController;
16
+	[splitViewController rnn_setDisplayMode:options.splitView.displayMode];
17
+	[splitViewController rnn_setPrimaryEdge:options.splitView.primaryEdge];
18
+	[splitViewController rnn_setMinWidth:options.splitView.minWidth];
19
+	[splitViewController rnn_setMaxWidth:options.splitView.maxWidth];
20
+}
21
+
22
+
23
+- (void)applyOptionsOnInit:(RNNNavigationOptions *)initialOptions {
24
+	[super applyOptionsOnInit:initialOptions];
25
+	
26
+	UISplitViewController* splitViewController = self.bindedViewController;
27
+	[splitViewController rnn_setDisplayMode:initialOptions.splitView.displayMode];
28
+	[splitViewController rnn_setPrimaryEdge:initialOptions.splitView.primaryEdge];
29
+	[splitViewController rnn_setMinWidth:initialOptions.splitView.minWidth];
30
+	[splitViewController rnn_setMaxWidth:initialOptions.splitView.maxWidth];
31
+}
32
+
33
+- (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavigationOptions *)currentOptions defaultOptions:(RNNNavigationOptions *)defaultOptions {
34
+	[super mergeOptions:newOptions currentOptions:currentOptions defaultOptions:defaultOptions];
35
+	
36
+	UISplitViewController* splitViewController = self.bindedViewController;
37
+
38
+	if (newOptions.splitView.displayMode) {
39
+		[splitViewController rnn_setDisplayMode:newOptions.splitView.displayMode];
40
+	}
41
+	if (newOptions.splitView.primaryEdge) {
42
+		[splitViewController rnn_setPrimaryEdge:newOptions.splitView.primaryEdge];
43
+	}
44
+	if (newOptions.splitView.minWidth) {
45
+		[splitViewController rnn_setMinWidth:newOptions.splitView.minWidth];
46
+	}
47
+	if (newOptions.splitView.maxWidth) {
48
+		[splitViewController rnn_setMaxWidth:newOptions.splitView.maxWidth];
49
+	}
50
+}
51
+
52
+@end

+ 2
- 2
lib/ios/RNNSplitViewOptions.h 查看文件

@@ -4,7 +4,7 @@
4 4
 
5 5
 @property (nonatomic, strong) NSString* displayMode;
6 6
 @property (nonatomic, strong) NSString* primaryEdge;
7
-@property (nonatomic, strong) NSNumber* minWidth;
8
-@property (nonatomic, strong) NSNumber* maxWidth;
7
+@property (nonatomic, strong) Number* minWidth;
8
+@property (nonatomic, strong) Number* maxWidth;
9 9
 
10 10
 @end

+ 2
- 36
lib/ios/RNNSplitViewOptions.m 查看文件

@@ -8,43 +8,9 @@
8 8
 	
9 9
 	self.displayMode = dict[@"displayMode"];
10 10
 	self.primaryEdge = dict[@"primaryEdge"];
11
-	NSNumberFormatter *f = [[NSNumberFormatter alloc] init];
12
-	f.numberStyle = NSNumberFormatterDecimalStyle;
13
-	self.minWidth = [f numberFromString:dict[@"minWidth"]];
14
-	self.maxWidth = [f numberFromString:dict[@"maxWidth"]];
15
-	
11
+	self.minWidth = [NumberParser parse:dict key:@"minWidth"];
12
+	self.maxWidth = [NumberParser parse:dict key:@"maxWidth"];
16 13
 	return self;	
17 14
 }
18 15
 
19
--(void)applyOn:(UIViewController<RNNParentProtocol> *)viewController {
20
-	
21
-	UISplitViewController *svc = (UISplitViewController*) viewController;
22
-
23
-	if (@available(iOS 11.0, *)) {
24
-		if ([self.primaryEdge isEqualToString:@"trailing"]) {
25
-			[svc setPrimaryEdge:UISplitViewControllerPrimaryEdgeTrailing];
26
-		} else {
27
-			[svc setPrimaryEdge:UISplitViewControllerPrimaryEdgeLeading];
28
-		}
29
-	}
30
-	
31
-	if ([self.displayMode isEqualToString:@"visible"]) {
32
-		[svc setPreferredDisplayMode:UISplitViewControllerDisplayModeAllVisible];
33
-	} else if ([self.displayMode isEqualToString:@"hidden"]) {
34
-		[svc setPreferredDisplayMode:UISplitViewControllerDisplayModePrimaryHidden];
35
-	} else if ([self.displayMode isEqualToString:@"overlay"]) {
36
-		[svc setPreferredDisplayMode:UISplitViewControllerDisplayModePrimaryOverlay];
37
-	} else {
38
-		[svc setPreferredDisplayMode:UISplitViewControllerDisplayModeAutomatic];
39
-	}
40
-
41
-	if (self.minWidth) {
42
-		[svc setMinimumPrimaryColumnWidth:[self.minWidth doubleValue]];
43
-	}
44
-
45
-	if (self.maxWidth) {
46
-		[svc setMaximumPrimaryColumnWidth:[self.maxWidth doubleValue]];
47
-	}
48
-}
49
-
50 16
 @end

+ 12
- 0
lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj 查看文件

@@ -235,6 +235,8 @@
235 235
 		50F5DFC21F407A8C001A00BC /* RNNTabBarController.m in Sources */ = {isa = PBXBuildFile; fileRef = 50F5DFC01F407A8C001A00BC /* RNNTabBarController.m */; };
236 236
 		50F5DFC51F407AA0001A00BC /* RNNNavigationController.h in Headers */ = {isa = PBXBuildFile; fileRef = 50F5DFC31F407AA0001A00BC /* RNNNavigationController.h */; };
237 237
 		50F5DFC61F407AA0001A00BC /* RNNNavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 50F5DFC41F407AA0001A00BC /* RNNNavigationController.m */; };
238
+		651E1F8A21FD624600DFEA19 /* UISplitViewController+RNNOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 651E1F8921FD624600DFEA19 /* UISplitViewController+RNNOptions.m */; };
239
+		651E1F8D21FD642100DFEA19 /* RNNSplitViewControllerPresenter.m in Sources */ = {isa = PBXBuildFile; fileRef = 651E1F8C21FD642100DFEA19 /* RNNSplitViewControllerPresenter.m */; };
238 240
 		7365071121E4B16F004E020F /* RCTConvert+UIBarButtonSystemItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 7365070F21E4B16F004E020F /* RCTConvert+UIBarButtonSystemItem.h */; };
239 241
 		7365071221E4B16F004E020F /* RCTConvert+UIBarButtonSystemItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 7365071021E4B16F004E020F /* RCTConvert+UIBarButtonSystemItem.m */; };
240 242
 		7B1126A01E2D263F00F9B03B /* RNNEventEmitter.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B11269F1E2D263F00F9B03B /* RNNEventEmitter.m */; };
@@ -560,6 +562,10 @@
560 562
 		50F5DFC01F407A8C001A00BC /* RNNTabBarController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNTabBarController.m; sourceTree = "<group>"; };
561 563
 		50F5DFC31F407AA0001A00BC /* RNNNavigationController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNNavigationController.h; sourceTree = "<group>"; };
562 564
 		50F5DFC41F407AA0001A00BC /* RNNNavigationController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNNavigationController.m; sourceTree = "<group>"; };
565
+		651E1F8821FD611600DFEA19 /* UISplitViewController+RNNOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UISplitViewController+RNNOptions.h"; sourceTree = "<group>"; };
566
+		651E1F8921FD624600DFEA19 /* UISplitViewController+RNNOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UISplitViewController+RNNOptions.m"; sourceTree = "<group>"; };
567
+		651E1F8B21FD63F400DFEA19 /* RNNSplitViewControllerPresenter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNSplitViewControllerPresenter.h; sourceTree = "<group>"; };
568
+		651E1F8C21FD642100DFEA19 /* RNNSplitViewControllerPresenter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNSplitViewControllerPresenter.m; sourceTree = "<group>"; };
563 569
 		7365070F21E4B16F004E020F /* RCTConvert+UIBarButtonSystemItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RCTConvert+UIBarButtonSystemItem.h"; sourceTree = "<group>"; };
564 570
 		7365071021E4B16F004E020F /* RCTConvert+UIBarButtonSystemItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTConvert+UIBarButtonSystemItem.m"; sourceTree = "<group>"; };
565 571
 		7B11269E1E2D263F00F9B03B /* RNNEventEmitter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNNEventEmitter.h; sourceTree = "<group>"; };
@@ -942,6 +948,8 @@
942 948
 				501224052173592D000F5F98 /* RNNTabBarPresenter.m */,
943 949
 				5012240821735959000F5F98 /* RNNSideMenuPresenter.h */,
944 950
 				5012240921735959000F5F98 /* RNNSideMenuPresenter.m */,
951
+				651E1F8B21FD63F400DFEA19 /* RNNSplitViewControllerPresenter.h */,
952
+				651E1F8C21FD642100DFEA19 /* RNNSplitViewControllerPresenter.m */,
945 953
 			);
946 954
 			name = Presenters;
947 955
 			sourceTree = "<group>";
@@ -1094,6 +1102,8 @@
1094 1102
 				5038A3B4216DF602009280BC /* UINavigationController+RNNOptions.m */,
1095 1103
 				5038A3B7216DFCFD009280BC /* UITabBarController+RNNOptions.h */,
1096 1104
 				5038A3B8216DFCFD009280BC /* UITabBarController+RNNOptions.m */,
1105
+				651E1F8821FD611600DFEA19 /* UISplitViewController+RNNOptions.h */,
1106
+				651E1F8921FD624600DFEA19 /* UISplitViewController+RNNOptions.m */,
1097 1107
 				7BD721F31E2D3AA100724059 /* Bridge */,
1098 1108
 				7B1E4C4B1E2D173700C3A525 /* Controllers */,
1099 1109
 				263905881E4C6F440023D7D3 /* RNNSideMenu */,
@@ -1445,6 +1455,7 @@
1445 1455
 				50570B272061473D006A1B5C /* RNNTitleOptions.m in Sources */,
1446 1456
 				263905BF1E4C6F440023D7D3 /* RCCTheSideBarManagerViewController.m in Sources */,
1447 1457
 				5012241F217366D4000F5F98 /* ColorParser.m in Sources */,
1458
+				651E1F8D21FD642100DFEA19 /* RNNSplitViewControllerPresenter.m in Sources */,
1448 1459
 				501E0218213E7EA3003365C5 /* RNNReactView.m in Sources */,
1449 1460
 				50BE951220B5A787004F5DF5 /* RNNStatusBarOptions.m in Sources */,
1450 1461
 				50495953216F62BD006D2B81 /* NullNumber.m in Sources */,
@@ -1473,6 +1484,7 @@
1473 1484
 				50395590217482FE00B0A663 /* NullIntNumber.m in Sources */,
1474 1485
 				E8A5CD631F49114F00E89D0D /* RNNElement.m in Sources */,
1475 1486
 				5038A3CB216E328A009280BC /* Param.m in Sources */,
1487
+				651E1F8A21FD624600DFEA19 /* UISplitViewController+RNNOptions.m in Sources */,
1476 1488
 				50395594217485B000B0A663 /* Double.m in Sources */,
1477 1489
 				504AFE751FFFF0540076E904 /* RNNTopTabsOptions.m in Sources */,
1478 1490
 				50175CD2207A2AA1004FE91B /* RNNComponentOptions.m in Sources */,

+ 1
- 0
lib/ios/ReactNativeNavigationTests/RNNControllerFactoryTest.m 查看文件

@@ -6,6 +6,7 @@
6 6
 #import "RNNSideMenuChildVC.h"
7 7
 #import "RNNNavigationController.h"
8 8
 #import "RNNTabBarController.h"
9
+#import "RNNTopTabsViewController.h"
9 10
 #import "RNNSplitViewController.h"
10 11
 
11 12
 @interface RNNControllerFactoryTest : XCTestCase

+ 14
- 0
lib/ios/UISplitViewController+RNNOptions.h 查看文件

@@ -0,0 +1,14 @@
1
+#import <UIKit/UIKit.h>
2
+#import "Number.h"
3
+
4
+@interface UISplitViewController (RNNOptions)
5
+
6
+- (void)rnn_setDisplayMode:(NSString *)displayMode;
7
+
8
+- (void)rnn_setPrimaryEdge:(NSString *)primaryEdge;
9
+
10
+- (void)rnn_setMinWidth:(Number *)minWidth;
11
+
12
+- (void)rnn_setMaxWidth:(Number *)maxWidth;
13
+
14
+@end

+ 41
- 0
lib/ios/UISplitViewController+RNNOptions.m 查看文件

@@ -0,0 +1,41 @@
1
+#import "UISplitViewController+RNNOptions.h"
2
+#import "RNNSplitViewController.h"
3
+
4
+@implementation UISplitViewController (RNNOptions)
5
+
6
+- (void)rnn_setDisplayMode:(NSString *)displayMode {
7
+	if ([displayMode isEqualToString:@"visible"]) {
8
+		self.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible;
9
+	} else if ([displayMode isEqualToString:@"hidden"]) {
10
+		self.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryHidden;
11
+	} else if ([displayMode isEqualToString:@"overlay"]) {
12
+		self.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryOverlay;
13
+	} else {
14
+		self.preferredDisplayMode = UISplitViewControllerDisplayModeAutomatic;
15
+	}
16
+}
17
+
18
+- (void)rnn_setPrimaryEdge:(NSString *)primaryEdge {
19
+	if (@available(iOS 11.0, *)) {
20
+		if ([primaryEdge isEqualToString:@"trailing"]) {
21
+			self.primaryEdge = UISplitViewControllerPrimaryEdgeTrailing;
22
+		} else {
23
+			self.primaryEdge = UISplitViewControllerPrimaryEdgeLeading;
24
+		}
25
+	}
26
+}
27
+
28
+- (void)rnn_setMinWidth:(Number *)minWidth {
29
+	if (minWidth.hasValue) {
30
+		[self setMinimumPrimaryColumnWidth:[[minWidth get] doubleValue]];
31
+	}
32
+}
33
+
34
+- (void)rnn_setMaxWidth:(Number *)maxWidth {
35
+	if (maxWidth.hasValue) {
36
+		[self setMaximumPrimaryColumnWidth:[[maxWidth get] doubleValue]];
37
+	}
38
+}
39
+
40
+@end
41
+