Allow loading lottie animations from memory.

This commit is contained in:
John Preston 2019-05-10 18:47:48 +03:00
parent 707aa88974
commit 642deecbbb
3 changed files with 14 additions and 5 deletions

View file

@ -94,10 +94,14 @@ QSize HistorySticker::countCurrentSize(int newWidth) {
}
void HistorySticker::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const {
if (!_lottie
&& _data->loaded()
&& Lottie::ValidateFile(_data->filepath())) {
_lottie = Lottie::FromFile(_data->filepath());
if (!_lottie && _data->filename().endsWith(qstr(".json"))) {
if (_data->loaded()) {
_lottie = _data->data().isEmpty()
? Lottie::FromFile(_data->filepath())
: Lottie::FromData(_data->data());
} else {
_data->automaticLoad(_parent->data()->fullId(), _parent->data());
}
}
auto sticker = _data->sticker();

View file

@ -51,7 +51,11 @@ std::unique_ptr<Animation> FromFile(const QString &path) {
if (content.isEmpty()) {
return nullptr;
}
return std::make_unique<Lottie::Animation>(content);
return FromData(content);
}
std::unique_ptr<Animation> FromData(const QByteArray &data) {
return std::make_unique<Lottie::Animation>(data);
}
Animation::Animation(const QByteArray &content) {

View file

@ -25,6 +25,7 @@ class Animation;
bool ValidateFile(const QString &path);
std::unique_ptr<Animation> FromFile(const QString &path);
std::unique_ptr<Animation> FromData(const QByteArray &data);
struct PlaybackOptions {
float64 speed = 1.;