-
Notifications
You must be signed in to change notification settings - Fork 118
Pull to collapse
Saket Narayan edited this page Apr 1, 2021
·
9 revisions
ExpandablePageLayout
is nested scrolling aware. Its pull-to-collapse gesture will work seamlessly with your scrollable content as long as you use widgets that support nested scrolling such as NestedScrollView
, RecyclerView
, etc.
In case nested scrolling isn’t supported by your layout, the pull-to-collapse gesture can be intercepted manually:
expandablePage.pullToCollapseInterceptor = { downX, downY, upwardPull ->
val directionInt = if (upwardPull) +1 else -1
val canScrollFurther = scrollableContainer.canScrollVertically(directionInt)
if (canScrollFurther) InterceptResult.INTERCEPTED else InterceptResult.IGNORED
}
When the scrollable content does not consume the entire space, the downX
and downY
parameters can be used to check if the touch actually lies on them.
When the content is pulled and released, ExpandablePageLayout
uses the default toolbar height as the threshold to decide if the content can be collapsed. This can be customised using,
expandablePage.pullToCollapseThresholdDistance = THRESHOLD_IN_PIXELS