Browse Source

commands handler refactor

Daniel Zlotin 7 years ago
parent
commit
c60eb2e6d2
3 changed files with 23 additions and 35 deletions
  1. 9
    18
      ios/RNNCommandsHandler.m
  2. 2
    2
      ios/RNNNavigationStackManager.h
  3. 12
    15
      ios/RNNNavigationStackManager.m

+ 9
- 18
ios/RNNCommandsHandler.m View File

7
 @implementation RNNCommandsHandler {
7
 @implementation RNNCommandsHandler {
8
 	RNNControllerFactory *_controllerFactory;
8
 	RNNControllerFactory *_controllerFactory;
9
 	RNNStore *_store;
9
 	RNNStore *_store;
10
+	RNNNavigationStackManager* _navigationStackManager;
11
+	RNNModalManager* _modalManager;
10
 }
12
 }
11
 
13
 
12
 -(instancetype) initWithStore:(RNNStore*)store controllerFactory:(RNNControllerFactory*)controllerFactory {
14
 -(instancetype) initWithStore:(RNNStore*)store controllerFactory:(RNNControllerFactory*)controllerFactory {
13
 	self = [super init];
15
 	self = [super init];
14
 	_store = store;
16
 	_store = store;
15
 	_controllerFactory = controllerFactory;
17
 	_controllerFactory = controllerFactory;
18
+	_navigationStackManager = [[RNNNavigationStackManager alloc] initWithStore:_store];
19
+	_modalManager = [[RNNModalManager alloc] initWithStore:_store];
16
 	return self;
20
 	return self;
17
 }
21
 }
18
 
22
 
28
 
32
 
29
 -(void) push:(NSString*)containerId layout:(NSDictionary*)layout {
33
 -(void) push:(NSString*)containerId layout:(NSDictionary*)layout {
30
 	[self assertReady];
34
 	[self assertReady];
31
-	
32
 	UIViewController *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
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
 -(void) pop:(NSString*)containerId {
39
 -(void) pop:(NSString*)containerId {
42
 	[self assertReady];
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
 -(void) showModal:(NSDictionary*)layout {
44
 -(void) showModal:(NSDictionary*)layout {
53
 	[self assertReady];
45
 	[self assertReady];
54
-	
55
 	UIViewController *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
46
 	UIViewController *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
56
-	[[[RNNModalManager alloc] initWithStore:_store] showModal:newVc];
47
+	[_modalManager showModal:newVc];
57
 }
48
 }
58
 
49
 
59
 -(void) dismissModal:(NSString*)containerId {
50
 -(void) dismissModal:(NSString*)containerId {
60
 	[self assertReady];
51
 	[self assertReady];
61
-	[[[RNNModalManager alloc] initWithStore:_store] dismissModal:containerId];
52
+	[_modalManager dismissModal:containerId];
62
 }
53
 }
63
 
54
 
64
 -(void) dismissAllModals {
55
 -(void) dismissAllModals {
65
 	[self assertReady];
56
 	[self assertReady];
66
-	[[[RNNModalManager alloc] initWithStore:_store] dismissAllModals];
57
+	[_modalManager dismissAllModals];
67
 }
58
 }
68
 
59
 
69
 #pragma mark - private
60
 #pragma mark - private

+ 2
- 2
ios/RNNNavigationStackManager.h View File

6
 
6
 
7
 -(instancetype)initWithStore:(RNNStore*)store;
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
 @end
12
 @end

+ 12
- 15
ios/RNNNavigationStackManager.m View File

4
 	RNNStore *_store;
4
 	RNNStore *_store;
5
 }
5
 }
6
 
6
 
7
-
8
 -(instancetype)initWithStore:(RNNStore*)store {
7
 -(instancetype)initWithStore:(RNNStore*)store {
9
 	self = [super init];
8
 	self = [super init];
10
 	_store = store;
9
 	_store = store;
11
 	return self;
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
 		[vcs removeObject:vc];
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
 @end
31
 @end