Skip to content
Menu

In-app messages

Theming and dark mode

Markdown version

Match in-app messages to your app's colors, fonts, corner radius and spacing, control dark mode, and understand how per-message styles override the theme.

The default message views take their look from a HeraldTheme: light and dark colors, fonts, corner radius and spacing. It is the same theme type the content card feed uses, so one definition styles both.

Before you start

  • You install the default presenter with Herald.useDefaultInAppUI (iOS) or HeraldInAppPresenter.install (Android).

1. Pass your theme to the presenter

swift
import SwiftUI
import HeraldUI

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)

let theme = HeraldTheme(lightColors: light, darkColors: dark, cornerRadius: 16, spacing: 20)
Herald.useDefaultInAppUI(theme: theme)

Both calls return the presenter. Its theme property can be changed later, for example when the user picks a different app theme; the next message uses the new value.

What the theme controls

Theme valueUsed in messages for
surfaceMessage background (all four types)
onSurfaceHeader, body, the close button, and the text of secondary buttons
accentBackground of the first (primary) button
onAccentText of the primary button
scrimThe dimmed layer behind a modal
outlineImage placeholder while an image loads
typography.title, .body, .buttonHeader, body and button text
cornerRadiusMessage and button corners
spacingPadding inside messages and the slideup's distance from the screen edge

Buttons after the first have no fill: they use the text color on the message background.

Per-message styles

A message can carry its own style: backgroundColor, textColor, buttonColor, buttonTextColor and cornerRadius. Each field that is set replaces the matching theme value for that message only. Fields left null, and colors that are not valid #RRGGBB or #AARRGGBB hex, fall back to the theme, with one exception: when a message sets backgroundColor without textColor, the text is black or white, whichever has the higher contrast against that background. buttonColor without buttonTextColor works the same way for the button label. The theme's text colors are picked for the theme's own surfaces, so they could be unreadable on a color the message chose.

Style fieldReplaces
backgroundColorsurface
textColoronSurface
buttonColoraccent
buttonTextColoronAccent
cornerRadiuscornerRadius

Message colors do not change with dark mode. A message with a white backgroundColor stays white in dark mode. To keep dark mode working, leave colors null and let the theme decide, or pick colors that read well in both modes.

Dark mode

darkModeBehavior
nil / null (default)Follows the system light or dark setting
trueAlways uses darkColors
falseAlways uses lightColors

If your app has its own appearance setting, set darkMode from it and update presenter.theme when the user changes it. On iOS, a forced value also sets the message window's interface style, so system controls inside the message match.

Fonts

swift
let typography = HeraldTypography(
    title: .custom("Avenir Next", size: 20, relativeTo: .title3).weight(.semibold),
    body: .custom("Avenir Next", size: 16, relativeTo: .body)
)
Herald.useDefaultInAppUI(theme: HeraldTheme(typography: typography))

The defaults are system text styles on iOS and sp sizes on Android, so they follow the user's text size. Keep that when you replace them: relativeTo: on iOS, sp on Android.

HTML messages

The theme does not style an HTML page. The message background (the theme's surface, or the message's backgroundColor) shows behind and around the page. Style the page with its own CSS, including dark mode, and test it in both modes on both platforms.

Verify it works

Show a modal in light mode and in dark mode, and once with the system text size at its largest. Use Herald.shared.debugShowInAppMessage(_:) / Herald.debugShowInAppMessage(_:) with a message loaded through debugLoadMessages to repeat this without waiting for a trigger; both are for debug builds only.

Troubleshooting

  • Messages ignore the feed theme. The feed reads the theme from the view tree; the presenter does not. Pass the theme to useDefaultInAppUI or install as well.
  • One message looks off-brand. It carries its own style colors. Check the message, not the theme.
  • Text is clipped at large text sizes. A custom font with a fixed size. Use relativeTo: or sp.

Next

See Herald decide live →