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

Commit

Permalink
Add support for start delay in shimmer library. (#92)
Browse files Browse the repository at this point in the history
Summary:
Shimmer library right now only supports repeat delay but not start delay while ValueAnimator supports both. This is useful to stagger the shimmer animations in case there are multiple ShimmerFrameLayouts in a view.
Pull Request resolved: #92

Differential Revision: D18642161

Pulled By: xiphirx

fbshipit-source-id: d30e13194d27d7a12e6a01dc79b9f876679de8a4
  • Loading branch information
ankur2136 authored and facebook-github-bot committed Nov 21, 2019
1 parent 2636489 commit 901b641
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
17 changes: 16 additions & 1 deletion shimmer/src/main/java/com/facebook/shimmer/Shimmer.java
Expand Up @@ -78,6 +78,7 @@ public class Shimmer {
int repeatMode = ValueAnimator.RESTART;
long animationDuration = 1000L;
long repeatDelay;
long startDelay;

Shimmer() {}

Expand Down Expand Up @@ -179,7 +180,11 @@ T consumeAttributes(TypedArray a) {
setRepeatMode(
a.getInt(R.styleable.ShimmerFrameLayout_shimmer_repeat_mode, mShimmer.repeatMode));
}

if (a.hasValue(R.styleable.ShimmerFrameLayout_shimmer_start_delay)) {
setStartDelay(
a.getInt(
R.styleable.ShimmerFrameLayout_shimmer_start_delay, (int) mShimmer.startDelay));
}
if (a.hasValue(R.styleable.ShimmerFrameLayout_shimmer_direction)) {
int direction =
a.getInt(R.styleable.ShimmerFrameLayout_shimmer_direction, mShimmer.direction);
Expand Down Expand Up @@ -260,6 +265,7 @@ public T copyFrom(Shimmer other) {
setRepeatCount(other.repeatCount);
setRepeatMode(other.repeatMode);
setRepeatDelay(other.repeatDelay);
setStartDelay(other.startDelay);
setDuration(other.animationDuration);
mShimmer.baseColor = other.baseColor;
mShimmer.highlightColor = other.highlightColor;
Expand Down Expand Up @@ -399,6 +405,15 @@ public T setRepeatDelay(long millis) {
return getThis();
}

/** Sets how long to wait for starting the shimmering animation. */
public T setStartDelay(long millis) {
if (millis < 0) {
throw new IllegalArgumentException("Given a negative start delay: " + millis);
}
mShimmer.startDelay = millis;
return getThis();
}

/** Sets how long the shimmering animation takes to do one full sweep. */
public T setDuration(long millis) {
if (millis < 0) {
Expand Down
Expand Up @@ -163,6 +163,7 @@ private void updateValueAnimator() {
mValueAnimator =
ValueAnimator.ofFloat(0f, 1f + (float) (mShimmer.repeatDelay / mShimmer.animationDuration));
mValueAnimator.setRepeatMode(mShimmer.repeatMode);
mValueAnimator.setStartDelay(mShimmer.startDelay);
mValueAnimator.setRepeatCount(mShimmer.repeatCount);
mValueAnimator.setDuration(mShimmer.animationDuration + mShimmer.repeatDelay);
mValueAnimator.addUpdateListener(mUpdateListener);
Expand Down
1 change: 1 addition & 0 deletions shimmer/src/main/res/values/attrs.xml
Expand Up @@ -15,6 +15,7 @@
<enum name="restart" value="1"/>
<enum name="reverse" value="2"/>
</attr>
<attr name="shimmer_start_delay" format="integer"/>
<attr name="shimmer_direction" format="enum">
<enum name="left_to_right" value="0"/>
<enum name="top_to_bottom" value="1"/>
Expand Down

0 comments on commit 901b641

Please sign in to comment.