yayaa/ParallaxRecyclerView

Images via Picasso do not show until user has scrolled?

MiralDesai opened this issue · 6 comments

Seem to be getting a bug where the images do no appear until you scroll. The image is loaded, but the row in the RecyclerView will remain empty until I scroll down. When I scroll up, the image does not load, I have to scroll down for the next images to appear. When I do, they appear immediately.

Do you have any idea why this might be the case? One the image is displayed, Parallax and everything else is fine, it just seems to holding onto the image and not displaying until I scroll down which is a bit strange.

yayaa commented

Can you check with sample application and confirm that you receive same issue? Because that is also using Picasso, so we can narrow down the problem here.

Same here, but it only happens with the first position. Let me know if you need more details for this. Thanks!

I edited this method in ParallaxRecyclerView:

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);

            LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
            int firstVisiblePosition = layoutManager.findFirstVisibleItemPosition();
            int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition();

            for (int i = firstVisiblePosition; i <= lastVisibleItemPosition; i++) {
                ViewHolder viewHolder = recyclerView.findViewHolderForAdapterPosition(i);
                if (viewHolder instanceof ParallaxViewHolder) {
                    ParallaxViewHolder childViewHolder = (ParallaxViewHolder) viewHolder;
                    childViewHolder.animateImage();
                }
            }

            if (scrollListener != null)
                scrollListener.onScrolled(recyclerView, dx, dy);
        }

(note that I'm using a sectioned list with headers, that's the reason for the instanceof)

If I have time tomorrow I'll look into this!

OK I've had some time to look into this. I was able to replicate this in the sample application by adding a placeholder to Picasso.

Is there a way we can handle placeholders?

Edit: Nevermind might have solved it with an implementation change, will investigate.

`Picasso.with(context).load(imageUrls[position % imageUrls.length]).tag(context).placeholder(android.R.color.holo_red_dark).into(viewHolder.getBackgroundImage(), new Callback() {
        @Override
        public void onSuccess() {
            viewHolder.getBackgroundImage().reuse();
        }

        @Override
        public void onError() {

        }
    });`

Setting a callback has solved the issue. Placeholder and image load fine.

Sorry, I was without Internet for a week. Glad you could solve it, and thanks!