mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-02-02 00:51:10 +00:00
rlottie: now loadFromData() api takes resourcePath for loading external resource
This commit is contained in:
committed by
Hermet Park
parent
8047001e1f
commit
b7d488671a
@@ -369,9 +369,9 @@ void LottieView::setFilePath(const char *filePath)
|
||||
}
|
||||
}
|
||||
|
||||
void LottieView::loadFromData(const std::string &jsonData, const std::string &key)
|
||||
void LottieView::loadFromData(const std::string &jsonData, const std::string &key, const std::string &resourcePath)
|
||||
{
|
||||
if (mPlayer = Animation::loadFromData(jsonData, key)) {
|
||||
if (mPlayer = Animation::loadFromData(jsonData, key, resourcePath)) {
|
||||
mFrameRate = mPlayer->frameRate();
|
||||
mTotalFrame = mPlayer->totalFrame();
|
||||
} else {
|
||||
|
||||
@@ -49,7 +49,7 @@ public:
|
||||
void setSize(int w, int h);
|
||||
void setPos(int x, int y);
|
||||
void setFilePath(const char *filePath);
|
||||
void loadFromData(const std::string &jsonData, const std::string &key);
|
||||
void loadFromData(const std::string &jsonData, const std::string &key, const std::string &resourcePath="");
|
||||
void show();
|
||||
void hide();
|
||||
void loop(bool loop);
|
||||
|
||||
@@ -143,7 +143,7 @@ public:
|
||||
* @internal
|
||||
*/
|
||||
static std::unique_ptr<Animation>
|
||||
loadFromData(std::string jsonData, const std::string &key);
|
||||
loadFromData(std::string jsonData, const std::string &key, const std::string &resourcePath="");
|
||||
|
||||
/**
|
||||
* @brief Returns default framerate of the Lottie resource.
|
||||
|
||||
@@ -49,6 +49,7 @@ LOT_EXPORT Lottie_Animation *lottie_animation_from_file(const char *path);
|
||||
*
|
||||
* @param[in] data The JSON string data.
|
||||
* @param[in] key the string that will be used to cache the JSON string data.
|
||||
* @param[in] resource_path the path that will be used to load external resource needed by the JSON data.
|
||||
*
|
||||
* @return Animation object that can build the contents of the
|
||||
* Lottie resource represented by JSON string data.
|
||||
@@ -56,7 +57,7 @@ LOT_EXPORT Lottie_Animation *lottie_animation_from_file(const char *path);
|
||||
* @ingroup Lottie_Animation
|
||||
* @internal
|
||||
*/
|
||||
LOT_EXPORT Lottie_Animation *lottie_animation_from_data(const char *data, const char *key);
|
||||
LOT_EXPORT Lottie_Animation *lottie_animation_from_data(const char *data, const char *key, const char *resource_path);
|
||||
|
||||
/**
|
||||
* @brief Free given Animation object resource.
|
||||
|
||||
@@ -41,9 +41,9 @@ LOT_EXPORT Lottie_Animation_S *lottie_animation_from_file(const char *path)
|
||||
}
|
||||
}
|
||||
|
||||
LOT_EXPORT Lottie_Animation_S *lottie_animation_from_data(const char *data, const char *key)
|
||||
LOT_EXPORT Lottie_Animation_S *lottie_animation_from_data(const char *data, const char *key, const char *resourcePath)
|
||||
{
|
||||
if (auto animation = Animation::loadFromData(data, key) ) {
|
||||
if (auto animation = Animation::loadFromData(data, key, resourcePath) ) {
|
||||
Lottie_Animation_S *handle = new Lottie_Animation_S();
|
||||
handle->mAnimation = std::move(animation);
|
||||
return handle;
|
||||
|
||||
@@ -198,7 +198,7 @@ std::future<Surface> AnimationImpl::renderAsync(size_t frameNo, Surface &&surfac
|
||||
* @param path add the details
|
||||
*/
|
||||
std::unique_ptr<Animation>
|
||||
Animation::loadFromData(std::string jsonData, const std::string &key)
|
||||
Animation::loadFromData(std::string jsonData, const std::string &key, const std::string &resourcePath)
|
||||
{
|
||||
if (jsonData.empty()) {
|
||||
vWarning << "jason data is empty";
|
||||
@@ -206,7 +206,8 @@ Animation::loadFromData(std::string jsonData, const std::string &key)
|
||||
}
|
||||
|
||||
LottieLoader loader;
|
||||
if (loader.loadFromData(std::move(jsonData), key)) {
|
||||
if (loader.loadFromData(std::move(jsonData), key,
|
||||
(resourcePath.empty() ? " " : resourcePath))) {
|
||||
auto animation = std::unique_ptr<Animation>(new Animation);
|
||||
animation->d->init(loader.model());
|
||||
return animation;
|
||||
|
||||
@@ -90,14 +90,14 @@ bool LottieLoader::load(const std::string &path)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LottieLoader::loadFromData(std::string &&jsonData, const std::string &key)
|
||||
bool LottieLoader::loadFromData(std::string &&jsonData, const std::string &key, const std::string &resourcePath)
|
||||
{
|
||||
LottieFileCache &fileCache = LottieFileCache::get();
|
||||
|
||||
mModel = fileCache.find(key);
|
||||
if (mModel) return true;
|
||||
|
||||
LottieParser parser(const_cast<char *>(jsonData.c_str()));
|
||||
LottieParser parser(const_cast<char *>(jsonData.c_str()), resourcePath.c_str());
|
||||
mModel = parser.model();
|
||||
fileCache.add(key, mModel);
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ class LottieLoader
|
||||
{
|
||||
public:
|
||||
bool load(const std::string &filePath);
|
||||
bool loadFromData(std::string &&jsonData, const std::string &key);
|
||||
bool loadFromData(std::string &&jsonData, const std::string &key, const std::string &resourcePath);
|
||||
std::shared_ptr<LOTModel> model();
|
||||
private:
|
||||
std::shared_ptr<LOTModel> mModel;
|
||||
|
||||
@@ -25,7 +25,7 @@ class LottieParserImpl;
|
||||
class LottieParser {
|
||||
public:
|
||||
~LottieParser();
|
||||
LottieParser(char* str, const char *dir_path="");
|
||||
LottieParser(char* str, const char *dir_path);
|
||||
std::shared_ptr<LOTModel> model();
|
||||
private:
|
||||
LottieParserImpl *d;
|
||||
|
||||
Reference in New Issue
Block a user