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.32k stars 697 forks source link

Shimmer Getting Stopped Inside RecyclerView When Scrolling #42

Closed thatsenam closed 6 years ago

thatsenam commented 6 years ago

Hello, Shimmer works like a charm in my project but there's a little problem. as i am using shimmer inside my recyclerview its getting stopped animating when i scrolled :(

A simple video of that problem -> Video_Of_Stopping Shimmer [20 Sec]

Note: I applied shimmer in nested recyclerview. Here's my snippet(for simplicity i just added meaningful code).

Inside MyAdapter

public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
......................................
 switch (holder.getItemViewType()) {
 case ViewType.LATEST_MOVIE:
                final LatestMovieViewHolder latestMovieViewHolder = (LatestMovieViewHolder) holder;
                latestMovieViewHolder.titleMovie.setText("Latest Movie");
                latestMovieViewHolder.shimmerFrameLayout.setVisibility(View.VISIBLE);
                latestMovieViewHolder.shimmerFrameLayout.startShimmerAnimation();
                latestMovieViewHolder.sectionRecylerView.setLayoutManager(new LinearLayoutManager(context, OrientationHelper.HORIZONTAL, false));
                latestMovieViewHolder.sectionRecylerView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
                RetrofitRequestAPI retrofitRequestAPI = MyRetrofit.getRetrofitInstance().create(RetrofitRequestAPI.class);
                Call<List<Movie>> requestObject = retrofitRequestAPI.getMoviesInTheater();
                requestObject.enqueue(new Callback<List<Movie>>() {
                    @Override
                    public void onResponse(Call<List<Movie>> call, Response<List<Movie>> response) {
                        if (response.body() != null) {
                            latestMovieViewHolder.shimmerFrameLayout.stopShimmerAnimation();
                            latestMovieViewHolder.sectionRecylerView.setVisibility(View.VISIBLE);
                            latestMovieViewHolder.shimmerFrameLayout.setVisibility(View.GONE);
                            latestMovieViewHolder.sectionRecylerView.setAdapter(new SectionAdapter(context, response.body()));
                        }
                    }

                    @Override
                    public void onFailure(Call<List<Movie>> call, Throwable t) {
                        Toast.makeText(context, t.getMessage(), Toast.LENGTH_LONG).show();
                    }
                });
                break;
............................`

**And here XML** 

`
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    <!--------------------other staff>

    <com.facebook.shimmer.ShimmerFrameLayout
        android:id="@+id/shimmerView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="gone">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <include layout="@layout/recyler_view_shimmer" />
            <include layout="@layout/recyler_view_shimmer" />
            <include layout="@layout/recyler_view_shimmer" />
        </LinearLayout>
    </com.facebook.shimmer.ShimmerFrameLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/singleSectionRecylerView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>
LutfiTekin commented 6 years ago

Maybe you should freeze recyclerview until your data loaded. Call setLayoutFrozen(true)

xiphirx commented 6 years ago

I'm not immediately sure what is going wrong from a first glance. The project was recently rewritten entirely so it's likely that this issue may not exist with the new version. I'll look into releasing it soon.

thatsenam commented 6 years ago

@xiphirx When the newer version will be released??

xiphirx commented 6 years ago

0.2.0 was just uploaded to sonatype, it will take a bit to propagate to jcenter/maven central.

MiriamCordes commented 6 years ago

Still not working for me (even with version 0.2.0) @xiphirx

xiphirx commented 6 years ago

Please open a new issue with code that reproduces the issue.

MiriamCordes commented 6 years ago

@xiphirx I found the solution to my problem, thanks for answering so quickly though :)

deshario commented 6 years ago

@MiriamCordes Can u share your code so it will be helpful for others too.