Skip to content

Commit

Permalink
Add new method jsBundleURLForBundleRoot with fallback block to RCTBun…
Browse files Browse the repository at this point in the history
…dleURLProvider

Reviewed By: julian-krzeminski

Differential Revision: D17336324

fbshipit-source-id: b14a08d940ec7594978d3e34f1e833f65d3bd411
  • Loading branch information
apadalko authored and facebook-github-bot committed Sep 23, 2019
1 parent 845cbec commit 034a7d1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 7 additions & 0 deletions React/Base/RCTBundleURLProvider.h
Expand Up @@ -31,6 +31,13 @@ extern const NSUInteger kRCTBundleURLProviderDefaultPort;
*/
- (void)resetToDefaults;

/**
* Returns the jsBundleURL for a given bundle entrypoint and
* the fallback offline JS bundle if the packager is not running.
*/
- (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot
fallbackURLProvider:(NSURL *(^)(void))fallbackURLProvider;

/**
* Returns the jsBundleURL for a given bundle entrypoint and
* the fallback offline JS bundle if the packager is not running.
Expand Down
12 changes: 10 additions & 2 deletions React/Base/RCTBundleURLProvider.m
Expand Up @@ -130,11 +130,11 @@ - (NSString *)packagerServerHost
return nil;
}

- (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot fallbackResource:(NSString *)resourceName fallbackExtension:(NSString *)extension
- (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot fallbackURLProvider:(NSURL *(^)(void))fallbackURLProvider
{
NSString *packagerServerHost = [self packagerServerHost];
if (!packagerServerHost) {
return [self jsBundleURLForFallbackResource:resourceName fallbackExtension:extension];
return fallbackURLProvider();
} else {
return [RCTBundleURLProvider jsBundleURLForBundleRoot:bundleRoot
packagerHost:packagerServerHost
Expand All @@ -143,6 +143,14 @@ - (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot fallbackResource:(NSS
}
}

- (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot
fallbackResource:(NSString *)resourceName fallbackExtension:(NSString *)extension
{
return [self jsBundleURLForBundleRoot:bundleRoot fallbackURLProvider:^NSURL*{
return [self jsBundleURLForFallbackResource:resourceName fallbackExtension:extension];
}];
}

- (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot fallbackResource:(NSString *)resourceName
{
return [self jsBundleURLForBundleRoot:bundleRoot fallbackResource:resourceName fallbackExtension:nil];
Expand Down

0 comments on commit 034a7d1

Please sign in to comment.