Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,17 @@ object PagerViewViewManagerImpl {
fun setPageMargin(host: NestedScrollableHost, margin: Int) {
val pager = getViewPager(host)
val pageMargin = PixelUtil.toPixelFromDIP(margin.toDouble()).toInt()
if (pageMargin == 0) {
pager.setPageTransformer(null)
return
}
/**
* Don't use MarginPageTransformer to be able to support negative margins
* Don't use MarginPageTransformer to be able to support negative margins.
*/
pager.setPageTransformer { page, position ->
val offset = pageMargin * position
if (pager.orientation == ViewPager2.ORIENTATION_HORIZONTAL) {
val isRTL = pager.layoutDirection == View.LAYOUT_DIRECTION_RTL
page.translationX = if (isRTL) -offset else offset
page.translationX = offset
} else {
page.translationY = offset
}
Expand Down Expand Up @@ -184,4 +187,4 @@ object PagerViewViewManagerImpl {
}
Choreographer.getInstance().postFrameCallback(refreshFrameCallback)
}
}
}
Loading