diff --git a/React/CxxBridge/RCTCxxBridge.mm b/React/CxxBridge/RCTCxxBridge.mm index 4efb27593..a499a8968 100644 --- a/React/CxxBridge/RCTCxxBridge.mm +++ b/React/CxxBridge/RCTCxxBridge.mm @@ -1190,8 +1190,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR [self->_performanceLogger markStopForTag:RCTPLRAMBundleLoad]; [self->_performanceLogger setValue:scriptStr->size() forTag:RCTPLRAMStartupCodeSize]; if (self->_reactInstance) { - std::string baseDirectoryPath = sourceUrlStr.stringByDeletingLastPathComponent.UTF8String; - auto registry = std::make_unique(std::move(ramBundle), baseDirectoryPath); + auto registry = std::make_unique(std::move(ramBundle), sourceUrlStr.UTF8String); self->_reactInstance->loadRAMBundle(std::move(registry), std::move(scriptStr), sourceUrlStr.UTF8String, !async); } diff --git a/ReactAndroid/src/main/jni/react/jni/JniRAMBundleRegistry.cpp b/ReactAndroid/src/main/jni/react/jni/JniRAMBundleRegistry.cpp index 17f38a81c..01c907d43 100644 --- a/ReactAndroid/src/main/jni/react/jni/JniRAMBundleRegistry.cpp +++ b/ReactAndroid/src/main/jni/react/jni/JniRAMBundleRegistry.cpp @@ -2,8 +2,6 @@ #include "JniRAMBundleRegistry.h" -#include - #include #include @@ -12,16 +10,6 @@ namespace facebook { namespace react { -static std::string jsBundlesDir(const std::string& entryFile) { - std::string dir = dirname(entryFile.c_str()); - std::string entryName = basename(entryFile.c_str()); - entryName.erase(entryName.find("."), std::string::npos); - - std::string path = "js-bundles/" + entryName + "/"; - // android's asset manager does not work with paths that start with a dot - return dir == "." ? path : dir + "/" + path; -} - JniRAMBundleRegistry::JniRAMBundleRegistry(std::unique_ptr mainBundle, AAssetManager *assetManager, const std::string& entryFile) : RAMBundleRegistry(std::move(mainBundle)), m_assetManager(assetManager), diff --git a/ReactCommon/cxxreact/JSIndexedRAMBundleRegistry.cpp b/ReactCommon/cxxreact/JSIndexedRAMBundleRegistry.cpp index 92d1fdbfb..2e678802a 100644 --- a/ReactCommon/cxxreact/JSIndexedRAMBundleRegistry.cpp +++ b/ReactCommon/cxxreact/JSIndexedRAMBundleRegistry.cpp @@ -10,12 +10,12 @@ namespace facebook { namespace react { -std::unique_ptr JSIndexedRAMBundleRegistry::bundleById(uint32_t index) const { - return folly::make_unique(bundlePathById(index).c_str()); -} +JSIndexedRAMBundleRegistry::JSIndexedRAMBundleRegistry(std::unique_ptr mainBundle, const std::string& entryFile): + RAMBundleRegistry(std::move(mainBundle)), m_baseDirectoryPath(jsBundlesDir(entryFile)) {} -std::string JSIndexedRAMBundleRegistry::bundlePathById(uint32_t index) const { - return m_baseDirectoryPath + "/js-bundles/" + toString(index) + ".jsbundle"; +std::unique_ptr JSIndexedRAMBundleRegistry::bundleById(uint32_t index) const { + std::string bundlePathById = m_baseDirectoryPath + toString(index) + ".jsbundle"; + return folly::make_unique(bundlePathById.c_str()); } } // namespace react diff --git a/ReactCommon/cxxreact/JSIndexedRAMBundleRegistry.h b/ReactCommon/cxxreact/JSIndexedRAMBundleRegistry.h index db3a189e8..8dd213a21 100644 --- a/ReactCommon/cxxreact/JSIndexedRAMBundleRegistry.h +++ b/ReactCommon/cxxreact/JSIndexedRAMBundleRegistry.h @@ -13,16 +13,11 @@ namespace react { class RN_EXPORT JSIndexedRAMBundleRegistry: public RAMBundleRegistry { public: - JSIndexedRAMBundleRegistry( - std::unique_ptr mainBundle, - std::string baseDirectoryPath): - RAMBundleRegistry(std::move(mainBundle)), m_baseDirectoryPath(baseDirectoryPath) {} + JSIndexedRAMBundleRegistry(std::unique_ptr mainBundle, const std::string& entryFile); protected: virtual std::unique_ptr bundleById(uint32_t index) const override; private: - std::string bundlePathById(uint32_t index) const; - std::string m_baseDirectoryPath; }; diff --git a/ReactCommon/cxxreact/RAMBundleRegistry.cpp b/ReactCommon/cxxreact/RAMBundleRegistry.cpp index f291f71f1..6b88a155a 100644 --- a/ReactCommon/cxxreact/RAMBundleRegistry.cpp +++ b/ReactCommon/cxxreact/RAMBundleRegistry.cpp @@ -2,6 +2,8 @@ #include "RAMBundleRegistry.h" +#include + namespace facebook { namespace react { @@ -23,5 +25,20 @@ JSModulesUnbundle *RAMBundleRegistry::getBundle(uint32_t bundleId) const { return m_bundles.at(bundleId).get(); } +std::string RAMBundleRegistry::jsBundlesDir(std::string entryFile) { + char *pEntryFile = const_cast(entryFile.c_str()); + std::string dir = dirname(pEntryFile); + std::string entryName = basename(pEntryFile); + + std::size_t dotPosition = entryName.find("."); + if (dotPosition != std::string::npos) { + entryName.erase(dotPosition, std::string::npos); + } + + std::string path = "js-bundles/" + entryName + "/"; + // android's asset manager does not work with paths that start with a dot + return dir == "." ? path : dir + "/" + path; +} + } // namespace react } // namespace facebook diff --git a/ReactCommon/cxxreact/RAMBundleRegistry.h b/ReactCommon/cxxreact/RAMBundleRegistry.h index 950379b83..d146be447 100644 --- a/ReactCommon/cxxreact/RAMBundleRegistry.h +++ b/ReactCommon/cxxreact/RAMBundleRegistry.h @@ -28,6 +28,7 @@ public: JSModulesUnbundle::Module getModule(uint32_t bundleId, uint32_t moduleId); virtual ~RAMBundleRegistry() {}; protected: + std::string jsBundlesDir(std::string entryFile); virtual std::unique_ptr bundleById(uint32_t index) const { throw std::runtime_error("Please, override this method in a subclass to support multiple RAM bundles."); }