Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay setProgress(...) if animation is loading #8

Merged
merged 1 commit into from
Nov 9, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ public static LottieAnimationView forScreenshotTest(Context context) {

private final LongSparseArray<LayerView> layerMap = new LongSparseArray<>();
private final RootAnimatableLayer rootAnimatableLayer = new RootAnimatableLayer(this);
@FloatRange(from=0f, to=1f) private float progress;
private String animationName;
private boolean isScreenshotTest;
private boolean isAnimationLoading;
private boolean setProgressWhenCompositionSet;
private boolean playAnimationWhenCompositionSet;
@Nullable private AsyncTask fileToJsonTask;
@Nullable private AsyncTask jsonToCompositionTask;
Expand Down Expand Up @@ -193,6 +195,8 @@ public void recycleBitmaps() {
*/
public void setAnimation(final String animationName) {
isAnimationLoading = true;
setProgressWhenCompositionSet = false;
playAnimationWhenCompositionSet = false;

this.animationName = animationName;

Expand Down Expand Up @@ -295,6 +299,7 @@ private void setJsonSync(JSONObject json) {

private void onAnimationLoadingFail() {
isAnimationLoading = false;
setProgressWhenCompositionSet = false;
playAnimationWhenCompositionSet = false;
}

Expand All @@ -303,8 +308,16 @@ private void setComposition(@NonNull Composition composition) {
return;
}

isAnimationLoading = false;

clearComposition();
setProgress(0f);

if (setProgressWhenCompositionSet) {
setProgressWhenCompositionSet = false;
setProgress(progress);
} else {
setProgress(0f);
}

this.composition = composition;
rootAnimatableLayer.setCompDuration(composition.getDuration());
Expand All @@ -313,7 +326,6 @@ private void setComposition(@NonNull Composition composition) {
requestLayout();
setImageDrawable(rootAnimatableLayer);

isAnimationLoading = false;
if (playAnimationWhenCompositionSet) {
playAnimationWhenCompositionSet = false;
playAnimation();
Expand Down Expand Up @@ -405,11 +417,17 @@ public void playAnimation() {
}

public void cancelAnimation() {
setProgressWhenCompositionSet = false;
playAnimationWhenCompositionSet = false;
rootAnimatableLayer.cancelAnimation();
}

public void setProgress(@FloatRange(from=0f, to=1f) float progress) {
this.progress = progress;
if (isAnimationLoading) {
setProgressWhenCompositionSet = true;
return;
}
rootAnimatableLayer.setProgress(progress);
}

Expand Down