daimajia / AndroidSwipeLayout

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

When I open swipelayout it immediately closes #297

Open coralinejones1985 opened 8 years ago

coralinejones1985 commented 8 years ago

I also tried your demo, which has the same bug.

fahadhaq commented 8 years ago

is this fix available on the maven repo?

coralinejones1985 commented 8 years ago

No, it fixed only in my fork.

devilabhi commented 8 years ago

Even am facing this issue... I have swipeable RecyclerView having buttons. In some of the devices as I swipe from Right to left and as buttons gets visible, it automatically closes the expandable view.

Any help could be appreciated Thanks

ThijsmvSchaik commented 8 years ago

@devilabhi You have to add a SwipeListener and a GlobalLayoutListener to your SwipeLayout Add an GlobalLayoutListener to your swipeLayout and keep a variable with the value isOpening> Example

swipeLayout.addSwipeListener(new SimpleSwipeListener() {
        @Override
        public void onStartOpen(SwipeLayout layout) {
            isOpenSwipeLayout = true;
        }

        @Override
        public void onStartClose(SwipeLayout layout) {
            isOpenSwipeLayout = false;
        }
    });

    swipeGlobalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (isOpenSwipeLayout) {
                // Opens the layout without animation
                swipeLayout.open(false);
            }
        }
    };

swipeLayout.getViewTreeObserver().addOnGlobalLayoutListener(swipeGlobalLayoutListener);
pranishres commented 7 years ago

@ThijsmvSchaik 's implementation helped me to solve the issue. Here is the full implementation on ViewHolder class. Hope this helps.

    @BindView(R.id.swpMyVehicleList)
    SwipeLayout swipeLayout;

    public TestViewHolder(View itemView) {
        super(itemView);
        ButterKnife.bind(this, itemView);

        final boolean[] isOpenSwipeLayout = {false};
        swipeLayout.addSwipeListener(new SimpleSwipeListener() {

            @Override
            public void onStartOpen(SwipeLayout layout) {
                isOpenSwipeLayout[0] = true;
            }

            @Override
            public void onStartClose(SwipeLayout layout) {
                isOpenSwipeLayout[0] = false;
            }
        });

        ViewTreeObserver.OnGlobalLayoutListener swipeGlobalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                if (isOpenSwipeLayout[0]) {
                    // Opens the layout without animation
                    swipeLayout.open(false);
                }
            }
        };

        swipeLayout.getViewTreeObserver().addOnGlobalLayoutListener(swipeGlobalLayoutListener);
    }