Skip to content
Permalink
Browse files

Add support for start delay in shimmer library. (#92)

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 901b641c4d3237f4131e58601976d9731b740f1f
@@ -78,6 +78,7 @@
int repeatMode = ValueAnimator.RESTART;
long animationDuration = 1000L;
long repeatDelay;
long startDelay;

Shimmer() {}

@@ -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);
@@ -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;
@@ -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) {
@@ -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);
@@ -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"/>

0 comments on commit 901b641

Please sign in to comment.
You can’t perform that action at this time.