Skip to content
Menu

Content cards

Customizing the feed

Markdown version

Change the default feed's colors, fonts and spacing, filter and sort cards, replace the view for a card type and handle taps yourself.

Every part of the default feed can be changed without giving up its automatic logging: the theme, which cards appear and in what order, how each card type looks, and what a tap does.

Before you start

1. Apply a theme

A HeraldTheme holds light and dark color sets, fonts, a corner radius and a base spacing unit. Pass the same theme to the in-app message presenter so cards and messages match.

swift
import SwiftUI
import HeraldUI

let lumenTheme: HeraldTheme = {
    var light = HeraldColors.light
    light.accent = Color(red: 0.07, green: 0.55, blue: 0.42)
    var dark = HeraldColors.dark
    dark.accent = Color(red: 0.36, green: 0.84, blue: 0.67)
    return HeraldTheme(
        lightColors: light,
        darkColors: dark,
        typography: HeraldTypography(title: .custom("Avenir Next", size: 17, relativeTo: .headline)),
        cornerRadius: 16
    )
}()

struct InboxView: View {
    var body: some View {
        ContentCardFeed().heraldTheme(lumenTheme)
    }
}

What each color does in the feed:

ColorUsed for
backgroundBehind the feed
surfaceCard background
onSurfaceCard title
onSurfaceVariantCard body and the empty-state text
accentCall-to-action text
outlineCard border and image placeholder

onAccent and scrim are used by in-app messages. Fonts: title, body and button (the call to action). spacing is the card padding and the gap around cards. darkMode set to true or false forces dark or light colors; nil / null follows the system.

Keep text scalable when you change fonts. On iOS, build custom fonts with Font.custom(_:size:relativeTo:) so Dynamic Type still applies. On Android, give sizes in sp.

2. Filter and sort

filter keeps the cards it returns true for. order replaces the default pinned-first, newest-first sort.

swift
// Only workout tips, oldest first.
ContentCardFeed(
    filter: { $0.categories.contains("tips") },
    order: { $0.createdAt < $1.createdAt }
)

The default sort is available as ContentCardFeedDefaults.order (iOS) and ContentCardFeedDefaults.Order (Android) if you want to filter but keep it.

3. Handle taps yourself

By default a tap opens the card's url. Pass onCardClick to route it yourself. The SDK logs the click before your handler runs.

swift
ContentCardFeed(onCardClick: { card in
    router.open(card)
})

4. Replace the view for a card type

Pass cardContent to draw cards yourself. Call onClick when your view is tapped, so the click is logged and handled. Fall back to the default view for the types you do not replace. The feed still measures impressions and handles swipe to dismiss around your view.

swift
ContentCardFeed { card, onClick in
    if card.type == .classic {
        LumenTipCard(card: card, onClick: onClick)
    } else {
        ContentCardView(card: card, onClick: onClick)
    }
}

struct LumenTipCard: View {
    let card: ContentCard
    let onClick: () -> Void

    var body: some View {
        Button(action: onClick) {
            Label(card.title ?? "", systemImage: "figure.run")
                .frame(maxWidth: .infinity, minHeight: 44, alignment: .leading)
        }
    }
}

The default per-type views are public, so you can reuse them inside your own layout: ClassicContentCardView, CaptionedImageContentCardView and ImageOnlyContentCardView on iOS, ClassicContentCard, CaptionedImageContentCard and ImageOnlyContentCard on Android.

5. Change the empty state and labels

swift
ContentCardFeed(emptyMessage: "You're all caught up")
  • iOS looks up emptyMessage, the Dismiss action label and the Close button label in your app's strings files, so add those keys to translate them.
  • Android reads the herald_feed_empty, herald_dismiss and herald_close string resources. Override them in your app's res/values*/strings.xml.
  • On Android, contentPadding sets the padding around the list, and modifier applies to the list itself.

Verify it works

Switch the device between light and dark mode and raise the system text size: the feed should follow both. Tap a card with your onCardClick handler and confirm it runs once.

Troubleshooting

  • The theme has no effect (iOS). .heraldTheme(_:) must be applied to the feed or one of its ancestors, not to a sibling view.
  • The theme has no effect (Android). ContentCardFeed must be inside the CompositionLocalProvider that provides LocalHeraldTheme.
  • Custom cards are never marked as viewed. Impressions are measured on the view you return, so it needs a real size. A zero-height view never counts as half visible.
  • A custom card's tap is not logged. Call the onClick you were given, not your own navigation code directly.

Next

See Herald decide live →