Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

listen animation state #97

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package com.facebook.shimmer;

import android.animation.Animator;
import android.animation.ValueAnimator;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
Expand Down Expand Up @@ -63,7 +64,15 @@ public void setShimmer(@Nullable Shimmer shimmer) {

/** Starts the shimmer animation. */
public void startShimmer() {
startShimmer(null);
}

/** Starts the shimmer animation with animation listener. */
public void startShimmer(Animator.AnimatorListener listener) {
if (mValueAnimator != null && !isShimmerStarted() && getCallback() != null) {
if (listener != null) {
mValueAnimator.addListener(listener);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're adding a listener here but never removing it, you should also removeAllListeners on line 171

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also should be removed in stopShimmer, otherwise starting and stopping will constantly accumulate new listeners

}
mValueAnimator.start();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package com.facebook.shimmer;

import android.animation.Animator;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
Expand Down Expand Up @@ -94,7 +95,12 @@ public ShimmerFrameLayout setShimmer(@Nullable Shimmer shimmer) {

/** Starts the shimmer animation. */
public void startShimmer() {
mShimmerDrawable.startShimmer();
startShimmer(null);
}

/** Starts the shimmer animation with animation listener. */
public void startShimmer(Animator.AnimatorListener listener) {
mShimmerDrawable.startShimmer(listener);
}

/** Stops the shimmer animation. */
Expand Down