瀏覽代碼

commands handler refactor

Daniel Zlotin 7 年之前
父節點
當前提交
c60eb2e6d2
共有 3 個文件被更改,包括 23 次插入35 次删除
  1. 9
    18
      ios/RNNCommandsHandler.m
  2. 2
    2
      ios/RNNNavigationStackManager.h
  3. 12
    15
      ios/RNNNavigationStackManager.m

+ 9
- 18
ios/RNNCommandsHandler.m 查看文件

@@ -7,12 +7,16 @@
7 7
 @implementation RNNCommandsHandler {
8 8
 	RNNControllerFactory *_controllerFactory;
9 9
 	RNNStore *_store;
10
+	RNNNavigationStackManager* _navigationStackManager;
11
+	RNNModalManager* _modalManager;
10 12
 }
11 13
 
12 14
 -(instancetype) initWithStore:(RNNStore*)store controllerFactory:(RNNControllerFactory*)controllerFactory {
13 15
 	self = [super init];
14 16
 	_store = store;
15 17
 	_controllerFactory = controllerFactory;
18
+	_navigationStackManager = [[RNNNavigationStackManager alloc] initWithStore:_store];
19
+	_modalManager = [[RNNModalManager alloc] initWithStore:_store];
16 20
 	return self;
17 21
 }
18 22
 
@@ -28,42 +32,29 @@
28 32
 
29 33
 -(void) push:(NSString*)containerId layout:(NSDictionary*)layout {
30 34
 	[self assertReady];
31
-	
32 35
 	UIViewController *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
33
-	
34
-	// find on who to push
35
-	UIViewController *vc = [_store findContainerForId:containerId];
36
-	
37
-	// do the actual pushing
38
-	[[[RNNNavigationStackManager alloc] initWithStore:_store] push:newVc onTop:vc animated:YES];
36
+	[_navigationStackManager push:newVc onTop:containerId];
39 37
 }
40 38
 
41 39
 -(void) pop:(NSString*)containerId {
42 40
 	[self assertReady];
43
-	
44
-	// find who to pop
45
-	UIViewController *vc = [_store findContainerForId:containerId];
46
-	
47
-	// do the popping
48
-	[[[RNNNavigationStackManager alloc] initWithStore:_store] pop:vc animated:YES];
49
-	[_store removeContainer:containerId];
41
+	[_navigationStackManager pop:containerId];
50 42
 }
51 43
 
52 44
 -(void) showModal:(NSDictionary*)layout {
53 45
 	[self assertReady];
54
-	
55 46
 	UIViewController *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
56
-	[[[RNNModalManager alloc] initWithStore:_store] showModal:newVc];
47
+	[_modalManager showModal:newVc];
57 48
 }
58 49
 
59 50
 -(void) dismissModal:(NSString*)containerId {
60 51
 	[self assertReady];
61
-	[[[RNNModalManager alloc] initWithStore:_store] dismissModal:containerId];
52
+	[_modalManager dismissModal:containerId];
62 53
 }
63 54
 
64 55
 -(void) dismissAllModals {
65 56
 	[self assertReady];
66
-	[[[RNNModalManager alloc] initWithStore:_store] dismissAllModals];
57
+	[_modalManager dismissAllModals];
67 58
 }
68 59
 
69 60
 #pragma mark - private

+ 2
- 2
ios/RNNNavigationStackManager.h 查看文件

@@ -6,7 +6,7 @@
6 6
 
7 7
 -(instancetype)initWithStore:(RNNStore*)store;
8 8
 
9
--(void)push:(UIViewController*)newTop onTop:(UIViewController*)currentTop animated:(BOOL)animated;
10
--(void)pop:(UIViewController*)vc animated:(BOOL)animated;
9
+-(void)push:(UIViewController*)newTop onTop:(NSString*)containerId;
10
+-(void)pop:(NSString*)containerId;
11 11
 
12 12
 @end

+ 12
- 15
ios/RNNNavigationStackManager.m 查看文件

@@ -4,31 +4,28 @@
4 4
 	RNNStore *_store;
5 5
 }
6 6
 
7
-
8 7
 -(instancetype)initWithStore:(RNNStore*)store {
9 8
 	self = [super init];
10 9
 	_store = store;
11 10
 	return self;
12 11
 }
13 12
 
14
--(void)push:(UIViewController*)newTop onTop:(UIViewController*)currentTop animated:(BOOL)animated{
15
-	
16
-	[[currentTop navigationController] pushViewController:newTop animated:animated];
13
+-(void)push:(UIViewController *)newTop onTop:(NSString *)containerId {
14
+	UIViewController *vc = [_store findContainerForId:containerId];
15
+	[[vc navigationController] pushViewController:newTop animated:true];
17 16
 }
18 17
 
19
-
20
--(void)pop:(UIViewController*)vc animated:(BOOL)animated{
21
-	
22
-	if([[vc navigationController] topViewController] == vc ) {
23
-		[[vc navigationController] popViewControllerAnimated:animated];
24
-	}
25
-	else {
26
-		NSMutableArray * vcs = [vc navigationController].viewControllers.mutableCopy;
18
+-(void)pop:(NSString *)containerId {
19
+	UIViewController* vc = [_store findContainerForId:containerId];
20
+	UINavigationController* nvc = [vc navigationController];
21
+	if ([nvc topViewController] == vc) {
22
+		[nvc popViewControllerAnimated:true];
23
+	} else {
24
+		NSMutableArray * vcs = nvc.viewControllers.mutableCopy;
27 25
 		[vcs removeObject:vc];
28
-		[[vc navigationController] setViewControllers:vcs animated:animated];
26
+		[nvc setViewControllers:vcs animated:true];
29 27
 	}
28
+	[_store removeContainer:containerId];
30 29
 }
31 30
 
32
-
33
-
34 31
 @end