daimajia / AndroidSwipeLayout

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

Added function to manually reset offsets of bottomview #190

Open PulfordJ opened 9 years ago

PulfordJ commented 9 years ago

Using

swipeLayout.close(true, true); 

doesn't appear to guarantee this. I suspect the library assumes the user is manually closing the view and doesn't upset the offset in all or some cases. Adding manual resetting of offset allowed the use of Google Inbox like swipe-to-delete functionality:

Example listener with the new function:

  swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() {

            public void onStartOpen(SwipeLayout swipeLayout) {

            }

            @Override
            public void onOpen(SwipeLayout swipeLayout) {

            }

            @Override
            public void onStartClose(SwipeLayout swipeLayout) {

            }

            @Override
            public void onClose(SwipeLayout swipeLayout) {

            }

            @Override
            public void onUpdate(SwipeLayout swipeLayout, int i, int i2) {

            }

            @Override
            public void onHandRelease(SwipeLayout swipeLayout, float xvel, float yvel) {

                //If item is fully open commence delete action.
                if (swipeLayout.getOpenStatus().equals(SwipeLayout.Status.Open)) {
                    Toast.makeText(context, "Item deleted", Toast.LENGTH_SHORT).show();
                   //Action to remove item here.
                }
                //If it is half open then close item, we don't want to delete unless the user
                //scrolls all the way.
                else if (swipeLayout.getOpenStatus().equals(SwipeLayout.Status.Middle)){
                    swipeLayout.close(true, true);
                    //Use resetOffsets to prevent bug
                    // where bottomView scrolls across the item
                    // more and more
                    // on each half-open-release event
                    swipeLayout.resetOffsets();

                }
            }
        });

Of course if you have any idea how to duplicate this functionality without exposing the extra function then go for it or I can do it with guidance/time. I would have attempted this but I think it would have risked bugging out the "smooth" close function parameter .