Procházet zdrojové kódy

Invoke all commands on the main thread (#5857)

* Invoke all commands on the main thread

* Fix tests

* Remove flaky test
Yogev Ben David před 5 roky
rodič
revize
8843224a9a
No account linked to committer's email address

+ 23
- 0
lib/ios/RNNAssert.h Zobrazit soubor

1
+#import <Foundation/Foundation.h>
2
+
3
+extern BOOL RNNIsMainQueue(void);
4
+
5
+#ifndef RNN_NSASSERT
6
+#define RNN_NSASSERT RCT_DEBUG
7
+#endif
8
+
9
+#ifndef NS_BLOCK_ASSERTIONS
10
+#define RNNAssert(condition, ...) do { \
11
+  if ((condition) == 0) { \
12
+    if (RNN_NSASSERT) { \
13
+      [[NSAssertionHandler currentHandler] handleFailureInFunction:(NSString * _Nonnull)@(__func__) \
14
+        file:(NSString * _Nonnull)@(__FILE__) lineNumber:__LINE__ description:__VA_ARGS__]; \
15
+    } \
16
+  } \
17
+} while (false)
18
+#else
19
+#define RNNAssert(condition, ...) do {} while (false)
20
+#endif
21
+
22
+#define RNNAssertMainQueue() RNNAssert(RNNIsMainQueue(), \
23
+@"This function must be called on the main queue")

+ 75
- 47
lib/ios/RNNBridgeModule.m Zobrazit soubor

2
 #import "Constants.h"
2
 #import "Constants.h"
3
 
3
 
4
 @implementation RNNBridgeModule {
4
 @implementation RNNBridgeModule {
5
-	RNNCommandsHandler* _commandsHandler;
5
+    RNNCommandsHandler* _commandsHandler;
6
 }
6
 }
7
 @synthesize bridge = _bridge;
7
 @synthesize bridge = _bridge;
8
 RCT_EXPORT_MODULE();
8
 RCT_EXPORT_MODULE();
9
 
9
 
10
 - (dispatch_queue_t)methodQueue {
10
 - (dispatch_queue_t)methodQueue {
11
-	return dispatch_get_main_queue();
11
+    return dispatch_get_main_queue();
12
 }
12
 }
13
 
13
 
14
 -(instancetype)initWithCommandsHandler:(RNNCommandsHandler *)commandsHandler {
14
 -(instancetype)initWithCommandsHandler:(RNNCommandsHandler *)commandsHandler {
15
-	self = [super init];
16
-	_commandsHandler = commandsHandler;
17
-	return self;
15
+    self = [super init];
16
+    _commandsHandler = commandsHandler;
17
+    return self;
18
 }
18
 }
19
 
19
 
20
 #pragma mark - JS interface
20
 #pragma mark - JS interface
21
 
21
 
22
 RCT_EXPORT_METHOD(setRoot:(NSString*)commandId layout:(NSDictionary*)layout resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
22
 RCT_EXPORT_METHOD(setRoot:(NSString*)commandId layout:(NSDictionary*)layout resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
23
-	[_commandsHandler setRoot:layout commandId:commandId completion:^{
24
-		resolve(layout);
25
-	}];
23
+    RCTExecuteOnMainQueue(^{
24
+        [_commandsHandler setRoot:layout commandId:commandId completion:^{
25
+            resolve(layout);
26
+        }];
27
+    });
26
 }
28
 }
27
 
29
 
28
 RCT_EXPORT_METHOD(mergeOptions:(NSString*)componentId options:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
30
 RCT_EXPORT_METHOD(mergeOptions:(NSString*)componentId options:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
29
-	[_commandsHandler mergeOptions:componentId options:options completion:^{
30
-		resolve(componentId);
31
-	}];
31
+    RCTExecuteOnMainQueue(^{
32
+        [_commandsHandler mergeOptions:componentId options:options completion:^{
33
+            resolve(componentId);
34
+        }];
35
+    });
32
 }
36
 }
33
 
37
 
34
 RCT_EXPORT_METHOD(setDefaultOptions:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
38
 RCT_EXPORT_METHOD(setDefaultOptions:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
35
-	[_commandsHandler setDefaultOptions:options completion:^{
36
-		resolve(nil);
37
-	}];
39
+    RCTExecuteOnMainQueue(^{
40
+        [_commandsHandler setDefaultOptions:options completion:^{
41
+            resolve(nil);
42
+        }];
43
+    });
38
 }
44
 }
39
 
45
 
40
 RCT_EXPORT_METHOD(push:(NSString*)commandId componentId:(NSString*)componentId layout:(NSDictionary*)layout resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
46
 RCT_EXPORT_METHOD(push:(NSString*)commandId componentId:(NSString*)componentId layout:(NSDictionary*)layout resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
41
-	[_commandsHandler push:componentId commandId:commandId layout:layout completion:^{
42
-		resolve(componentId);
43
-	} rejection:reject];
47
+    RCTExecuteOnMainQueue(^{
48
+        [_commandsHandler push:componentId commandId:commandId layout:layout completion:^{
49
+            resolve(componentId);
50
+        } rejection:reject];
51
+    });
44
 }
52
 }
45
 
53
 
46
 RCT_EXPORT_METHOD(pop:(NSString*)commandId componentId:(NSString*)componentId mergeOptions:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
54
 RCT_EXPORT_METHOD(pop:(NSString*)commandId componentId:(NSString*)componentId mergeOptions:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
47
-	[_commandsHandler pop:componentId commandId:commandId mergeOptions:(NSDictionary*)options completion:^{
48
-		resolve(componentId);
49
-	} rejection:reject];
55
+    RCTExecuteOnMainQueue(^{
56
+        [_commandsHandler pop:componentId commandId:commandId mergeOptions:(NSDictionary*)options completion:^{
57
+            resolve(componentId);
58
+        } rejection:reject];
59
+    });
50
 }
60
 }
51
 
61
 
52
 RCT_EXPORT_METHOD(setStackRoot:(NSString*)commandId componentId:(NSString*)componentId children:(NSArray*)children resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
62
 RCT_EXPORT_METHOD(setStackRoot:(NSString*)commandId componentId:(NSString*)componentId children:(NSArray*)children resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
53
-	[_commandsHandler setStackRoot:componentId commandId:commandId children:children completion:^{
54
-		resolve(componentId);
55
-	} rejection:reject];
63
+    RCTExecuteOnMainQueue(^{
64
+        [_commandsHandler setStackRoot:componentId commandId:commandId children:children completion:^{
65
+            resolve(componentId);
66
+        } rejection:reject];
67
+    });
56
 }
68
 }
57
 
69
 
58
 RCT_EXPORT_METHOD(popTo:(NSString*)commandId componentId:(NSString*)componentId mergeOptions:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
70
 RCT_EXPORT_METHOD(popTo:(NSString*)commandId componentId:(NSString*)componentId mergeOptions:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
59
-	[_commandsHandler popTo:componentId commandId:commandId mergeOptions:options completion:^{
60
-		resolve(componentId);
61
-	} rejection:reject];
71
+    RCTExecuteOnMainQueue(^{
72
+        [_commandsHandler popTo:componentId commandId:commandId mergeOptions:options completion:^{
73
+            resolve(componentId);
74
+        } rejection:reject];
75
+    });
62
 }
76
 }
63
 
77
 
64
 RCT_EXPORT_METHOD(popToRoot:(NSString*)commandId componentId:(NSString*)componentId mergeOptions:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
78
 RCT_EXPORT_METHOD(popToRoot:(NSString*)commandId componentId:(NSString*)componentId mergeOptions:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
65
-	[_commandsHandler popToRoot:componentId commandId:commandId mergeOptions:options completion:^{
66
-		resolve(componentId);
67
-	} rejection:reject];
79
+    RCTExecuteOnMainQueue(^{
80
+        [_commandsHandler popToRoot:componentId commandId:commandId mergeOptions:options completion:^{
81
+            resolve(componentId);
82
+        } rejection:reject];
83
+    });
68
 }
84
 }
69
 
85
 
70
 RCT_EXPORT_METHOD(showModal:(NSString*)commandId layout:(NSDictionary*)layout resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
86
 RCT_EXPORT_METHOD(showModal:(NSString*)commandId layout:(NSDictionary*)layout resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
71
-	[_commandsHandler showModal:layout commandId:commandId completion:^(NSString *componentId) {
72
-		resolve(componentId);
73
-	}];
87
+    RCTExecuteOnMainQueue(^{
88
+        [_commandsHandler showModal:layout commandId:commandId completion:^(NSString *componentId) {
89
+            resolve(componentId);
90
+        }];
91
+    });
74
 }
92
 }
75
 
93
 
76
 RCT_EXPORT_METHOD(dismissModal:(NSString*)commandId componentId:(NSString*)componentId mergeOptions:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
94
 RCT_EXPORT_METHOD(dismissModal:(NSString*)commandId componentId:(NSString*)componentId mergeOptions:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
77
-	[_commandsHandler dismissModal:componentId commandId:commandId mergeOptions:options completion:^{
78
-		resolve(componentId);
79
-	} rejection:reject];
95
+    RCTExecuteOnMainQueue(^{
96
+        [_commandsHandler dismissModal:componentId commandId:commandId mergeOptions:options completion:^{
97
+            resolve(componentId);
98
+        } rejection:reject];
99
+    });
80
 }
100
 }
81
 
101
 
82
 RCT_EXPORT_METHOD(dismissAllModals:(NSString*)commandId mergeOptions:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
102
 RCT_EXPORT_METHOD(dismissAllModals:(NSString*)commandId mergeOptions:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
83
-	[_commandsHandler dismissAllModals:options commandId:commandId completion:^{
84
-		resolve(nil);
85
-	}];
103
+    RCTExecuteOnMainQueue(^{
104
+        [_commandsHandler dismissAllModals:options commandId:commandId completion:^{
105
+            resolve(nil);
106
+        }];
107
+    });
86
 }
108
 }
87
 
109
 
88
 RCT_EXPORT_METHOD(showOverlay:(NSString*)commandId layout:(NSDictionary*)layout resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
110
 RCT_EXPORT_METHOD(showOverlay:(NSString*)commandId layout:(NSDictionary*)layout resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
89
-	[_commandsHandler showOverlay:layout commandId:commandId completion:^{
90
-		resolve(layout[@"id"]);
91
-	}];
111
+    RCTExecuteOnMainQueue(^{
112
+        [_commandsHandler showOverlay:layout commandId:commandId completion:^{
113
+            resolve(layout[@"id"]);
114
+        }];
115
+    });
92
 }
116
 }
93
 
117
 
94
 RCT_EXPORT_METHOD(dismissOverlay:(NSString*)commandId componentId:(NSString*)componentId resolve:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
118
 RCT_EXPORT_METHOD(dismissOverlay:(NSString*)commandId componentId:(NSString*)componentId resolve:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
95
-	[_commandsHandler dismissOverlay:componentId commandId:commandId completion:^{
96
-		resolve(@(1));
97
-	} rejection:reject];
119
+    RCTExecuteOnMainQueue(^{
120
+        [_commandsHandler dismissOverlay:componentId commandId:commandId completion:^{
121
+            resolve(@(1));
122
+        } rejection:reject];
123
+    });
98
 }
124
 }
99
 
125
 
100
 RCT_EXPORT_METHOD(getLaunchArgs:(NSString*)commandId :(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
126
 RCT_EXPORT_METHOD(getLaunchArgs:(NSString*)commandId :(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
101
-	NSArray* args = [[NSProcessInfo processInfo] arguments];
102
-	resolve(args);
127
+    NSArray* args = [[NSProcessInfo processInfo] arguments];
128
+    resolve(args);
103
 }
129
 }
104
 
130
 
105
 RCT_EXPORT_METHOD(getNavigationConstants:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
131
 RCT_EXPORT_METHOD(getNavigationConstants:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
106
-	resolve([Constants getConstants]);
132
+    RCTExecuteOnMainQueue(^{
133
+        resolve([Constants getConstants]);
134
+    });
107
 }
135
 }
108
 
136
 
109
 @end
137
 @end

+ 20
- 2
lib/ios/RNNCommandsHandler.m Zobrazit soubor

7
 #import "UIViewController+LayoutProtocol.h"
7
 #import "UIViewController+LayoutProtocol.h"
8
 #import "RNNLayoutManager.h"
8
 #import "RNNLayoutManager.h"
9
 #import "UIViewController+Utils.h"
9
 #import "UIViewController+Utils.h"
10
+#import "RNNAssert.h"
10
 
11
 
11
 static NSString* const setRoot	= @"setRoot";
12
 static NSString* const setRoot	= @"setRoot";
12
 static NSString* const setStackRoot	= @"setStackRoot";
13
 static NSString* const setStackRoot	= @"setStackRoot";
52
 
53
 
53
 - (void)setRoot:(NSDictionary*)layout commandId:(NSString*)commandId completion:(RNNTransitionCompletionBlock)completion {
54
 - (void)setRoot:(NSDictionary*)layout commandId:(NSString*)commandId completion:(RNNTransitionCompletionBlock)completion {
54
 	[self assertReady];
55
 	[self assertReady];
56
+    RNNAssertMainQueue();
55
 	
57
 	
56
 	if (@available(iOS 9, *)) {
58
 	if (@available(iOS 9, *)) {
57
 		if(_controllerFactory.defaultOptions.layout.direction.hasValue) {
59
 		if(_controllerFactory.defaultOptions.layout.direction.hasValue) {
85
 
87
 
86
 - (void)mergeOptions:(NSString*)componentId options:(NSDictionary*)mergeOptions completion:(RNNTransitionCompletionBlock)completion {
88
 - (void)mergeOptions:(NSString*)componentId options:(NSDictionary*)mergeOptions completion:(RNNTransitionCompletionBlock)completion {
87
 	[self assertReady];
89
 	[self assertReady];
90
+    RNNAssertMainQueue();
88
 	
91
 	
89
 	UIViewController<RNNLayoutProtocol>* vc = [RNNLayoutManager findComponentForId:componentId];
92
 	UIViewController<RNNLayoutProtocol>* vc = [RNNLayoutManager findComponentForId:componentId];
90
 	RNNNavigationOptions* newOptions = [[RNNNavigationOptions alloc] initWithDict:mergeOptions];
93
 	RNNNavigationOptions* newOptions = [[RNNNavigationOptions alloc] initWithDict:mergeOptions];
100
 
103
 
101
 - (void)setDefaultOptions:(NSDictionary*)optionsDict completion:(RNNTransitionCompletionBlock)completion {
104
 - (void)setDefaultOptions:(NSDictionary*)optionsDict completion:(RNNTransitionCompletionBlock)completion {
102
 	[self assertReady];
105
 	[self assertReady];
106
+    RNNAssertMainQueue();
107
+    
103
 	RNNNavigationOptions* defaultOptions = [[RNNNavigationOptions alloc] initWithDict:optionsDict];
108
 	RNNNavigationOptions* defaultOptions = [[RNNNavigationOptions alloc] initWithDict:optionsDict];
104
 	[_controllerFactory setDefaultOptions:defaultOptions];
109
 	[_controllerFactory setDefaultOptions:defaultOptions];
105
 	
110
 	
111
 
116
 
112
 - (void)push:(NSString*)componentId commandId:(NSString*)commandId layout:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
117
 - (void)push:(NSString*)componentId commandId:(NSString*)commandId layout:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
113
 	[self assertReady];
118
 	[self assertReady];
119
+    RNNAssertMainQueue();
114
 	
120
 	
115
 	UIViewController *newVc = [_controllerFactory createLayout:layout];
121
 	UIViewController *newVc = [_controllerFactory createLayout:layout];
116
 	UIViewController *fromVC = [RNNLayoutManager findComponentForId:componentId];
122
 	UIViewController *fromVC = [RNNLayoutManager findComponentForId:componentId];
172
 
178
 
173
 - (void)setStackRoot:(NSString*)componentId commandId:(NSString*)commandId children:(NSArray*)children completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
179
 - (void)setStackRoot:(NSString*)componentId commandId:(NSString*)commandId children:(NSArray*)children completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
174
 	[self assertReady];
180
 	[self assertReady];
181
+    RNNAssertMainQueue();
175
 	
182
 	
176
 	NSArray<UIViewController *> *childViewControllers = [_controllerFactory createChildrenLayout:children];
183
 	NSArray<UIViewController *> *childViewControllers = [_controllerFactory createChildrenLayout:children];
177
 	for (UIViewController<RNNLayoutProtocol>* viewController in childViewControllers) {
184
 	for (UIViewController<RNNLayoutProtocol>* viewController in childViewControllers) {
197
 
204
 
198
 - (void)pop:(NSString*)componentId commandId:(NSString*)commandId mergeOptions:(NSDictionary*)mergeOptions completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
205
 - (void)pop:(NSString*)componentId commandId:(NSString*)commandId mergeOptions:(NSDictionary*)mergeOptions completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
199
 	[self assertReady];
206
 	[self assertReady];
200
-	
207
+	RNNAssertMainQueue();
208
+    
201
 	RNNComponentViewController *vc = (RNNComponentViewController*)[RNNLayoutManager findComponentForId:componentId];
209
 	RNNComponentViewController *vc = (RNNComponentViewController*)[RNNLayoutManager findComponentForId:componentId];
202
 	RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initWithDict:mergeOptions];
210
 	RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initWithDict:mergeOptions];
203
 	[vc overrideOptions:options];
211
 	[vc overrideOptions:options];
222
 
230
 
223
 - (void)popTo:(NSString*)componentId commandId:(NSString*)commandId mergeOptions:(NSDictionary *)mergeOptions completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
231
 - (void)popTo:(NSString*)componentId commandId:(NSString*)commandId mergeOptions:(NSDictionary *)mergeOptions completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
224
 	[self assertReady];
232
 	[self assertReady];
233
+    RNNAssertMainQueue();
234
+    
225
 	RNNComponentViewController *vc = (RNNComponentViewController*)[RNNLayoutManager findComponentForId:componentId];
235
 	RNNComponentViewController *vc = (RNNComponentViewController*)[RNNLayoutManager findComponentForId:componentId];
226
 	RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initWithDict:mergeOptions];
236
 	RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initWithDict:mergeOptions];
227
 	[vc overrideOptions:options];
237
 	[vc overrideOptions:options];
234
 
244
 
235
 - (void)popToRoot:(NSString*)componentId commandId:(NSString*)commandId mergeOptions:(NSDictionary *)mergeOptions completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
245
 - (void)popToRoot:(NSString*)componentId commandId:(NSString*)commandId mergeOptions:(NSDictionary *)mergeOptions completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
236
 	[self assertReady];
246
 	[self assertReady];
247
+    RNNAssertMainQueue();
248
+    
237
 	RNNComponentViewController *vc = (RNNComponentViewController*)[RNNLayoutManager findComponentForId:componentId];
249
 	RNNComponentViewController *vc = (RNNComponentViewController*)[RNNLayoutManager findComponentForId:componentId];
238
 	RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initWithDict:mergeOptions];
250
 	RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initWithDict:mergeOptions];
239
 	[vc overrideOptions:options];
251
 	[vc overrideOptions:options];
255
 
267
 
256
 - (void)showModal:(NSDictionary*)layout commandId:(NSString *)commandId completion:(RNNTransitionWithComponentIdCompletionBlock)completion {
268
 - (void)showModal:(NSDictionary*)layout commandId:(NSString *)commandId completion:(RNNTransitionWithComponentIdCompletionBlock)completion {
257
 	[self assertReady];
269
 	[self assertReady];
270
+    RNNAssertMainQueue();
258
 	
271
 	
259
 	UIViewController *newVc = [_controllerFactory createLayout:layout];
272
 	UIViewController *newVc = [_controllerFactory createLayout:layout];
260
 	
273
 	
270
 
283
 
271
 - (void)dismissModal:(NSString*)componentId commandId:(NSString*)commandId mergeOptions:(NSDictionary *)mergeOptions completion:(RNNTransitionCompletionBlock)completion rejection:(RNNTransitionRejectionBlock)reject {
284
 - (void)dismissModal:(NSString*)componentId commandId:(NSString*)commandId mergeOptions:(NSDictionary *)mergeOptions completion:(RNNTransitionCompletionBlock)completion rejection:(RNNTransitionRejectionBlock)reject {
272
 	[self assertReady];
285
 	[self assertReady];
286
+    RNNAssertMainQueue();
273
 	
287
 	
274
 	UIViewController *modalToDismiss = (UIViewController *)[RNNLayoutManager findComponentForId:componentId];
288
 	UIViewController *modalToDismiss = (UIViewController *)[RNNLayoutManager findComponentForId:componentId];
275
 	
289
 	
293
 
307
 
294
 - (void)dismissAllModals:(NSDictionary *)mergeOptions commandId:(NSString*)commandId completion:(RNNTransitionCompletionBlock)completion {
308
 - (void)dismissAllModals:(NSDictionary *)mergeOptions commandId:(NSString*)commandId completion:(RNNTransitionCompletionBlock)completion {
295
 	[self assertReady];
309
 	[self assertReady];
310
+    RNNAssertMainQueue();
296
 	
311
 	
297
 	[CATransaction begin];
312
 	[CATransaction begin];
298
 	[CATransaction setCompletionBlock:^{
313
 	[CATransaction setCompletionBlock:^{
307
 
322
 
308
 - (void)showOverlay:(NSDictionary *)layout commandId:(NSString*)commandId completion:(RNNTransitionCompletionBlock)completion {
323
 - (void)showOverlay:(NSDictionary *)layout commandId:(NSString*)commandId completion:(RNNTransitionCompletionBlock)completion {
309
 	[self assertReady];
324
 	[self assertReady];
310
-	
325
+    RNNAssertMainQueue();
326
+    
311
 	UIViewController* overlayVC = [_controllerFactory createLayout:layout];
327
 	UIViewController* overlayVC = [_controllerFactory createLayout:layout];
312
     [overlayVC setReactViewReadyCallback:^{UIWindow* overlayWindow = [[RNNOverlayWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
328
     [overlayVC setReactViewReadyCallback:^{UIWindow* overlayWindow = [[RNNOverlayWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
313
         overlayWindow.rootViewController = overlayVC;
329
         overlayWindow.rootViewController = overlayVC;
327
 
343
 
328
 - (void)dismissOverlay:(NSString*)componentId commandId:(NSString*)commandId completion:(RNNTransitionCompletionBlock)completion rejection:(RNNTransitionRejectionBlock)reject {
344
 - (void)dismissOverlay:(NSString*)componentId commandId:(NSString*)commandId completion:(RNNTransitionCompletionBlock)completion rejection:(RNNTransitionRejectionBlock)reject {
329
 	[self assertReady];
345
 	[self assertReady];
346
+    RNNAssertMainQueue();
347
+    
330
 	UIViewController* viewController = [RNNLayoutManager findComponentForId:componentId];
348
 	UIViewController* viewController = [RNNLayoutManager findComponentForId:componentId];
331
 	if (viewController) {
349
 	if (viewController) {
332
 		[_overlayManager dismissOverlay:viewController];
350
 		[_overlayManager dismissOverlay:viewController];

+ 12
- 0
lib/ios/RNNUtils.m Zobrazit soubor

1
 #import "RNNUtils.h"
1
 #import "RNNUtils.h"
2
 
2
 
3
 @implementation RNNUtils
3
 @implementation RNNUtils
4
+
4
 +(double)getDoubleOrKey:(NSDictionary*)dict withKey:(NSString*)key withDefault:(double)defaultResult {
5
 +(double)getDoubleOrKey:(NSDictionary*)dict withKey:(NSString*)key withDefault:(double)defaultResult {
5
 	if ([dict objectForKey:key]) {
6
 	if ([dict objectForKey:key]) {
6
 		return [dict[key] doubleValue];
7
 		return [dict[key] doubleValue];
29
 	return [NSNumber numberWithLong:[[NSDate date] timeIntervalSince1970] * 1000];
30
 	return [NSNumber numberWithLong:[[NSDate date] timeIntervalSince1970] * 1000];
30
 }
31
 }
31
 
32
 
33
+
34
+BOOL RNNIsMainQueue() {
35
+  static void *mainQueueKey = &mainQueueKey;
36
+  static dispatch_once_t onceToken;
37
+  dispatch_once(&onceToken, ^{
38
+    dispatch_queue_set_specific(dispatch_get_main_queue(),
39
+                                mainQueueKey, mainQueueKey, NULL);
40
+  });
41
+  return dispatch_get_specific(mainQueueKey) == mainQueueKey;
42
+}
43
+
32
 @end
44
 @end

+ 2
- 0
lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj Zobrazit soubor

484
 		502F0E132178CF8200367CC3 /* UIViewController+RNNOptionsTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+RNNOptionsTest.m"; sourceTree = "<group>"; };
484
 		502F0E132178CF8200367CC3 /* UIViewController+RNNOptionsTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+RNNOptionsTest.m"; sourceTree = "<group>"; };
485
 		502F0E152178D09600367CC3 /* RNNBasePresenterTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNBasePresenterTest.m; sourceTree = "<group>"; };
485
 		502F0E152178D09600367CC3 /* RNNBasePresenterTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNBasePresenterTest.m; sourceTree = "<group>"; };
486
 		502F0E172179C39900367CC3 /* RNNTabBarPresenterTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNTabBarPresenterTest.m; sourceTree = "<group>"; };
486
 		502F0E172179C39900367CC3 /* RNNTabBarPresenterTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNTabBarPresenterTest.m; sourceTree = "<group>"; };
487
+		5030B62D23D60002008F1642 /* RNNAssert.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNAssert.h; sourceTree = "<group>"; };
487
 		50344D2623A03DB4004B6A7C /* BottomTabsAttachMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BottomTabsAttachMode.h; sourceTree = "<group>"; };
488
 		50344D2623A03DB4004B6A7C /* BottomTabsAttachMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BottomTabsAttachMode.h; sourceTree = "<group>"; };
488
 		50344D2723A03DB4004B6A7C /* BottomTabsAttachMode.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BottomTabsAttachMode.m; sourceTree = "<group>"; };
489
 		50344D2723A03DB4004B6A7C /* BottomTabsAttachMode.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BottomTabsAttachMode.m; sourceTree = "<group>"; };
489
 		5038A372216CDDB6009280BC /* UIViewController+SideMenuController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIViewController+SideMenuController.h"; sourceTree = "<group>"; };
490
 		5038A372216CDDB6009280BC /* UIViewController+SideMenuController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIViewController+SideMenuController.h"; sourceTree = "<group>"; };
1305
 				E5F6C39E22DB4D0E0093C2CE /* UIViewController+Utils.m */,
1306
 				E5F6C39E22DB4D0E0093C2CE /* UIViewController+Utils.m */,
1306
 				50DE2E43238EA14E005CD5F4 /* NSArray+utils.h */,
1307
 				50DE2E43238EA14E005CD5F4 /* NSArray+utils.h */,
1307
 				50DE2E44238EA14E005CD5F4 /* NSArray+utils.m */,
1308
 				50DE2E44238EA14E005CD5F4 /* NSArray+utils.m */,
1309
+				5030B62D23D60002008F1642 /* RNNAssert.h */,
1308
 			);
1310
 			);
1309
 			name = Utils;
1311
 			name = Utils;
1310
 			sourceTree = "<group>";
1312
 			sourceTree = "<group>";

+ 2
- 2
playground/ios/NavigationTests/RNNCommandsHandlerTest.m Zobrazit soubor

83
 	return [[RNNComponentViewController alloc] initWithLayoutInfo:layoutInfo rootViewCreator:_creator eventEmitter:nil presenter:[RNNComponentPresenter new] options:[[RNNNavigationOptions alloc] initWithDict:@{}] defaultOptions:nil];
83
 	return [[RNNComponentViewController alloc] initWithLayoutInfo:layoutInfo rootViewCreator:_creator eventEmitter:nil presenter:[RNNComponentPresenter new] options:[[RNNNavigationOptions alloc] initWithDict:@{}] defaultOptions:nil];
84
 }
84
 }
85
 
85
 
86
-- (void)testAssertReadyForEachMethodThrowsExceptoins {
86
+- (void)testAssertReadyForEachMethodThrowsExceptions {
87
 	NSArray* methods = [self getPublicMethodNamesForObject:self.uut];
87
 	NSArray* methods = [self getPublicMethodNamesForObject:self.uut];
88
 	[self.uut setReadyToReceiveCommands:false];
88
 	[self.uut setReadyToReceiveCommands:false];
89
 	for (NSString* methodName in methods) {
89
 	for (NSString* methodName in methods) {
94
 	}
94
 	}
95
 }
95
 }
96
 
96
 
97
--(NSArray*) getPublicMethodNamesForObject:(NSObject*)obj{
97
+- (NSArray*)getPublicMethodNamesForObject:(NSObject*)obj {
98
 	NSMutableArray* skipMethods = [NSMutableArray new];
98
 	NSMutableArray* skipMethods = [NSMutableArray new];
99
 	
99
 	
100
 	[skipMethods addObject:@"initWithControllerFactory:eventEmitter:stackManager:modalManager:overlayManager:mainWindow:"];
100
 	[skipMethods addObject:@"initWithControllerFactory:eventEmitter:stackManager:modalManager:overlayManager:mainWindow:"];