mirror of
https://github.com/status-im/react-native.git
synced 2025-02-26 08:05:34 +00:00
[ReactNative] Fix script load from local files
This commit is contained in:
parent
128be89491
commit
9df3e889ad
@ -55,12 +55,20 @@
|
||||
|
||||
- (void)loadBundleAtURL:(NSURL *)scriptURL onComplete:(void (^)(NSError *))onComplete
|
||||
{
|
||||
if (!scriptURL) {
|
||||
if (scriptURL == nil) {
|
||||
NSError *error = [NSError errorWithDomain:@"JavaScriptLoader"
|
||||
code:1
|
||||
userInfo:@{NSLocalizedDescriptionKey: @"No script URL provided"}];
|
||||
onComplete(error);
|
||||
return;
|
||||
} else if ([scriptURL isFileURL]) {
|
||||
NSString *bundlePath = [[NSBundle bundleForClass:[self class]] resourcePath];
|
||||
NSString *localPath = [scriptURL.absoluteString substringFromIndex:@"file://".length];
|
||||
|
||||
if (![localPath hasPrefix:bundlePath]) {
|
||||
NSString *absolutePath = [NSString stringWithFormat:@"%@/%@", bundlePath, localPath];
|
||||
scriptURL = [NSURL fileURLWithPath:absolutePath];
|
||||
}
|
||||
}
|
||||
|
||||
NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithURL:scriptURL completionHandler:
|
||||
@ -115,18 +123,15 @@
|
||||
onComplete(error);
|
||||
return;
|
||||
}
|
||||
|
||||
// Success!
|
||||
RCTSourceCode *sourceCodeModule = _bridge.modules[NSStringFromClass([RCTSourceCode class])];
|
||||
sourceCodeModule.scriptURL = scriptURL;
|
||||
sourceCodeModule.scriptText = rawText;
|
||||
|
||||
[_bridge enqueueApplicationScript:rawText url:scriptURL onComplete:^(NSError *_error) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
onComplete(error);
|
||||
onComplete(_error);
|
||||
});
|
||||
}];
|
||||
|
||||
}];
|
||||
|
||||
[task resume];
|
||||
|
Loading…
x
Reference in New Issue
Block a user