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

Add show + hide functionality#86

Closed
ScottCooper92 wants to merge 2 commits intofacebookarchive:masterfrom
ScottCooper92:hide_show
Closed

Add show + hide functionality#86
ScottCooper92 wants to merge 2 commits intofacebookarchive:masterfrom
ScottCooper92:hide_show

Conversation

@ScottCooper92
Copy link
Copy Markdown
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.

}

/** Return whether the shimmer is visible **/
public boolean isShimmerVisible(){
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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);
}

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

@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
Copy Markdown

@xiphirx merged this pull request in 97ca4d1.

PoppyProses added a commit to PoppyProses/PoppyProses that referenced this pull request Aug 20, 2025
Summary:
PR for facebookarchive/shimmer-android#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: facebookarchive/shimmer-android#86

Differential Revision: D16053297

Pulled By: xiphirx

fbshipit-source-id: 9f50e1f56c1f2272fbb2da70dbea3680da6e03f1
FelixiReed added a commit to FelixiReed/monoap that referenced this pull request Sep 17, 2025
Summary:
PR for facebookarchive/shimmer-android#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: facebookarchive/shimmer-android#86

Differential Revision: D16053297

Pulled By: xiphirx

fbshipit-source-id: 9f50e1f56c1f2272fbb2da70dbea3680da6e03f1
overbomigu added a commit to overbomigu/imgur that referenced this pull request Nov 22, 2025
Summary:
PR for facebookarchive/shimmer-android#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: facebookarchive/shimmer-android#86

Differential Revision: D16053297

Pulled By: xiphirx

fbshipit-source-id: 9f50e1f56c1f2272fbb2da70dbea3680da6e03f1
AstarLighte added a commit to AstarLighte/mixdown that referenced this pull request Dec 16, 2025
Summary:
PR for facebookarchive/shimmer-android#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: facebookarchive/shimmer-android#86

Differential Revision: D16053297

Pulled By: xiphirx

fbshipit-source-id: 9f50e1f56c1f2272fbb2da70dbea3680da6e03f1
edsoftsae added a commit to edsoftsae/edsoftsae that referenced this pull request Jan 4, 2026
Summary:
PR for facebookarchive/shimmer-android#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: facebookarchive/shimmer-android#86

Differential Revision: D16053297

Pulled By: xiphirx

fbshipit-source-id: 9f50e1f56c1f2272fbb2da70dbea3680da6e03f1
owpdoeir added a commit to owpdoeir/mmap_ringbuffer that referenced this pull request Mar 27, 2026
Summary:
PR for facebookarchive/shimmer-android#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: facebookarchive/shimmer-android#86

Differential Revision: D16053297

Pulled By: xiphirx

fbshipit-source-id: 9f50e1f56c1f2272fbb2da70dbea3680da6e03f1
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