Skip to content
Permalink
Browse files

Add show + hide functionality (#86)

Summary:
PR for #85

It doesn't seem like the best implementation since I'm just nulling the Shimmer but it does the job.

I've tested this in the sample app by depending on the library project rather than the snapshot and added another button for toggling it on and off but haven't included any of that in this PR. If you would like me to I'll update it.
Pull Request resolved: #86

Differential Revision: D16053297

Pulled By: xiphirx

fbshipit-source-id: 9f50e1f56c1f2272fbb2da70dbea3680da6e03f1
  • Loading branch information...
Glurt authored and facebook-github-bot committed Jun 28, 2019
1 parent cd1148d commit 97ca4d1d7cd1ec4e3435ee46a1748da00aa0511e
Showing with 35 additions and 1 deletion.
  1. +35 −1 shimmer/src/main/java/com/facebook/shimmer/ShimmerFrameLayout.java
@@ -30,6 +30,8 @@
private final Paint mContentPaint = new Paint();
private final ShimmerDrawable mShimmerDrawable = new ShimmerDrawable();

private boolean mShowShimmer = true;

public ShimmerFrameLayout(Context context) {
super(context);
init(context, null);
@@ -100,6 +102,36 @@ public boolean isShimmerStarted() {
return mShimmerDrawable.isShimmerStarted();
}

/**
* Sets the ShimmerDrawable to be visible.
* @param startShimmer Whether to start the shimmer again.
*/
public void showShimmer(boolean startShimmer) {
if (mShowShimmer) {
return;
}
mShowShimmer = true;
if (startShimmer) {
startShimmer();
}
}

/** Sets the ShimmerDrawable to be invisible, stopping it in the process. */
public void hideShimmer() {
if (!mShowShimmer) {
return;
}

stopShimmer();
mShowShimmer = false;
invalidate();
}

/** Return whether the shimmer drawable is visible. */
public boolean isShimmerVisible() {
return mShowShimmer;
}

@Override
public void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
@@ -123,7 +155,9 @@ public void onDetachedFromWindow() {
@Override
public void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
mShimmerDrawable.draw(canvas);
if (mShowShimmer) {
mShimmerDrawable.draw(canvas);
}
}

@Override

0 comments on commit 97ca4d1

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