Content cards
Pinning, expiry and categories
How pinned cards, expiry dates, categories and extras behave on the device, and how to use them in the default feed and in your own UI.
Four card fields control where a card appears and for how long: pinned, expiresAt, categories and extras. The SDK applies expiry for you; the other three are yours to act on.
You set these fields per message variant in Herald. See Create cards in Herald. A variant with no saved options sends cards that are not pinned, never expire, and have no categories or extras.
Pinned
| Behavior | |
|---|---|
| Default feed | Pinned cards come first, newest first among them, then every other card, newest first. |
| Custom UI | contentCards is not reordered for you. Sort with pinned first if you want the same order. |
| Dismissal | Pinning does not stop dismissal. Use dismissible for that. |
let ordered = store.cards.sorted { a, b in
a.pinned != b.pinned ? a.pinned : a.createdAt > b.createdAt
}val ordered = cards.sortedWith(compareByDescending<ContentCard> { it.pinned }.thenByDescending { it.createdAt })Expiry
- A card with an
expiresAtin the past is never incontentCards. The SDK checks expiry every time it updates the list. - A card that expires while it is on screen leaves
contentCardsat its expiry time: the SDK updates the list then, without a sync, so an open feed drops it. - Herald stops returning a card once it expires, so it is gone from the next sync on every device.
- A null
expiresAtmeans the card stays until the user dismisses it or Herald retires it.
Categories
categories is a list of strings. Use it to place cards: an inbox, a home screen banner, a section per topic.
// Home banner: one "promo" card.
let banner = store.cards.first { $0.categories.contains("promo") }
// Inbox feed without promos.
ContentCardFeed(filter: { !$0.categories.contains("promo") })// Home banner: one "promo" card.
val banner = cards.firstOrNull { "promo" in it.categories }
// Inbox feed without promos.
ContentCardFeed(filter = { "promo" !in it.categories })A card can have several categories, or none. A filter that requires a category hides cards without one.
Extras
extras carries key-value data for your own UI, such as a badge label or a background color. Values can be any JSON value; strings, numbers and booleans are the usual choice.
- The default feed reads one key:
alt, the screen reader description for animage_onlycard that has no title. - Read other keys in a custom card view. On iOS a value is a
HeraldValue, so match the case:if case .string(let badge)? = card.extras["badge"] { ... }. On Android it isAny?:card.extras["badge"] as? String.
Edge cases
- Clock changes. The SDK compares
expiresAtwith the device clock, so a device set ahead hides cards early. - Sign-out.
reset()clears every card regardless of pinning or expiry.