Skip to content

cascade

demo

cascade offers a drop-in replacement for PopupMenu. For guidance on creating & nesting menus, the official documentation can be followed while replacing any usages of PopupMenu with CascadePopupMenu.

implementation "me.saket.cascade:cascade:2.3.0"
- val popup = PopupMenu(context, anchor)
+ val popup = CascadePopupMenu(context, anchor)
  popup.inflate(R.menu.nicolas_cage_movies)
  popup.show()

Consistency with Toolbar's overflow menu

Toolbar uses PopupMenu for showing overflow menu without offering any way to change this. If you're replacing all PopupMenu usages in your project with cascade, there are a few ways you could achieve consistency by forcing Toolbar to use cascade:

  • The safest way is to extract out your toolbar menu items with app:showAsAction="ifRoom" into their own menu that is shown using cascade manually.

  • Alternatively, cascade offers an override using reflection but is currently incompatible with Proguard:

toolbar.overrideAllPopupMenus { context, anchor ->
  CascadePopupMenu(context, anchor)
}

// The lambda can be collapsed into a reference
// if you're only using the two-param constructor.
toolbar.overrideAllPopupMenus(with = ::CascadePopupMenu)