Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Slidr and ViewPager conflict #62

Open
2hamed opened this issue Mar 30, 2018 · 3 comments
Open

Slidr and ViewPager conflict #62

2hamed opened this issue Mar 30, 2018 · 3 comments

Comments

@2hamed
Copy link

2hamed commented Mar 30, 2018

Hi there,

There is a problem with using Slidr with a ViewPager in which Slidr intercepts touch events from ViewPager making it impossible for ViewPager to swipe left.

Slidr should consider the ViewPager and lock the dragging when the ViewPager is not at its first page.

@GGLabCenter
Copy link
Contributor

GGLabCenter commented Apr 11, 2018

Hello,
this is how I solved this problem (it's working):

viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                if(position == 1)
                    enableSliding(false);
                else 
                    enableSliding(true);
            }
            @Override
            public void onPageSelected(int position) {
                if(position == 1)
                    enableSliding(false);
                else 
                    enableSliding(true);
            }
            @Override
            public void onPageScrollStateChanged(int state) {
            }
        });

public void enableSliding(boolean enable){
        if (enable)
            slidrInterface.unlock();
        else
            slidrInterface.lock();
    }

slidrInterface is the interface obtained from the method of the library. This is how I use it with two tabs of a tablayout + viewpager. All perfectly working. If you have morethan two tabs you have only to do some little edit with the position variable.

@2hamed
Copy link
Author

2hamed commented Apr 13, 2018

@GGLabCenter What about nested ViewPagers or ViewPagers inside fragments or horizontal RecyclerViews.
I suspect this problem has to be solved at the library level. For example one should do a view traversal inside tryCaptureView and check if there is any horizontally scrollable view inside the sliding parent.

@GGLabCenter
Copy link
Contributor

Hello @2hamed ,
nested viewpagers: you should look for some function available to set the listening view (child/parent) from the user. Then it's the same code as above;

viewpagers inside fragments: same code as above, i used also in this way. the viewpager in fact is a statefragmentpageradapter that shows the current fragment, you can build your login from that;

I did not try the library functions inside a recyclerview. You could try to disable the interface inside the recyclerview's listener and before exiting from the listener you can reactivate it.

I believe in same way you can avoid to modify the library and achieve the same results. That said, you could clone the main repository and modify the library, then submit a pull request to the creator. In this way an eventual bug could be fixed :-)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants