From 90a00a66e22fe89729ff43323cc9fb4ddf073a02 Mon Sep 17 00:00:00 2001 From: Yujie Liu Date: Fri, 3 Nov 2017 14:15:19 -0700 Subject: [PATCH] bundledSourceURLForBridge always return bundle path Differential Revision: D6215467 fbshipit-source-id: 49d818cfdb776dd849a809440a1e592e5cb2231a --- React/Base/RCTBridgeDelegate.h | 2 -- React/Base/RCTBundleURLProvider.h | 8 ++++++++ React/Base/RCTBundleURLProvider.m | 12 +++++++++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/React/Base/RCTBridgeDelegate.h b/React/Base/RCTBridgeDelegate.h index a58d8246f..631e18255 100644 --- a/React/Base/RCTBridgeDelegate.h +++ b/React/Base/RCTBridgeDelegate.h @@ -43,8 +43,6 @@ /** * The location of bundle path, this should be a `file://` url * pointing to a path inside the bundle resources, e.g. `file://..//main.jsbundle`. - * When running from the packager this should be an absolute URL, - * e.g. `http://localhost:8081/index.ios.bundle`. */ - (NSURL *)bundledSourceURLForBridge:(RCTBridge *)bridge; diff --git a/React/Base/RCTBundleURLProvider.h b/React/Base/RCTBundleURLProvider.h index 360128891..efc9be73b 100644 --- a/React/Base/RCTBundleURLProvider.h +++ b/React/Base/RCTBundleURLProvider.h @@ -42,6 +42,14 @@ extern const NSUInteger kRCTBundleURLProviderDefaultPort; - (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot fallbackResource:(NSString *)resourceName; +/** + * Returns the jsBundleURL for a given bundle entrypoint and + * the fallback offline JS bundle. If resourceName or extension + * are nil, "main" and "jsbundle" will be used, respectively. + */ +- (NSURL *)jsBundleURLForFallbackResource:(NSString *)resourceName + fallbackExtension:(NSString *)extension; + /** * Returns the resourceURL for a given bundle entrypoint and * the fallback offline resource file if the packager is not running. diff --git a/React/Base/RCTBundleURLProvider.m b/React/Base/RCTBundleURLProvider.m index c28e3aa44..e6daa3020 100644 --- a/React/Base/RCTBundleURLProvider.m +++ b/React/Base/RCTBundleURLProvider.m @@ -121,9 +121,7 @@ static NSURL *serverRootWithHost(NSString *host) { NSString *packagerServerHost = [self packagerServerHost]; if (!packagerServerHost) { - resourceName = resourceName ?: @"main"; - extension = extension ?: @"jsbundle"; - return [[NSBundle mainBundle] URLForResource:resourceName withExtension:extension]; + return [self jsBundleURLForFallbackResource:resourceName fallbackExtension:extension]; } else { return [RCTBundleURLProvider jsBundleURLForBundleRoot:bundleRoot packagerHost:packagerServerHost @@ -137,6 +135,14 @@ static NSURL *serverRootWithHost(NSString *host) return [self jsBundleURLForBundleRoot:bundleRoot fallbackResource:resourceName fallbackExtension:nil]; } +- (NSURL *)jsBundleURLForFallbackResource:(NSString *)resourceName + fallbackExtension:(NSString *)extension +{ + resourceName = resourceName ?: @"main"; + extension = extension ?: @"jsbundle"; + return [[NSBundle mainBundle] URLForResource:resourceName withExtension:extension]; +} + - (NSURL *)resourceURLForResourceRoot:(NSString *)root resourceName:(NSString *)name resourceExtension:(NSString *)extension