|
@@ -1,22 +1,28 @@
|
1
|
1
|
|
2
|
2
|
#import "RNNCommandsHandler.h"
|
3
|
3
|
|
4
|
|
-
|
5
|
|
-#import "RNN.h"
|
6
|
|
-#import "RNNControllerFactory.h"
|
7
|
|
-#import "RNNReactRootViewCreator.h"
|
8
|
|
-#import "RNNStore.h"
|
9
|
4
|
#import "RNNModalManager.h"
|
10
|
5
|
#import "RNNNavigationStackManager.h"
|
11
|
6
|
|
|
7
|
+@interface RNNCommandsHandler ()
|
|
8
|
+@property RNNControllerFactory *controllerFactory;
|
|
9
|
+@property RNNStore *store;
|
|
10
|
+@end
|
|
11
|
+
|
12
|
12
|
@implementation RNNCommandsHandler
|
13
|
13
|
|
|
14
|
+-(instancetype) initWithStore:(RNNStore*)store controllerFactory:(RNNControllerFactory*)controllerFactory {
|
|
15
|
+ self = [super init];
|
|
16
|
+ self.store = store;
|
|
17
|
+ self.controllerFactory = controllerFactory;
|
|
18
|
+ return self;
|
|
19
|
+}
|
|
20
|
+
|
14
|
21
|
#pragma mark - public
|
15
|
22
|
|
16
|
23
|
-(void) setRoot:(NSDictionary*)layout {
|
17
|
24
|
[self assertReady];
|
18
|
|
- RNNControllerFactory *factory = [[RNNControllerFactory alloc] initWithRootViewCreator:[RNNReactRootViewCreator new] store:[RNN instance].store];
|
19
|
|
- UIViewController *vc = [factory createLayoutAndSaveToStore:layout];
|
|
25
|
+ UIViewController *vc = [self.controllerFactory createLayoutAndSaveToStore:layout];
|
20
|
26
|
|
21
|
27
|
UIApplication.sharedApplication.delegate.window.rootViewController = vc;
|
22
|
28
|
[UIApplication.sharedApplication.delegate.window makeKeyAndVisible];
|
|
@@ -24,41 +30,48 @@
|
24
|
30
|
|
25
|
31
|
-(void) push:(NSString*)containerId layout:(NSDictionary*)layout {
|
26
|
32
|
[self assertReady];
|
27
|
|
- RNNControllerFactory *factory = [[RNNControllerFactory alloc] initWithRootViewCreator:[RNNReactRootViewCreator new] store:[RNN instance].store];
|
28
|
|
- UIViewController *newVc = [factory createLayoutAndSaveToStore:layout];
|
29
|
|
- UIViewController *vc = [[RNN instance].store findContainerForId:containerId];
|
30
|
33
|
|
31
|
|
- [[[RNNNavigationStackManager alloc] initWithStore:[RNN instance].store] push:newVc onTop:vc animated:YES];
|
|
34
|
+ UIViewController *newVc = [self.controllerFactory createLayoutAndSaveToStore:layout];
|
|
35
|
+
|
|
36
|
+ // find on who to push
|
|
37
|
+ UIViewController *vc = [self.store findContainerForId:containerId];
|
|
38
|
+
|
|
39
|
+ // do the actual pushing
|
|
40
|
+ [[[RNNNavigationStackManager alloc] initWithStore:self.store] push:newVc onTop:vc animated:YES];
|
32
|
41
|
}
|
33
|
42
|
|
34
|
43
|
-(void) pop:(NSString*)containerId {
|
35
|
44
|
[self assertReady];
|
36
|
|
- UIViewController *vc = [[RNN instance].store findContainerForId:containerId];
|
37
|
|
- [[[RNNNavigationStackManager alloc] initWithStore:[RNN instance].store] pop:vc animated:YES];
|
38
|
|
- [[RNN instance].store removeContainer:containerId];
|
|
45
|
+
|
|
46
|
+ // find who to pop
|
|
47
|
+ UIViewController *vc = [self.store findContainerForId:containerId];
|
|
48
|
+
|
|
49
|
+ // do the popping
|
|
50
|
+ [[[RNNNavigationStackManager alloc] initWithStore:self.store] pop:vc animated:YES];
|
|
51
|
+ [self.store removeContainer:containerId];
|
39
|
52
|
}
|
40
|
53
|
|
41
|
54
|
-(void) showModal:(NSDictionary*)layout {
|
42
|
55
|
[self assertReady];
|
43
|
|
- RNNControllerFactory *factory = [[RNNControllerFactory alloc] initWithRootViewCreator:[RNNReactRootViewCreator new] store:[RNN instance].store];
|
44
|
|
- UIViewController *newVc = [factory createLayoutAndSaveToStore:layout];
|
45
|
|
- [[[RNNModalManager alloc] initWithStore:[RNN instance].store] showModal:newVc];
|
|
56
|
+
|
|
57
|
+ UIViewController *newVc = [self.controllerFactory createLayoutAndSaveToStore:layout];
|
|
58
|
+ [[[RNNModalManager alloc] initWithStore:self.store] showModal:newVc];
|
46
|
59
|
}
|
47
|
60
|
|
48
|
61
|
-(void) dismissModal:(NSString*)containerId {
|
49
|
62
|
[self assertReady];
|
50
|
|
- [[[RNNModalManager alloc] initWithStore:[RNN instance].store] dismissModal:containerId];
|
|
63
|
+ [[[RNNModalManager alloc] initWithStore:self.store] dismissModal:containerId];
|
51
|
64
|
}
|
52
|
65
|
|
53
|
66
|
-(void) dismissAllModals {
|
54
|
67
|
[self assertReady];
|
55
|
|
- [[[RNNModalManager alloc] initWithStore:[RNN instance].store] dismissAllModals];
|
|
68
|
+ [[[RNNModalManager alloc] initWithStore:self.store] dismissAllModals];
|
56
|
69
|
}
|
57
|
70
|
|
58
|
71
|
#pragma mark - private
|
59
|
72
|
|
60
|
|
-- (void)assertReady {
|
61
|
|
- if (![RNN instance].isReadyToReceiveCommands) {
|
|
73
|
+-(void) assertReady {
|
|
74
|
+ if (!self.store.isReadyToReceiveCommands) {
|
62
|
75
|
@throw [NSException exceptionWithName:@"BridgeNotLoadedError" reason:@"Bridge not yet loaded! Send commands after Navigation.events().onAppLaunched() has been called." userInfo:nil];
|
63
|
76
|
}
|
64
|
77
|
}
|