[ReactNative] Fix WebView executor
This commit is contained in:
parent
6cb7178098
commit
67196b36bb
|
@ -42,13 +42,17 @@ static void RCTReportError(RCTJavaScriptCallback callback, NSString *fmt, ...)
|
||||||
{
|
{
|
||||||
UIWebView *_webView;
|
UIWebView *_webView;
|
||||||
NSMutableDictionary *_objectsToInject;
|
NSMutableDictionary *_objectsToInject;
|
||||||
|
NSRegularExpression *_commentsRegex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@synthesize valid = _valid;
|
||||||
|
|
||||||
- (instancetype)initWithWebView:(UIWebView *)webView
|
- (instancetype)initWithWebView:(UIWebView *)webView
|
||||||
{
|
{
|
||||||
if ((self = [super init])) {
|
if ((self = [super init])) {
|
||||||
_objectsToInject = [[NSMutableDictionary alloc] init];
|
_objectsToInject = [[NSMutableDictionary alloc] init];
|
||||||
_webView = webView ?: [[UIWebView alloc] init];
|
_webView = webView ?: [[UIWebView alloc] init];
|
||||||
|
_commentsRegex = [NSRegularExpression regularExpressionWithPattern:@"(^ *?\\/\\/.*?$|\\/\\*\\*[\\s\\S]+?\\*\\/)" options:NSRegularExpressionAnchorsMatchLines error:NULL];
|
||||||
_webView.delegate = self;
|
_webView.delegate = self;
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
|
@ -59,13 +63,9 @@ static void RCTReportError(RCTJavaScriptCallback callback, NSString *fmt, ...)
|
||||||
return [self initWithWebView:nil];
|
return [self initWithWebView:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)isValid
|
|
||||||
{
|
|
||||||
return _webView != nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)invalidate
|
- (void)invalidate
|
||||||
{
|
{
|
||||||
|
_valid = NO;
|
||||||
_webView.delegate = nil;
|
_webView.delegate = nil;
|
||||||
_webView = nil;
|
_webView = nil;
|
||||||
}
|
}
|
||||||
|
@ -129,10 +129,21 @@ static void RCTReportError(RCTJavaScriptCallback callback, NSString *fmt, ...)
|
||||||
}
|
}
|
||||||
|
|
||||||
RCTAssert(onComplete != nil, @"");
|
RCTAssert(onComplete != nil, @"");
|
||||||
_onApplicationScriptLoaded = onComplete;
|
__weak RCTWebViewExecutor *weakSelf = self;
|
||||||
|
_onApplicationScriptLoaded = ^(NSError *error){
|
||||||
|
RCTWebViewExecutor *strongSelf = weakSelf;
|
||||||
|
if (!strongSelf) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
strongSelf->_valid = error == nil;
|
||||||
|
onComplete(error);
|
||||||
|
};
|
||||||
|
|
||||||
|
script = [_commentsRegex stringByReplacingMatchesInString:script
|
||||||
|
options:0
|
||||||
|
range:NSMakeRange(0, script.length)
|
||||||
|
withTemplate:@""];
|
||||||
|
|
||||||
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…
Reference in New Issue