Closed dongheeleeme closed 1 year ago
Hi, Thank you for submitting this PR!
I have examined this issue, this issue originated from the duplicated events between onPageScrolled
and onPageSelected
.
Actually, the first planning was that the indicator should move to align the scroll position. (That looks more natural when users scroll screens) But there is an issue that the indicator moves with some animations make the weird actions (onPageSelected and onPageScrolled are invoked at the same time; when we select an item, the onPageScrolled
is called too). I think the best solution is to handle the scrolling state in the events, but I need to consider this issue more.
We can represent the above issue as below:
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
- if ((selectedIndex > position && previousPosition < positionOffset)) {
- post {
indicator.x = itemWidth * position + itemWidth * positionOffset + indicatorPadding
- previousPosition = positionOffset
- }
- }
}
The indicator will align the position of the ViewPager, but If we select a bottom navigation item, the final animation (overshoot) would be weird.
Thank you for explaining the details @skydoves. When I reproduced this issue, it happened only at navigation bar is initialized. and at that time, I could see onPageSelected
was not called. please let me know if I have missing points in this issue. I'll investigate this issue more.
Fixed Issue ➡️ #8
This issue seems to be happen when navigation bar is initialized at first time. But this bug is occurred depends on onPageScrolled's parameters
position
andpositionOffset
. So i think we need to enforce location of the indicator at first time. WDYT? Please let me know if you have any concern about my approach @skydoves