Thursday, 25 March 2021

Disable view pager swipe for other child fragments

I am working with ViewPager2 where i have 2 fragments in the viewpager. It works perfectly but there is a problem that i want it to just be swiped from FragmentTwo to FragmentOne fragment as it is working now. But when i swipe it from FragmentOne to FragmentTwo then it will be able to swipe only from the FirstFragment child fragment of FragmentOne fragment.

Image of my project, the image

In this image MainActivity is base activity where the viewpager2 is placed. It contains 2 fragment, FragmentOne and FragmentTwo. FragmentOne has a customized viewpager2 for BottomNavigationView. It has 3 fragments the first one is HomeFragment and this fragment has a button two transact to FragmentTwo. So i just want that the swipe transaction can be happen only from the HomeFragment, Not from its child or other two fragments. Like instagram where we can just swipe only from HomeFragment to ChatFragment.

I am not mentioning any code of the viewpager as it is so basic.

I've tried this way by getting the current fragment & last fragment & .isVisible or .add fragment in the MainActivity but nothing works.

Example:

if (!HomeFragment().isVisible){
            mViewPager?.isUserInputEnabled = false
        }


from Disable view pager swipe for other child fragments

No comments:

Post a Comment