position not retained when coming back from another fragment
palicka opened this issue · 6 comments
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
this is how it's initialised in onActivityCreated() method:
val pagerAdapter = MyViewPagerAdapter(activity!!)
viewPager.adapter = pagerAdapter
pagerIndicator.setViewPager2(viewPager)
@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 :)
@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 👍
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.
This bug is still existing in version 4.1.2
Fixed in 4.3
Hello, thanks for your contribution !
This issue is now fixed in the new version 4.3
Thanks 🔥