Skip to content

Page callbacks

Saket Narayan edited this page Nov 10, 2019 · 4 revisions

ExpandablePageLayout offers multiple ways of receiving callbacks for observing changes to the its movement.

State changes

There are four different states:

  • PageState.COLLAPSING
  • PageState.COLLAPSED
  • PageState.EXPANDING
  • PageState.EXPANDED

These can be accessed using ExpandablePage.currentState or by registering callbacks,

expandablePage.addStateChangeCallbacks(object: SimplePageStateChangeCallbacks() {

  override fun onPageAboutToExpand(expandAnimDuration: Long) {}

  override fun onPageExpanded() {}

  override fun onPageAboutToCollapse(collapseAnimDuration: Long) {}

  override fun onPageCollapsed() {}
})

Overridable functions

ExpandablePageLayout also offers the same set of callbacks as open functions that can be overridden when subclassing it. This can also be useful for apps that use a View driven navigation stack instead of multiple Activities or Fragments.

class Screen(context: Context) : ExpandablePageLayout(context) {
  
  override fun onPageAboutToExpand(expandAnimDuration: Long) {}

  override fun onPageExpanded() {}

  override fun onPageAboutToCollapse(collapseAnimDuration: Long) {}

  override fun onPageCollapsed() {}
}

Pull-to-collapse gesture

expandablePage.addOnPullListener(object: SimpleOnPullListener() {

  override fun onPull(...) {}

  override fun onRelease(collapseEligible: Boolean) {}
})