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

startShimmer() and stopShimmer() are not starting or stopping the animation view #61

Closed
ugokoli opened this issue Jul 25, 2018 · 12 comments

Comments

@ugokoli
Copy link

ugokoli commented Jul 25, 2018

I have implemented the library, but this two scenarios are happening;
First, when the view comes up the shimmer animation starts automatically, but when I call mShimmerFrameLayout.stopShimmer() it does not stop it.
Secondly, when autoStart is disabled in the layout attribute and the view comes up, if I call mShimmerFrameLayout.startShimmer(), it does not start the animation.

Please a solution is needed.

@xiphirx
Copy link
Contributor

xiphirx commented Jul 26, 2018

I just tested this in the sample app and the library is functioning correctly. Please attach a project reproducing the error.

@AlexanderEggers
Copy link

@xiphirx I have the same problem. When I call stopShimmer on my given ShimmerFrameLayout, the shimmer animation is not stopping. Internally it is calling the value animator cancel method, but it is still not stopping the animation.

The library seems to have a problem with the internal state of the ShimmerFrameLayout because it actually does not matter if I call startShimmer/stopShimmer on the view. The animation will always be executed. I tested this by simply creating a new project and including the relevant ShimmerFrameLayout without calling any methods.

Here is a snippet of my code:

@JvmStatic
@BindingAdapter("image")
fun setImage(view: ImageView, imageUrl: String?) {
            imageUrl?.run {
                (view.parent as? ShimmerFrameLayout)?.startShimmer()

                var requestOptions = RequestOptions()
                requestOptions = requestOptions.transforms(CenterCrop(), RoundedCorners(2))

                GlideApp.with(view)
                        .load(imageUrl)
                        .centerCrop()
                        .placeholder(R.drawable.preview_panel_loading_image)
                        .apply(requestOptions)
                        .listener(object: RequestListener<Drawable> {

                            override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
                                (view.parent as? ShimmerFrameLayout)?.stopShimmer()
                                return false
                            }

                            override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean {
                                (view.parent as? ShimmerFrameLayout)?.stopShimmer()
                                return false
                            }
                        })
                        .into(view)
            }
        }

@xiphirx
Copy link
Contributor

xiphirx commented Jul 30, 2018

It starts automatically when not calling anything because auto start is true by default. Can you verify that view.parent is actually a ShimmerFrameLayout? I cannot reproduce the same behavior in the sample app. You may also want to just use ShimmerDrawable directly as Glide's placeholder since its an ImageView.

@AlexanderEggers
Copy link

AlexanderEggers commented Jul 30, 2018

I just found out that the library is using custom layout parameter for the ShimmerFrameLayout. After setting the value, I was able to disable the auto start behaviour and use the methods instead. You should update the documentation to include this behaviour. Currently that is something that wasn't clear to me at the beginning. I expected that auto_start is false by default (especially due to your example that showed "how to start the shimmer animation".

Regarding the ShimmerDrawable, how I can I use that as a placeholder inside glide. I cannot find any reference to this drawable.

@xiphirx
Copy link
Contributor

xiphirx commented Jul 31, 2018

You can use ShimmerDrawable like any other drawable and set the same Shimmer object on it. In fact, ShimmerFrameLayout is just a thin wrapper that just delegates to ShimmerDrawable.

I'd imagine you could do something like

Shimmer shimmer = Shimmer...;
ShimmerDrawable d = new ShimmerDrawable();
d.setShimmer(shimmer);

GlideApp.with(view).load(imageUrl).placeholder(d)...

I'll look into updating the docs to be clear-er, thanks.

@xiphirx xiphirx closed this as completed Jul 31, 2018
@AlexanderEggers
Copy link

@xiphirx Thanks for your answer. As I wrote in my last reply, there's no available reference to ShimmerDrawable in the library (at least Android Studio cannot find this class). Are you certain that the version 0.2 is including this object?

@xiphirx
Copy link
Contributor

xiphirx commented Jul 31, 2018

Oh sorry, it's going to be in the next version. I should probably cut a new release soon

@AlexanderEggers
Copy link

AlexanderEggers commented Jul 31, 2018

@xiphirx When are you planning to do that? Sometime next week or later?

@ugokoli
Copy link
Author

ugokoli commented Aug 1, 2018

Yes please, I am also waiting for the next version soon, I hope it will address all these problems. Thanks

@xiphirx
Copy link
Contributor

xiphirx commented Aug 1, 2018

bdfacea

@AlexanderEggers
Copy link

AlexanderEggers commented Aug 2, 2018

@xiphirx Thanks for the new version! :)

@i-m-aman
Copy link

How to make the ShimmerDrawable rounded? I cannot change the color of the shimmer drawable.

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

No branches or pull requests

4 participants