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

Add show + hide functionality #86

Closed
wants to merge 2 commits into from
Closed

Add show + hide functionality #86

wants to merge 2 commits into from

Conversation

ScottCooper92
Copy link
Contributor

@ScottCooper92 ScottCooper92 commented Jun 27, 2019

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.

@@ -75,6 +75,11 @@ public boolean isShimmerStarted() {
return mValueAnimator != null && mValueAnimator.isStarted();
}

/** Return whether the shimmer is visible **/
public boolean isShimmerVisible(){
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think is necessary to achieve the functionality desired. See below comments.

* Sets the ShimmerDrawable to be visible.
* @param startShimmer Whether to start the shimmer again.
*/
public void showShimmer(boolean startShimmer) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Show / hide should be pretty simple and self sufficient within this class.

If we call showShimmer then it should simply set a boolean and start the shimmer if needed:

public void showShimmer() {
  if (mShowShimmer) {
    return;
  }
  mShowShimmer = true;
  if (startShimmer) {
    startShimmer();
  }
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Then in dispatchDraw we can just check to see if we want to show it.

if (mShowShimmer) {
  mShimmerDrawable.draw(canvas);
}

@@ -29,6 +29,7 @@
public class ShimmerFrameLayout extends FrameLayout {
private final Paint mContentPaint = new Paint();
private final ShimmerDrawable mShimmerDrawable = new ShimmerDrawable();
private Shimmer mShimmer = new Shimmer.AlphaHighlightBuilder().build();
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of this we should just have a simple boolean that denotes whether we should show the shimmer or not.

/** Sets the ShimmerDrawable to be invisible, stopping it in the process. */
public void hideShimmer() {
stopShimmer();
updateShimmerDrawable(null);
Copy link
Contributor

Choose a reason for hiding this comment

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

This should just set the boolean to false

@ScottCooper92
Copy link
Contributor Author

I knew there would be an easier way to do it, I don't have a great deal of experience with custom drawables though.

Show + hide now stop and start the ShimmerDrawable respectively and boolean gate the call to mShimmerDrawable.draw(canvas); as suggested. Interestingly if the shimmer is stopped, then we end up with the same problem of it still being visible, which is why the invalidate() call is necessary, again if there's a better way of doing this let me know.

Copy link
Contributor

@xiphirx xiphirx left a comment

Choose a reason for hiding this comment

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

Awesome, thank you!

Copy link

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@xiphirx is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link

@xiphirx merged this pull request in 97ca4d1.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants