daimajia / AndroidSwipeLayout

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

Only works correctly with fling and not with swipe #344

Open curliq opened 8 years ago

curliq commented 8 years ago

First I must say that I love the library, This is probably not a bug, but my poor implementation. When I scroll to show the bottomView it doesn't show right away, it only shows after I release the screen, and when i want to close, it only closes when I fling it, if I scroll it behaves weirdly and doesn't close, here's my code:

<?xml version="1.0" encoding="utf-8"?>
<com.daimajia.swipe.SwipeLayout
    android:id="@+id/notas_swipeLayout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="#ffffff"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <!-- Bottom view -->
    <LinearLayout
        android:id="@+id/notas_bottomView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:layout_gravity="end">

        <ImageButton
            android:id="@+id/nota_bottomView_delete"
            android:layout_width="60dp"
            android:layout_height="match_parent"
            android:background="#2e2e2e"
            android:src="@drawable/delete_white"
            />

    </LinearLayout>

    <!-- Top view -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:animateLayoutChanges="true"
        android:orientation="horizontal">

        <m.inschool8.Objects.SmoothCheckBox
            android:id="@+id/results_smoothCheckBox"
            android:layout_width="30dp"
            android:layout_height="30dp"
            app:duration="100"
            android:visibility="gone"
            android:layout_marginLeft="20dp"
            android:layout_marginStart="20dp"
            android:clickable="false"
            app:stroke_width="1dp"
            android:layout_gravity="center_vertical"/>

        <TextView
            android:id="@+id/grades_subject_info_result"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#212121"
            android:textSize="18sp"
            />

    </LinearLayout>

</com.daimajia.swipe.SwipeLayout>
     public class NotaAdapter extends RecyclerSwipeAdapter<NotaAdapter.NotaViewHolder> {

        public Context mContext;
        public ArrayList<String> mResultArray;
        public SwipeItemRecyclerMangerImpl mItemManger = new SwipeItemRecyclerMangerImpl(this);

        public NotaAdapter(Context context, ArrayList<String> results) {
            this.mContext = context;
            this.mResultArray = results;

        }

        @Override
        public NotaViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.nota_adapter_view, parent, false);
            return new NotaViewHolder(view);
        }

        @Override
        public void onBindViewHolder(final NotaViewHolder viewHolder, final int position) {
            viewHolder.swipeLayout.setShowMode(SwipeLayout.ShowMode.PullOut);

            viewHolder.buttonDelete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    //some stuff
                }
            });

            mItemManger.bindView(viewHolder.itemView, position);
        }

        @Override
        public int getItemCount() {
            return mResultArray.size();
        }

        @Override
        public int getSwipeLayoutResourceId(int position) {
            return R.id.notas_swipeLayout;
        }

        @Override
        public int getItemViewType(int position) {
            if (position == mResultArray.size()) return 3;
            else return 2;
        }

        public class NotaViewHolder extends RecyclerView.ViewHolder {
            SwipeLayout swipeLayout;

            public NotaViewHolder(final View itemView) {
                super(itemView);
                swipeLayout = (SwipeLayout) itemView.findViewById(R.id.notas_swipeLayout);

                swipeLayout.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                       //some stuff
                    }
                });

            }
        }
    }
}
Sirelon commented 7 years ago

The same bug was when I use requestLayout() for the bottom view. Make sure, that you don't change size of view during swipe. 'Cause, as I see, the SwipeLayout invoke method layout for each bottom views when you swiping.