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

Commit

Permalink
Add show + hide functionality (#86)
Browse files Browse the repository at this point in the history
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
ScottCooper92 authored and facebook-github-bot committed Jun 28, 2019
1 parent cd1148d commit 97ca4d1
Showing 1 changed file with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class ShimmerFrameLayout extends FrameLayout {
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);
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit 97ca4d1

Please sign in to comment.