Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

position not retained when coming back from another fragment #68

Closed
palicka opened this issue Nov 29, 2019 · 6 comments
Closed

position not retained when coming back from another fragment #68

palicka opened this issue Nov 29, 2019 · 6 comments
Assignees
Labels
Milestone

Comments

@palicka
Copy link

palicka commented Nov 29, 2019

Hi, I use navigation graph in my app and when I leave fragment which contains viewpager and come back (click on "skip" button in attached gif), viewpager's position is retained, but dots indicator is reset. I know that view is recreated when leaving and coming back, but I noticed ViewPager2.OnPageChangeCallback's onPageSelected is called with last position, but dots indicator somehow doesn't react. But when I scroll , indicator jumps to correct position. Please have a look at attached video. Thanks
ezgif-1-d6bbe5d48bf5

this is how it's initialised in onActivityCreated() method:

        val pagerAdapter = MyViewPagerAdapter(activity!!)
        viewPager.adapter = pagerAdapter
        pagerIndicator.setViewPager2(viewPager)
@VladPalamarchuk
Copy link

VladPalamarchuk commented Dec 3, 2019

@palicka I had the same issue, look my solution, hope it will helps

indicator.setViewPager(pager)
pager.post { adapter.notifyDataSetChanged() }

Where indicator - is indicator view, pager - is ViewPager, adapter - is PagerAdapter. Indicator internally react on adapter changes, so it will redraw indicators correctly. Hope it helps :)

@palicka
Copy link
Author

palicka commented Dec 4, 2019

@VladPalamarchuk thank you :) it works, but it would great if it was on that position right away :) but your solution is better than nothing so thank you again 👍

@ryandt
Copy link

ryandt commented Dec 20, 2019

This bug also occurs on screen rotation. ViewPager2 will continue to show the current Fragment but the indicator will reset to the first dot even if the first Fragment isn't showing.

@Natkarock
Copy link

This bug is still existing in version 4.1.2

@tommybuonomo
Copy link
Owner

Fixed in 4.3

@tommybuonomo tommybuonomo self-assigned this Apr 30, 2022
@tommybuonomo tommybuonomo added this to the 4.3 milestone Apr 30, 2022
@tommybuonomo
Copy link
Owner

Hello, thanks for your contribution !
This issue is now fixed in the new version 4.3
Thanks 🔥

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

No branches or pull requests

5 participants