mirror of
https://github.com/status-im/react-native.git
synced 2025-01-15 20:15:11 +00:00
[ReactNative] Fix and re-add WebView executor
This commit is contained in:
parent
ccbd656070
commit
72390239be
@ -47,7 +47,7 @@ typedef void (^WSMessageCallback)(NSError *error, NSDictionary *reply);
|
|||||||
[NSURLConnection connectionWithRequest:[NSURLRequest requestWithURL:startDevToolsURL] delegate:nil];
|
[NSURLConnection connectionWithRequest:[NSURLRequest requestWithURL:startDevToolsURL] delegate:nil];
|
||||||
|
|
||||||
if (![self connectToProxy]) {
|
if (![self connectToProxy]) {
|
||||||
RCTLogError(@"Connection to %@ timed out. Are you running node proxy?", url);
|
RCTLogError(@"Connection to %@ timed out. Are you running node proxy? If you are running on the device check if you have the right IP address on `RCTWebSocketExecutor.m` file.", url);
|
||||||
[self invalidate];
|
[self invalidate];
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
#import "RCTRootView.h"
|
#import "RCTRootView.h"
|
||||||
#import "RCTSparseArray.h"
|
#import "RCTSparseArray.h"
|
||||||
#import "RCTUtils.h"
|
#import "RCTUtils.h"
|
||||||
#import "RCTWebViewExecutor.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Must be kept in sync with `MessageQueue.js`.
|
* Must be kept in sync with `MessageQueue.js`.
|
||||||
@ -530,11 +529,7 @@ static id<RCTJavaScriptExecutor> _latestJSExecutor;
|
|||||||
- (void)setUp
|
- (void)setUp
|
||||||
{
|
{
|
||||||
Class executorClass = _executorClass ?: _globalExecutorClass ?: [RCTContextExecutor class];
|
Class executorClass = _executorClass ?: _globalExecutorClass ?: [RCTContextExecutor class];
|
||||||
if ([NSStringFromClass(executorClass) isEqualToString:@"RCTWebViewExecutor"]) {
|
_javaScriptExecutor = [[executorClass alloc] init];
|
||||||
_javaScriptExecutor = [[RCTWebViewExecutor alloc] initWithWebView:[[UIWebView alloc] init]];
|
|
||||||
} else {
|
|
||||||
_javaScriptExecutor = [[executorClass alloc] init];
|
|
||||||
}
|
|
||||||
_latestJSExecutor = _javaScriptExecutor;
|
_latestJSExecutor = _javaScriptExecutor;
|
||||||
_eventDispatcher = [[RCTEventDispatcher alloc] initWithBridge:self];
|
_eventDispatcher = [[RCTEventDispatcher alloc] initWithBridge:self];
|
||||||
_shadowQueue = dispatch_queue_create("com.facebook.ReactKit.ShadowQueue", DISPATCH_QUEUE_SERIAL);
|
_shadowQueue = dispatch_queue_create("com.facebook.ReactKit.ShadowQueue", DISPATCH_QUEUE_SERIAL);
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#import "RCTRedBox.h"
|
#import "RCTRedBox.h"
|
||||||
#import "RCTRootView.h"
|
#import "RCTRootView.h"
|
||||||
#import "RCTSourceCode.h"
|
#import "RCTSourceCode.h"
|
||||||
|
#import "RCTWebViewExecutor.h"
|
||||||
|
|
||||||
@interface RCTDevMenu () <UIActionSheetDelegate> {
|
@interface RCTDevMenu () <UIActionSheetDelegate> {
|
||||||
BOOL _liveReload;
|
BOOL _liveReload;
|
||||||
@ -33,13 +34,14 @@
|
|||||||
|
|
||||||
- (void)show
|
- (void)show
|
||||||
{
|
{
|
||||||
NSString *debugTitle = self.bridge.executorClass == Nil ? @"Enable Debugging" : @"Disable Debugging";
|
NSString *debugTitleChrome = self.bridge.executorClass != Nil && self.bridge.executorClass == NSClassFromString(@"RCTWebSocketExecutor") ? @"Disable Chrome Debugging" : @"Enable Chrome Debugging";
|
||||||
|
NSString *debugTitleSafari = self.bridge.executorClass == [RCTWebViewExecutor class] ? @"Disable Safari Debugging" : @"Enable Safari Debugging";
|
||||||
NSString *liveReloadTitle = _liveReload ? @"Disable Live Reload" : @"Enable Live Reload";
|
NSString *liveReloadTitle = _liveReload ? @"Disable Live Reload" : @"Enable Live Reload";
|
||||||
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"React Native: Development"
|
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"React Native: Development"
|
||||||
delegate:self
|
delegate:self
|
||||||
cancelButtonTitle:@"Cancel"
|
cancelButtonTitle:@"Cancel"
|
||||||
destructiveButtonTitle:nil
|
destructiveButtonTitle:nil
|
||||||
otherButtonTitles:@"Reload", debugTitle, liveReloadTitle, nil];
|
otherButtonTitles:@"Reload", debugTitleChrome, debugTitleSafari, liveReloadTitle, nil];
|
||||||
actionSheet.actionSheetStyle = UIBarStyleBlack;
|
actionSheet.actionSheetStyle = UIBarStyleBlack;
|
||||||
[actionSheet showInView:[[[[UIApplication sharedApplication] keyWindow] rootViewController] view]];
|
[actionSheet showInView:[[[[UIApplication sharedApplication] keyWindow] rootViewController] view]];
|
||||||
}
|
}
|
||||||
@ -49,9 +51,14 @@
|
|||||||
if (buttonIndex == 0) {
|
if (buttonIndex == 0) {
|
||||||
[self.bridge reload];
|
[self.bridge reload];
|
||||||
} else if (buttonIndex == 1) {
|
} else if (buttonIndex == 1) {
|
||||||
self.bridge.executorClass = self.bridge.executorClass == Nil ? NSClassFromString(@"RCTWebSocketExecutor") : nil;
|
Class cls = NSClassFromString(@"RCTWebSocketExecutor");
|
||||||
|
self.bridge.executorClass = (self.bridge.executorClass != cls) ? cls : nil;
|
||||||
[self.bridge reload];
|
[self.bridge reload];
|
||||||
} else if (buttonIndex == 2) {
|
} else if (buttonIndex == 2) {
|
||||||
|
Class cls = [RCTWebViewExecutor class];
|
||||||
|
self.bridge.executorClass = (self.bridge.executorClass != cls) ? cls : Nil;
|
||||||
|
[self.bridge reload];
|
||||||
|
} else if (buttonIndex == 3) {
|
||||||
_liveReload = !_liveReload;
|
_liveReload = !_liveReload;
|
||||||
[self _pollAndReload];
|
[self _pollAndReload];
|
||||||
}
|
}
|
||||||
|
@ -125,6 +125,8 @@ static void RCTReportError(RCTJavaScriptCallback callback, NSString *fmt, ...)
|
|||||||
RCTAssert(onComplete != nil, @"");
|
RCTAssert(onComplete != nil, @"");
|
||||||
_onApplicationScriptLoaded = onComplete;
|
_onApplicationScriptLoaded = onComplete;
|
||||||
|
|
||||||
|
script = [script stringByReplacingOccurrencesOfString:@"<script>" withString:@""];
|
||||||
|
script = [script stringByReplacingOccurrencesOfString:@"</script>" withString:@""];
|
||||||
if (_objectsToInject.count > 0) {
|
if (_objectsToInject.count > 0) {
|
||||||
NSMutableString *scriptWithInjections = [[NSMutableString alloc] initWithString:@"/* BEGIN NATIVELY INJECTED OBJECTS */\n"];
|
NSMutableString *scriptWithInjections = [[NSMutableString alloc] initWithString:@"/* BEGIN NATIVELY INJECTED OBJECTS */\n"];
|
||||||
[_objectsToInject enumerateKeysAndObjectsUsingBlock:^(NSString *objectName, NSString *blockScript, BOOL *stop) {
|
[_objectsToInject enumerateKeysAndObjectsUsingBlock:^(NSString *objectName, NSString *blockScript, BOOL *stop) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user