-
Notifications
You must be signed in to change notification settings - Fork 24.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Android support for loading multiple RAM bundles
Differential Revision: D5901574 fbshipit-source-id: 395bae41e58505918d7ad20ac432eba3361361ea
- Loading branch information
1 parent
e691699
commit 4162d73
Showing
6 changed files
with
76 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
ReactAndroid/src/main/jni/react/jni/JniRAMBundleRegistry.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2004-present Facebook. All Rights Reserved. | ||
|
||
#include "JniRAMBundleRegistry.h" | ||
|
||
#include <libgen.h> | ||
|
||
#include <folly/Conv.h> | ||
#include <folly/Memory.h> | ||
|
||
#include "JniJSModulesUnbundle.h" | ||
|
||
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<JSModulesUnbundle> mainBundle, AAssetManager *assetManager, const std::string& entryFile) : | ||
RAMBundleRegistry(std::move(mainBundle)), | ||
m_assetManager(assetManager), | ||
m_baseDirectoryPath(jsBundlesDir(entryFile)) {} | ||
|
||
std::unique_ptr<JSModulesUnbundle> JniRAMBundleRegistry::bundleById(uint32_t index) const { | ||
std::string bundlePathById = m_baseDirectoryPath + folly::to<std::string>(index) + "/js-modules/"; | ||
return folly::make_unique<JniJSModulesUnbundle>(m_assetManager, bundlePathById); | ||
} | ||
|
||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
ReactAndroid/src/main/jni/react/jni/JniRAMBundleRegistry.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2004-present Facebook. All Rights Reserved. | ||
|
||
#include <android/asset_manager.h> | ||
#include <cxxreact/RAMBundleRegistry.h> | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
class JniRAMBundleRegistry : public RAMBundleRegistry { | ||
public: | ||
JniRAMBundleRegistry(std::unique_ptr<JSModulesUnbundle> mainBundle, AAssetManager *assetManager, const std::string& entryFile); | ||
|
||
protected: | ||
virtual std::unique_ptr<JSModulesUnbundle> bundleById(uint32_t index) const override; | ||
private: | ||
AAssetManager *m_assetManager = nullptr; | ||
std::string m_baseDirectoryPath; | ||
}; | ||
|
||
} | ||
} |