Skip to content

Commit

Permalink
fix(lottie): Improved the loadeability of Lottie library on Wasm when…
Browse files Browse the repository at this point in the history
… running in _Embedded_ context.
  • Loading branch information
carldebilly committed May 23, 2023
1 parent 4a994cd commit 685ba37
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/AddIns/Uno.UI.Lottie/WasmScripts/uno-lottie.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare const require: any;
declare const require: unknown | undefined;
declare const config: any;
declare namespace Uno.UI {
import AnimationData = Lottie.AnimationData;
Expand Down
14 changes: 12 additions & 2 deletions src/AddIns/Uno.UI.Lottie/WasmScripts/uno-lottie.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var Uno;
static setProgress(elementId, progress) {
Lottie.withPlayer(p => {
const animation = Lottie._runningAnimations[elementId].animation;
var frame = Lottie._numberOfFrames * progress;
let frame = Lottie._numberOfFrames * progress;
if (frame < animation.firstFrame) {
frame = frame - animation.firstFrame;
}
Expand Down Expand Up @@ -194,7 +194,17 @@ var Uno;
action(Lottie._player);
}
else {
require([`${config.uno_app_base}/lottie`], (p) => {
if (typeof require !== "function") {
console.error("RequireJS not present.");
return;
}
const dependencyToLoad = "/lottie";
const lottieDependencyName = config.uno_dependencies.find((d) => d.endsWith(dependencyToLoad));
require([lottieDependencyName], (p) => {
if (!p) {
console.error("Unable to load lottie player.");
return;
}
if (!Lottie._player) {
Lottie._player = p;
}
Expand Down
17 changes: 14 additions & 3 deletions src/AddIns/Uno.UI.Lottie/ts/Uno.UI.Lottie.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare const require: any;
declare const require: unknown | undefined;
declare const config: any;

namespace Uno.UI {
Expand Down Expand Up @@ -102,7 +102,7 @@ namespace Uno.UI {
public static setProgress(elementId: number, progress: number): string {
Lottie.withPlayer(p => {
const animation = Lottie._runningAnimations[elementId].animation;
var frame = Lottie._numberOfFrames * progress;
let frame = Lottie._numberOfFrames * progress;
if (frame < (animation as any).firstFrame) {
frame = frame - (animation as any).firstFrame
} else {
Expand Down Expand Up @@ -266,7 +266,18 @@ namespace Uno.UI {
if (Lottie._player) {
action(Lottie._player);
} else {
require([`${config.uno_app_base}/lottie`], (p: LottiePlayer) => {
if (typeof require !== "function") {
console.error("RequireJS not present.");
return;
}

const dependencyToLoad = "/lottie";
const lottieDependencyName = config.uno_dependencies.find((d: string) => d.endsWith(dependencyToLoad));
require([lottieDependencyName], (p: LottiePlayer) => {
if(!p) {
console.error("Unable to load lottie player.");
return;
}
if (!Lottie._player) {
Lottie._player = p;
}
Expand Down

0 comments on commit 685ba37

Please sign in to comment.