From dd400f842b416b421d73ce3d308b73e26a5d3577 Mon Sep 17 00:00:00 2001 From: Alex Dvornikov Date: Thu, 12 Oct 2017 12:30:24 -0700 Subject: [PATCH] add "jsBundlesDirectory" method to RCTBridgeDelegate Differential Revision: D6030185 fbshipit-source-id: 58d6f9d0d412c7ad0f83af9ae4df01c4dc1178bc --- React/Base/RCTBridgeDelegate.h | 7 +++++++ React/CxxBridge/RCTCxxBridge.mm | 7 ++++++- ReactCommon/cxxreact/JSIndexedRAMBundleRegistry.cpp | 4 ++-- ReactCommon/cxxreact/JSIndexedRAMBundleRegistry.h | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/React/Base/RCTBridgeDelegate.h b/React/Base/RCTBridgeDelegate.h index 2327b1c1de9..2ec89fd57ef 100644 --- a/React/Base/RCTBridgeDelegate.h +++ b/React/Base/RCTBridgeDelegate.h @@ -121,4 +121,11 @@ - (void)loadSourceForBridge:(RCTBridge *)bridge withBlock:(RCTSourceLoadBlock)loadCallback; +/** + * Specifies the path to folder where additional bundles are located + * + * @experimental + */ +- (NSURL *)jsBundlesDirectory; + @end diff --git a/React/CxxBridge/RCTCxxBridge.mm b/React/CxxBridge/RCTCxxBridge.mm index a499a8968ad..f95b19b57ae 100644 --- a/React/CxxBridge/RCTCxxBridge.mm +++ b/React/CxxBridge/RCTCxxBridge.mm @@ -1190,7 +1190,12 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR [self->_performanceLogger markStopForTag:RCTPLRAMBundleLoad]; [self->_performanceLogger setValue:scriptStr->size() forTag:RCTPLRAMStartupCodeSize]; if (self->_reactInstance) { - auto registry = std::make_unique(std::move(ramBundle), sourceUrlStr.UTF8String); + NSString *jsBundlesDirectory = [self.delegate respondsToSelector:@selector(jsBundlesDirectory)] + ? [[self.delegate jsBundlesDirectory].path stringByAppendingString:@"/"] + : nil; + auto registry = jsBundlesDirectory != nil + ? std::make_unique(std::move(ramBundle), jsBundlesDirectory.UTF8String) + : std::make_unique(std::move(ramBundle)); self->_reactInstance->loadRAMBundle(std::move(registry), std::move(scriptStr), sourceUrlStr.UTF8String, !async); } diff --git a/ReactCommon/cxxreact/JSIndexedRAMBundleRegistry.cpp b/ReactCommon/cxxreact/JSIndexedRAMBundleRegistry.cpp index 2e678802a58..44a58e36181 100644 --- a/ReactCommon/cxxreact/JSIndexedRAMBundleRegistry.cpp +++ b/ReactCommon/cxxreact/JSIndexedRAMBundleRegistry.cpp @@ -10,8 +10,8 @@ namespace facebook { namespace react { -JSIndexedRAMBundleRegistry::JSIndexedRAMBundleRegistry(std::unique_ptr mainBundle, const std::string& entryFile): - RAMBundleRegistry(std::move(mainBundle)), m_baseDirectoryPath(jsBundlesDir(entryFile)) {} +JSIndexedRAMBundleRegistry::JSIndexedRAMBundleRegistry(std::unique_ptr mainBundle, const std::string& baseDirectoryPath): +RAMBundleRegistry(std::move(mainBundle)), m_baseDirectoryPath(baseDirectoryPath) {} std::unique_ptr JSIndexedRAMBundleRegistry::bundleById(uint32_t index) const { std::string bundlePathById = m_baseDirectoryPath + toString(index) + ".jsbundle"; diff --git a/ReactCommon/cxxreact/JSIndexedRAMBundleRegistry.h b/ReactCommon/cxxreact/JSIndexedRAMBundleRegistry.h index 8dd213a2162..199f26772a5 100644 --- a/ReactCommon/cxxreact/JSIndexedRAMBundleRegistry.h +++ b/ReactCommon/cxxreact/JSIndexedRAMBundleRegistry.h @@ -13,7 +13,7 @@ namespace react { class RN_EXPORT JSIndexedRAMBundleRegistry: public RAMBundleRegistry { public: - JSIndexedRAMBundleRegistry(std::unique_ptr mainBundle, const std::string& entryFile); + JSIndexedRAMBundleRegistry(std::unique_ptr mainBundle, const std::string& baseDirectoryPath); protected: virtual std::unique_ptr bundleById(uint32_t index) const override;