add support to provide fallback-sourceURL: in case primary-sourceURL fails to load
Reviewed By: javache Differential Revision: D3339692 fbshipit-source-id: 93fa1821bf4abca878832d4f75c6b9968d8d0460
This commit is contained in:
parent
298dc7c152
commit
1586a32fa7
|
@ -170,7 +170,18 @@ RCT_EXTERN NSArray<Class> *RCTGetModuleClasses(void);
|
|||
if ([self.delegate respondsToSelector:@selector(loadSourceForBridge:withBlock:)]) {
|
||||
[self.delegate loadSourceForBridge:_parentBridge withBlock:onSourceLoad];
|
||||
} else if (self.bundleURL) {
|
||||
[RCTJavaScriptLoader loadBundleAtURL:self.bundleURL onComplete:^(NSError *error, NSData *source) {
|
||||
if (error && [self.delegate respondsToSelector:@selector(fallbackSourceURLForBridge:)]) {
|
||||
NSURL *fallbackURL = [self.delegate fallbackSourceURLForBridge:_parentBridge];
|
||||
if (fallbackURL && ![fallbackURL isEqual:self.bundleURL]) {
|
||||
RCTLogError(@"Failed to load bundle(%@) with error:(%@)", self.bundleURL, error.localizedDescription);
|
||||
self.bundleURL = fallbackURL;
|
||||
[RCTJavaScriptLoader loadBundleAtURL:self.bundleURL onComplete:onSourceLoad];
|
||||
return;
|
||||
}
|
||||
}
|
||||
onSourceLoad(error, source);
|
||||
}];
|
||||
} else {
|
||||
// Allow testing without a script
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
|
|
|
@ -23,6 +23,15 @@ typedef void (^RCTSourceLoadBlock)(NSError *error, NSData *source);
|
|||
|
||||
@optional
|
||||
|
||||
/**
|
||||
* The bridge will attempt to load the JS source code from the location specified
|
||||
* by the `sourceURLForBridge:` method, if loading fails, you can implement this
|
||||
* method to specify fallbackSourceURL.
|
||||
* NOTE: We don't plan to support this API permanently (this method will be
|
||||
* removed after we track down why a valid sourceURL fails to load sometimes).
|
||||
*/
|
||||
- (NSURL *)fallbackSourceURLForBridge:(RCTBridge *)bridge;
|
||||
|
||||
/**
|
||||
* The bridge initializes any registered RCTBridgeModules automatically, however
|
||||
* if you wish to instantiate your own module instances, you can return them
|
||||
|
|
Loading…
Reference in New Issue