Closed daviddebre closed 2 years ago
Can you state the reason why you need to disable the indicator scrolling?
Actually this was a request from the client, the app was built for.
By the way, here is the solution which was implemented to disable scrolling:
class ImageCarouselTabLayout(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : TabLayout(context, attrs, defStyleAttr) {
override fun setScrollPosition(position: Int, positionOffset: Float, updateSelectedText: Boolean, updateIndicatorPosition: Boolean) {
val manipulatedUpdateIndicatorPosition =
if (positionOffset == 0f) {
updateIndicatorPosition
} else {
/**
* since [positionOffset] represents the value of scrolling between two tab: updating the scrolling fraction for tabIndicator
* can be avoided by not updating indicator position (setting false) when [positionOffset] is not 0
*/
false
}
super.setScrollPosition(position, positionOffset, updateSelectedText, manipulatedUpdateIndicatorPosition)
}
}
I'll close this issue for now due to no further info available. Please feel free to reopen it if https://github.com/material-components/material-components-android/commit/a295de97283b51cacfbc74e58e95048d348cc471 doesn't solve your issue. : )
TabLayoutMediator
with the use ofTabLayoutOnPageChangeCallback
triggers scrolling the tab indicator inonPageScrolled
(viaupdateIndicator
). This implementations doesn't let to disable the tab indicator scrolling.The solution would be to extend the
TabLayoutMediator
in order to enable/disable tab indicator scrolling. Another potential solution is to be support setting a customViewPager2.OnPageChangeCallback
/TabLayoutOnPageChangeCallback
for theonPageChangeCallback
field.Version of library: 1.2.0-alpha02
Similar feature request: https://github.com/material-components/material-components-android/issues/813
If the feature request is approved, then I could help with an appropriate pull request.