daimajia / AndroidSwipeLayout

The Most Powerful Swipe Layout!
MIT License
12.37k stars 2.67k forks source link

Open not working with RecyclerView.Adapter #272

Open yamila-fraiman opened 8 years ago

yamila-fraiman commented 8 years ago

Hi, i want to open by default some rows from my RecyclerView.Adapter but is not working. Any idea? I tried postdelayed but didn't work for me.

IonutNegru87 commented 8 years ago

I have the same issue. I've made some debugging and from what I could understand the problem is in Rect computeSurfaceLayoutArea(boolean open) method. This is because at that point getMeasuredWidth() of Viewclass will return 0 which as a result will affect the forceSettleCapturedViewAt(int finalLeft, int finalTop, int xvel, int yvel) method of the ViewDragHelper which detects that it doesn't have to scroll anything.

Any solution for this?

IonutNegru87 commented 8 years ago

A quick fix for this is to use post() method on the view. I did something like this:

holder.swipeLayout.post(new Runnable() {
                @Override
                public void run() {
                    // We start the swipe tutorial only if the swipe is in a closed state
                    // If it is in a open state, it means the user already opened it and knows how to
                    if (holder.swipeLayout.getOpenStatus() == SwipeLayout.Status.Close) {
                        holder.swipeLayout.toggle();
                    }
                }
            });

Would be good if an optimization was done directly in the library to ensure the view is already measured when calling open,close,toggle,etc. methods.