Browse Source

Fix appLaunched and button press events on iOS

yogevbd 6 years ago
parent
commit
3d22e69d6a
3 changed files with 22 additions and 23 deletions
  1. 13
    13
      lib/ios/RNNCommandsHandler.m
  2. 1
    1
      lib/ios/RNNEventEmitter.h
  3. 8
    9
      lib/ios/RNNEventEmitter.m

+ 13
- 13
lib/ios/RNNCommandsHandler.m View File

46
 	[self assertReady];
46
 	[self assertReady];
47
 	
47
 	
48
 	[_modalManager dismissAllModals];
48
 	[_modalManager dismissAllModals];
49
-	[_eventEmitter sendOnNavigationComment:setRoot params:@{@"layout": layout}];
49
+	[_eventEmitter sendOnNavigationCommand:setRoot params:@{@"layout": layout}];
50
 
50
 
51
 	UIViewController *vc = [_controllerFactory createLayoutAndSaveToStore:layout];
51
 	UIViewController *vc = [_controllerFactory createLayoutAndSaveToStore:layout];
52
 	
52
 	
57
 
57
 
58
 -(void) mergeOptions:(NSString*)componentId options:(NSDictionary*)options completion:(RNNTransitionCompletionBlock)completion {
58
 -(void) mergeOptions:(NSString*)componentId options:(NSDictionary*)options completion:(RNNTransitionCompletionBlock)completion {
59
 	[self assertReady];
59
 	[self assertReady];
60
-	[_eventEmitter sendOnNavigationComment:mergeOptions params:@{@"componentId": componentId, @"options": options}];
60
+	[_eventEmitter sendOnNavigationCommand:mergeOptions params:@{@"componentId": componentId, @"options": options}];
61
 
61
 
62
 	UIViewController* vc = [_store findComponentForId:componentId];
62
 	UIViewController* vc = [_store findComponentForId:componentId];
63
 	if([vc isKindOfClass:[RNNRootViewController class]]) {
63
 	if([vc isKindOfClass:[RNNRootViewController class]]) {
74
 
74
 
75
 -(void) setDefaultOptions:(NSDictionary*)optionsDict completion:(RNNTransitionCompletionBlock)completion {
75
 -(void) setDefaultOptions:(NSDictionary*)optionsDict completion:(RNNTransitionCompletionBlock)completion {
76
 	[self assertReady];
76
 	[self assertReady];
77
-	[_eventEmitter sendOnNavigationComment:setDefaultOptions params:@{@"options": optionsDict}];
77
+	[_eventEmitter sendOnNavigationCommand:setDefaultOptions params:@{@"options": optionsDict}];
78
 	[_controllerFactory setDefaultOptionsDict:optionsDict];
78
 	[_controllerFactory setDefaultOptionsDict:optionsDict];
79
 }
79
 }
80
 
80
 
81
 -(void)push:(NSString*)componentId layout:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
81
 -(void)push:(NSString*)componentId layout:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
82
 	[self assertReady];
82
 	[self assertReady];
83
-	[_eventEmitter sendOnNavigationComment:push params:@{@"componentId": componentId}];
83
+	[_eventEmitter sendOnNavigationCommand:push params:@{@"componentId": componentId}];
84
 	UIViewController<RNNRootViewProtocol> *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
84
 	UIViewController<RNNRootViewProtocol> *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
85
 	[_navigationStackManager push:newVc onTop:componentId completion:^{
85
 	[_navigationStackManager push:newVc onTop:componentId completion:^{
86
 		completion();
86
 		completion();
89
 
89
 
90
 -(void)setStackRoot:(NSString*)componentId layout:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
90
 -(void)setStackRoot:(NSString*)componentId layout:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
91
 	[self assertReady];
91
 	[self assertReady];
92
-	[_eventEmitter sendOnNavigationComment:setStackRoot params:@{@"componentId": componentId}];
92
+	[_eventEmitter sendOnNavigationCommand:setStackRoot params:@{@"componentId": componentId}];
93
 
93
 
94
 	UIViewController<RNNRootViewProtocol> *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
94
 	UIViewController<RNNRootViewProtocol> *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
95
 	[_navigationStackManager setStackRoot:newVc fromComponent:componentId completion:^{
95
 	[_navigationStackManager setStackRoot:newVc fromComponent:componentId completion:^{
99
 
99
 
100
 -(void)pop:(NSString*)componentId options:(NSDictionary*)options completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
100
 -(void)pop:(NSString*)componentId options:(NSDictionary*)options completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
101
 	[self assertReady];
101
 	[self assertReady];
102
-	[_eventEmitter sendOnNavigationComment:pop params:@{@"componentId": componentId}];
102
+	[_eventEmitter sendOnNavigationCommand:pop params:@{@"componentId": componentId}];
103
 	[CATransaction begin];
103
 	[CATransaction begin];
104
 	[CATransaction setCompletionBlock:^{
104
 	[CATransaction setCompletionBlock:^{
105
 		completion();
105
 		completion();
118
 
118
 
119
 -(void) popTo:(NSString*)componentId completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
119
 -(void) popTo:(NSString*)componentId completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
120
 	[self assertReady];
120
 	[self assertReady];
121
-	[_eventEmitter sendOnNavigationComment:popTo params:@{@"componentId": componentId}];
121
+	[_eventEmitter sendOnNavigationCommand:popTo params:@{@"componentId": componentId}];
122
 	[CATransaction begin];
122
 	[CATransaction begin];
123
 	[CATransaction setCompletionBlock:^{
123
 	[CATransaction setCompletionBlock:^{
124
 		completion();
124
 		completion();
131
 
131
 
132
 -(void) popToRoot:(NSString*)componentId completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
132
 -(void) popToRoot:(NSString*)componentId completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
133
 	[self assertReady];
133
 	[self assertReady];
134
-	[_eventEmitter sendOnNavigationComment:popToRoot params:@{@"componentId": componentId}];
134
+	[_eventEmitter sendOnNavigationCommand:popToRoot params:@{@"componentId": componentId}];
135
 	[CATransaction begin];
135
 	[CATransaction begin];
136
 	[CATransaction setCompletionBlock:^{
136
 	[CATransaction setCompletionBlock:^{
137
 		completion();
137
 		completion();
144
 
144
 
145
 -(void) showModal:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion {
145
 -(void) showModal:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion {
146
 	[self assertReady];
146
 	[self assertReady];
147
-	[_eventEmitter sendOnNavigationComment:showModal params:@{@"layout": layout}];
147
+	[_eventEmitter sendOnNavigationCommand:showModal params:@{@"layout": layout}];
148
 	UIViewController<RNNRootViewProtocol> *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
148
 	UIViewController<RNNRootViewProtocol> *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
149
 	[_modalManager showModal:newVc completion:^{
149
 	[_modalManager showModal:newVc completion:^{
150
 		completion();
150
 		completion();
153
 
153
 
154
 -(void) dismissModal:(NSString*)componentId completion:(RNNTransitionCompletionBlock)completion {
154
 -(void) dismissModal:(NSString*)componentId completion:(RNNTransitionCompletionBlock)completion {
155
 	[self assertReady];
155
 	[self assertReady];
156
-	[_eventEmitter sendOnNavigationComment:dismissModal params:@{@"componentId": componentId}];
156
+	[_eventEmitter sendOnNavigationCommand:dismissModal params:@{@"componentId": componentId}];
157
 	[CATransaction begin];
157
 	[CATransaction begin];
158
 	[CATransaction setCompletionBlock:^{
158
 	[CATransaction setCompletionBlock:^{
159
 		completion();
159
 		completion();
166
 
166
 
167
 -(void) dismissAllModalsWithCompletion:(RNNTransitionCompletionBlock)completion {
167
 -(void) dismissAllModalsWithCompletion:(RNNTransitionCompletionBlock)completion {
168
 	[self assertReady];
168
 	[self assertReady];
169
-	[_eventEmitter sendOnNavigationComment:dismissAllModals params:@{}];
169
+	[_eventEmitter sendOnNavigationCommand:dismissAllModals params:@{}];
170
 	[CATransaction begin];
170
 	[CATransaction begin];
171
 	[CATransaction setCompletionBlock:^{
171
 	[CATransaction setCompletionBlock:^{
172
 		completion();
172
 		completion();
179
 
179
 
180
 -(void)showOverlay:(NSDictionary *)layout completion:(RNNTransitionCompletionBlock)completion {
180
 -(void)showOverlay:(NSDictionary *)layout completion:(RNNTransitionCompletionBlock)completion {
181
 	[self assertReady];
181
 	[self assertReady];
182
-	[_eventEmitter sendOnNavigationComment:showOverlay params:@{@"layout": layout}];
182
+	[_eventEmitter sendOnNavigationCommand:showOverlay params:@{@"layout": layout}];
183
 	UIViewController<RNNRootViewProtocol>* overlayVC = [_controllerFactory createOverlay:layout];
183
 	UIViewController<RNNRootViewProtocol>* overlayVC = [_controllerFactory createOverlay:layout];
184
 	[_overlayManager showOverlay:overlayVC completion:^{
184
 	[_overlayManager showOverlay:overlayVC completion:^{
185
 		completion();
185
 		completion();
188
 
188
 
189
 - (void)dismissOverlay:(NSString*)componentId completion:(RNNTransitionCompletionBlock)completion {
189
 - (void)dismissOverlay:(NSString*)componentId completion:(RNNTransitionCompletionBlock)completion {
190
 	[self assertReady];
190
 	[self assertReady];
191
-	[_eventEmitter sendOnNavigationComment:dismissModal params:@{@"componentId": componentId}];
191
+	[_eventEmitter sendOnNavigationCommand:dismissModal params:@{@"componentId": componentId}];
192
 	[_overlayManager dismissOverlay:componentId completion:^{	
192
 	[_overlayManager dismissOverlay:componentId completion:^{	
193
 		completion();
193
 		completion();
194
 	}];
194
 	}];

+ 1
- 1
lib/ios/RNNEventEmitter.h View File

16
 
16
 
17
 -(void)sendOnNavigationEvent:(NSString *)commandName params:(NSDictionary*)params;
17
 -(void)sendOnNavigationEvent:(NSString *)commandName params:(NSDictionary*)params;
18
 
18
 
19
--(void)sendOnNavigationComment:(NSString *)commandName params:(NSDictionary*)params;
19
+-(void)sendOnNavigationCommand:(NSString *)commandName params:(NSDictionary*)params;
20
 
20
 
21
 @end
21
 @end

+ 8
- 9
lib/ios/RNNEventEmitter.m View File

7
 
7
 
8
 RCT_EXPORT_MODULE();
8
 RCT_EXPORT_MODULE();
9
 
9
 
10
-static NSString* const onAppLaunched	= @"RNN.onAppLaunched";
10
+static NSString* const onAppLaunched	= @"RNN.appLaunched";
11
 static NSString* const componentDidAppear	= @"RNN.componentDidAppear";
11
 static NSString* const componentDidAppear	= @"RNN.componentDidAppear";
12
 static NSString* const componentDidDisappear	= @"RNN.componentDidDisappear";
12
 static NSString* const componentDidDisappear	= @"RNN.componentDidDisappear";
13
-static NSString* const onNavigationButtonPressed	= @"RNN.onNavigationButtonPressed";
14
-static NSString* const onNavigationCommand	= @"RNN.onNavigationCommand";
15
-static NSString* const onNavigationEvent	= @"RNN.onNavigationEvent";
13
+static NSString* const commandComplete	= @"RNN.commandCompleted";
14
+static NSString* const navigationEvent	= @"RNN.nativeEvent";
16
 
15
 
17
 -(NSArray<NSString *> *)supportedEvents {
16
 -(NSArray<NSString *> *)supportedEvents {
18
-	return @[onAppLaunched, componentDidAppear, componentDidDisappear, onNavigationButtonPressed, onNavigationCommand, onNavigationEvent];
17
+	return @[onAppLaunched, componentDidAppear, componentDidDisappear, commandComplete, navigationEvent];
19
 }
18
 }
20
 
19
 
21
 # pragma mark public
20
 # pragma mark public
37
 }
36
 }
38
 
37
 
39
 -(void)sendOnNavigationButtonPressed:(NSString *)componentId buttonId:(NSString*)buttonId {
38
 -(void)sendOnNavigationButtonPressed:(NSString *)componentId buttonId:(NSString*)buttonId {
40
-	[self send:onNavigationButtonPressed body:@{@"componentId":componentId , @"buttonId": buttonId}];
39
+	[self send:navigationEvent body:@{@"name": @"buttonPressed", @"params": @{@"componentId": componentId , @"buttonId": buttonId}}];
41
 }
40
 }
42
 
41
 
43
--(void)sendOnNavigationComment:(NSString *)commandName params:(NSDictionary*)params {
44
-	[self send:onNavigationButtonPressed body:@{@"commandName":commandName , @"params": params}];
42
+-(void)sendOnNavigationCommand:(NSString *)commandName params:(NSDictionary*)params {
43
+	[self send:navigationEvent body:@{@"commandName":commandName , @"params": params}];
45
 }
44
 }
46
 
45
 
47
 -(void)sendOnNavigationEvent:(NSString *)commandName params:(NSDictionary*)params {
46
 -(void)sendOnNavigationEvent:(NSString *)commandName params:(NSDictionary*)params {
48
-	[self send:onNavigationEvent body:@{@"commandName":commandName , @"params": params}];
47
+	[self send:navigationEvent body:@{@"commandName":commandName , @"params": params}];
49
 }
48
 }
50
 
49
 
51
 - (void)addListener:(NSString *)eventName {
50
 - (void)addListener:(NSString *)eventName {