facebookarchive / shimmer-android

An easy, flexible way to add a shimmering effect to any view in an Android app.
http://facebook.github.io/shimmer-android/
Other
5.31k stars 698 forks source link

Clear Shimmer #64

Closed zsweigart closed 5 years ago

zsweigart commented 6 years ago

I have an image view inside a shimmer frame layout, when load an image into the image view I want to clear the shimmer entirely but there is no way to do this. If I stop the shimmer there is still an overlay over my image view.

xiphirx commented 6 years ago

Do you need to have the image inside of the ShimmerFrameLayout ? Could you instead just hide the ShimmerFrameLayout when you're done loading your image?

zsweigart commented 6 years ago

Shouldn't the ShimmerFrameLayout contain the views? Or are you thinking of using RelativeLayout or FrameLayout parent view group that holds the shimmer and the image view and overlays them?

I was also able to achieve clearing by doing this:

shimmerFrameLayout.setShimmer(
  new Shimmer.AlphaHighlightBuilder()
    .setBaseAlpha(1)
    .setIntensity(0)
    .build());
shimmerFrameLayout.stopShimmer();
shimmerFrameLayout.clearAnimation();

But it's pretty ugly

xiphirx commented 6 years ago

Typically you have a "dummy" view inside of ShimmerFrameLayout that takes the form of the content you expect to be shown. When your content is ready you remove the ShimmerFrameLayout + the "dummy" view and show your loaded content.

zsweigart commented 6 years ago

Interesting, I can give that a shot. I think this would be a nice enhancement to the API though. I'm using Picasso to load an image into my image view so it shimmers while the call is being made over the placeholder image. Then when the callback is either successful or a failure I clear the shimmer and show the image or the error image.

xiphirx commented 6 years ago

The appropriate use there would be to use a ShimmerDrawable directly as the placeholder for Picasso while the image loads.

DamonBaker commented 6 years ago

This used to be the case in 0.1.0 where calling stopShimmerAnimation() would remove the overlay completely. This was useful when there is content already on the screen which is being "reloaded", or the user performs an action that requires additional loading. In cases like this I don't want to replace preexisting content with a dummy view.

xiphirx commented 5 years ago

It seems like a good compromise is letting users call setShimmer(null) to remove the shimmer. I can make that change.

xiphirx commented 5 years ago

e7a2129f79a6d2c76fceddaf1a8c401e30b4f5b8

JayyyR commented 5 years ago

@xiphirx any word on release with this change?

xiphirx commented 5 years ago

0.4.0 was just pushed to sonatype.

mochadwi commented 5 years ago

Shouldn't the ShimmerFrameLayout contain the views? Or are you thinking of using RelativeLayout or FrameLayout parent view group that holds the shimmer and the image view and overlays them?

I was also able to achieve clearing by doing this:

shimmerFrameLayout.setShimmer(
  new Shimmer.AlphaHighlightBuilder()
    .setBaseAlpha(1)
    .setIntensity(0)
    .build());
shimmerFrameLayout.stopShimmer();
shimmerFrameLayout.clearAnimation();

But it's pretty ugly

Nice workaround, also using setShimmer(null) much cleaner~

rfogar2 commented 5 years ago

Old issue, but what if you want to remove the shimmer and then show it later, e.g. refreshing a page? Does setShimmer(null) mean you will have to rebuild the Shimmer instance from scratch?

xiphirx commented 5 years ago

You can use the new show/hide methods https://github.com/facebook/shimmer-android/commit/97ca4d1d7cd1ec4e3435ee46a1748da00aa0511e

rfogar2 commented 5 years ago

@xiphirx Can you cut a new release?

xiphirx commented 5 years ago

https://github.com/facebook/shimmer-android/releases/tag/0.5.0

Give it a few minutes to propagate to maven central

ghost commented 5 years ago

When I am using shimmer.stopShimmer(); my app is force stoped. shimmer is working in loop on my project.

How can i stop it.

Shamivul commented 4 years ago

what happens to shimmer when onDestroy() is called after starting the animation? deos it destroy itself or does it need to be handled manually

warrior1112 commented 3 years ago

You can use the new show/hide methods 97ca4d1

thank you so much ! it helped.

Piyush0912 commented 1 year ago

Shouldn't the ShimmerFrameLayout contain the views? Or are you thinking of using RelativeLayout or FrameLayout parent view group that holds the shimmer and the image view and overlays them?

I was also able to achieve clearing by doing this:

shimmerFrameLayout.setShimmer(
  new Shimmer.AlphaHighlightBuilder()
    .setBaseAlpha(1)
    .setIntensity(0)
    .build());
shimmerFrameLayout.stopShimmer();
shimmerFrameLayout.clearAnimation();

But it's pretty ugly

where we use this code and what we write inside .placeholder in glide library