|
16 | 16 | #import "RCTLog.h" |
17 | 17 | #import "RCTPerfStats.h" |
18 | 18 | #import "RCTProfile.h" |
19 | | -#import "RCTRootView.h" |
| 19 | +#import "RCTRedBox.h" |
| 20 | +#import "RCTJavaScriptExecutorSource.h" |
| 21 | +#import "RCTStandardExecutorSource.h" |
20 | 22 | #import "RCTSourceCode.h" |
21 | 23 | #import "RCTUtils.h" |
22 | 24 |
|
@@ -45,7 +47,7 @@ - (void)RCT_motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event |
45 | 47 |
|
46 | 48 | @interface RCTDevMenu () <RCTBridgeModule, UIActionSheetDelegate> |
47 | 49 |
|
48 | | -@property (nonatomic, strong) Class executorClass; |
| 50 | +@property (nonatomic, assign) RCTStandardExecutorType executorType; |
49 | 51 |
|
50 | 52 | @end |
51 | 53 |
|
@@ -114,7 +116,7 @@ - (instancetype)init |
114 | 116 | [commands registerKeyCommandWithInput:@"n" |
115 | 117 | modifierFlags:UIKeyModifierCommand |
116 | 118 | action:^(UIKeyCommand *command) { |
117 | | - weakSelf.executorClass = Nil; |
| 119 | + weakSelf.executorType = RCTStandardExecutorTypeDefault; |
118 | 120 | }]; |
119 | 121 | #endif |
120 | 122 |
|
@@ -148,7 +150,7 @@ - (void)updateSettings |
148 | 150 | self.profilingEnabled = [_settings[@"profilingEnabled"] ?: @NO boolValue]; |
149 | 151 | self.liveReloadEnabled = [_settings[@"liveReloadEnabled"] ?: @NO boolValue]; |
150 | 152 | self.showFPS = [_settings[@"showFPS"] ?: @NO boolValue]; |
151 | | - self.executorClass = NSClassFromString(_settings[@"executorClass"]); |
| 153 | + self.executorType = [_settings[@"executorType"] ?: @(RCTStandardExecutorTypeDefault) unsignedIntegerValue]; |
152 | 154 | } |
153 | 155 |
|
154 | 156 | - (void)jsLoaded:(NSNotification *)notification |
@@ -177,7 +179,7 @@ - (void)jsLoaded:(NSNotification *)notification |
177 | 179 | // Hit these setters again after bridge has finished loading |
178 | 180 | self.profilingEnabled = _profilingEnabled; |
179 | 181 | self.liveReloadEnabled = _liveReloadEnabled; |
180 | | - self.executorClass = _executorClass; |
| 182 | + self.executorType = _executorType; |
181 | 183 | }); |
182 | 184 | } |
183 | 185 |
|
@@ -231,16 +233,24 @@ - (void)toggle |
231 | 233 | return; |
232 | 234 | } |
233 | 235 |
|
234 | | - NSString *debugTitleChrome = _executorClass && _executorClass == NSClassFromString(@"RCTWebSocketExecutor") ? @"Disable Chrome Debugging" : @"Debug in Chrome"; |
235 | | - NSString *debugTitleSafari = _executorClass && _executorClass == NSClassFromString(@"RCTWebViewExecutor") ? @"Disable Safari Debugging" : @"Debug in Safari"; |
236 | | - NSString *fpsMonitor = _showFPS ? @"Hide FPS Monitor" : @"Show FPS Monitor"; |
237 | | - |
238 | 236 | UIActionSheet *actionSheet = |
239 | 237 | [[UIActionSheet alloc] initWithTitle:@"React Native: Development" |
240 | 238 | delegate:self |
241 | 239 | cancelButtonTitle:nil |
242 | 240 | destructiveButtonTitle:nil |
243 | | - otherButtonTitles:@"Reload", debugTitleChrome, debugTitleSafari, fpsMonitor, nil]; |
| 241 | + otherButtonTitles:@"Reload", nil]; |
| 242 | + |
| 243 | + if ([_bridge.executorSource isKindOfClass:[RCTStandardExecutorSource class]]) { |
| 244 | + RCTStandardExecutorSource *source = (RCTStandardExecutorSource *)_bridge.executorSource; |
| 245 | + RCTStandardExecutorType executorType = source.executorType; |
| 246 | + NSString *debugTitleChrome = (executorType == RCTStandardExecutorTypeWebSocket) ? @"Disable Chrome Debugging" : @"Debug in Chrome"; |
| 247 | + NSString *debugTitleSafari = (executorType == RCTStandardExecutorTypeUIWebView) ? @"Disable Safari Debugging" : @"Debug in Safari"; |
| 248 | + [actionSheet addButtonWithTitle:debugTitleChrome]; |
| 249 | + [actionSheet addButtonWithTitle:debugTitleSafari]; |
| 250 | + } |
| 251 | + |
| 252 | + NSString *fpsMonitor = _showFPS ? @"Hide FPS Monitor" : @"Show FPS Monitor"; |
| 253 | + [actionSheet addButtonWithTitle:fpsMonitor]; |
244 | 254 |
|
245 | 255 | [actionSheet addButtonWithTitle:@"Inspect Element"]; |
246 | 256 |
|
@@ -275,47 +285,25 @@ - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger |
275 | 285 | return; |
276 | 286 | } |
277 | 287 |
|
278 | | - switch (buttonIndex) { |
279 | | - case 0: { |
280 | | - [self reload]; |
281 | | - break; |
282 | | - } |
283 | | - case 1: { |
284 | | - Class cls = NSClassFromString(@"RCTWebSocketExecutor"); |
285 | | - if (!cls) { |
286 | | - [[[UIAlertView alloc] initWithTitle:@"Chrome Debugger Unavailable" |
287 | | - message:@"You need to include the RCTWebSocket library to enable Chrome debugging" |
288 | | - delegate:nil |
289 | | - cancelButtonTitle:@"OK" |
290 | | - otherButtonTitles:nil] show]; |
291 | | - return; |
292 | | - } |
293 | | - self.executorClass = (_executorClass == cls) ? Nil : cls; |
294 | | - break; |
295 | | - } |
296 | | - case 2: { |
297 | | - Class cls = NSClassFromString(@"RCTWebViewExecutor"); |
298 | | - self.executorClass = (_executorClass == cls) ? Nil : cls; |
299 | | - break; |
300 | | - } |
301 | | - case 3: { |
302 | | - self.showFPS = !_showFPS; |
303 | | - break; |
304 | | - } |
305 | | - case 4: { |
306 | | - [_bridge.eventDispatcher sendDeviceEventWithName:@"toggleElementInspector" body:nil]; |
307 | | - break; |
308 | | - } |
309 | | - case 5: { |
310 | | - self.liveReloadEnabled = !_liveReloadEnabled; |
311 | | - break; |
312 | | - } |
313 | | - case 6: { |
314 | | - self.profilingEnabled = !_profilingEnabled; |
315 | | - break; |
316 | | - } |
317 | | - default: |
318 | | - break; |
| 288 | + if (buttonIndex == 0) { |
| 289 | + [self reload]; |
| 290 | + return; |
| 291 | + } |
| 292 | + |
| 293 | + // Note: after supporting iOS 8+, use UIAlertController which has a more cohesive API |
| 294 | + NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex]; |
| 295 | + if ([buttonTitle containsString:@"Chrome"]) { |
| 296 | + [self _toggleExecutorType:RCTStandardExecutorTypeWebSocket]; |
| 297 | + } else if ([buttonTitle containsString:@"Safari"]) { |
| 298 | + [self _toggleExecutorType:RCTStandardExecutorTypeUIWebView]; |
| 299 | + } else if ([buttonTitle containsString:@"FPS Monitor"]) { |
| 300 | + self.showFPS = !_showFPS; |
| 301 | + } else if ([buttonTitle containsString:@"Inspect Element"]) { |
| 302 | + [_bridge.eventDispatcher sendDeviceEventWithName:@"toggleElementInspector" body:nil]; |
| 303 | + } else if ([buttonTitle containsString:@"Live Reload"]) { |
| 304 | + self.liveReloadEnabled = !_liveReloadEnabled; |
| 305 | + } else if ([buttonTitle containsString:@"Profiling"]) { |
| 306 | + self.profilingEnabled = !_profilingEnabled; |
319 | 307 | } |
320 | 308 | } |
321 | 309 |
|
@@ -358,27 +346,28 @@ - (void)setLiveReloadEnabled:(BOOL)enabled |
358 | 346 | } |
359 | 347 | } |
360 | 348 |
|
361 | | -- (void)setExecutorClass:(Class)executorClass |
| 349 | +- (void)_toggleExecutorType:(RCTStandardExecutorType)executorType |
362 | 350 | { |
363 | | - if (_executorClass != executorClass) { |
364 | | - _executorClass = executorClass; |
365 | | - [self updateSetting:@"executorClass" value: NSStringFromClass(executorClass)]; |
| 351 | + if (_executorType == executorType) { |
| 352 | + self.executorType = RCTStandardExecutorTypeDefault; |
| 353 | + } else { |
| 354 | + self.executorType = executorType; |
366 | 355 | } |
| 356 | +} |
367 | 357 |
|
368 | | - if (_bridge.executorClass != executorClass) { |
369 | | - |
370 | | - // TODO (6929129): we can remove this special case test once we have better |
371 | | - // support for custom executors in the dev menu. But right now this is |
372 | | - // needed to prevent overriding a custom executor with the default if a |
373 | | - // custom executor has been set directly on the bridge |
374 | | - if (executorClass == Nil && |
375 | | - (_bridge.executorClass != NSClassFromString(@"RCTWebSocketExecutor") && |
376 | | - _bridge.executorClass != NSClassFromString(@"RCTWebViewExecutor"))) { |
377 | | - return; |
378 | | - } |
| 358 | +- (void)setExecutorType:(RCTStandardExecutorType)executorType |
| 359 | +{ |
| 360 | + if (_executorType != executorType) { |
| 361 | + _executorType = executorType; |
| 362 | + [self updateSetting:@"executorType" value:@(executorType)]; |
| 363 | + } |
379 | 364 |
|
380 | | - _bridge.executorClass = executorClass; |
381 | | - [self reload]; |
| 365 | + if ([_bridge.executorSource isKindOfClass:[RCTStandardExecutorSource class]]) { |
| 366 | + RCTStandardExecutorSource *source = (RCTStandardExecutorSource *)_bridge.executorSource; |
| 367 | + if (source.executorType != executorType) { |
| 368 | + source.executorType = executorType; |
| 369 | + [_bridge reload]; |
| 370 | + } |
382 | 371 | } |
383 | 372 | } |
384 | 373 |
|
|
0 commit comments