Skip to content

Custom expansion keys

Saket Narayan edited this page Apr 1, 2021 · 1 revision

InboxRecyclerView by default uses stable adapter IDs for expanding and collapsing items. These IDs are great for identifying expanded item across state restorations, but enforcing apps to use Long based IDs kinda sucks.

Apps that want to use their own custom type can do so by using InboxItemExpander:

// Before:
inboxRecyclerView.expandItem(adapterId = 42)

// After:
val itemExpander = InboxItemExpander { expandingItemKey, viewHolders ->
  viewHolders.firstOrNull { holder ->
    // Identify the expanding item's ViewHolder here. Otherwise return
    // null to expand the item from the top of the list.
    holder.{some identifier} == expandingItemKey 
  }
}
inboxRecyclerView.itemExpander = itemExpander
itemExpander.expandItem(item = ExpandableScreenKey(...))
Clone this wiki locally