For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /api/angular-lynx/device/theme.md.

LynxTheme

The light or dark appearance the app is drawn in, the device's own, and on Android its wallpaper's colors, as signals. import { LynxTheme, provideColorScheme } from '@blotch/angular-lynx';

Usage

src/app/app.ts
import { Component, inject } from '@angular/core';
import { LYNX_ELEMENTS, LynxTheme } from '@blotch/angular-lynx';

@Component({
  selector: 'app-root',
  imports: [LYNX_ELEMENTS],
  template: `
    <view (bindtap)="theme.setColorScheme('dark')">
      <text class="app-text">Drawn {{ theme.appearance() }}</text>
    </view>
  `,
})
export class App {
  readonly theme = inject(LynxTheme);
}

The page element has the dark class while appearance() is 'dark', so a stylesheet's dark values go under page.dark. See Dark mode.

API

LynxTheme

@Injectable({ providedIn: 'root' })
class LynxTheme {}

Reads the theme value that the host app sets in its global data. The host usually sets it from the operating system's appearance setting. In the web preview, where no host sets one, it's the browser's prefers-color-scheme.

LynxTheme.appearance

readonly appearance: Signal<'light' | 'dark'>;

What the app is drawn in: its own choice (see colorScheme), or the device's while that's 'system'.

LynxTheme.colorScheme

readonly colorScheme: Signal<LynxColorScheme>;

The app's choice: 'system' (the default) follows the device, and 'light' and 'dark' keep to one.

LynxTheme.setColorScheme()

setColorScheme(scheme: LynxColorScheme): void;

Sets the app's choice. It lasts until the app closes: store the user's choice and set it again at the next start.

LynxTheme.theme

readonly theme: Signal<'Light' | 'Dark'>;

The device's theme, whatever the app chose. 'Light' when the host sets none and no browser prefers dark.

LynxTheme.isDarkMode

readonly isDarkMode: Signal<boolean>;

true when theme() is 'Dark'.

provideColorScheme()

function provideColorScheme(scheme: LynxColorScheme): EnvironmentProviders;

Sets the app's choice from its first frame, in app.config.ts. An app with no dark design uses provideColorScheme('light').

LynxTheme.dynamicColors

readonly dynamicColors: Signal<DynamicColors | null>;

The colors Android 12 and later take from the user's wallpaper (Material You's dynamic color), as Material 3's color roles, in a light and a dark scheme. null where the host app sends none.

const theme = inject(LynxTheme);

// The wallpaper's tertiary color, or your own where there's none.
const accent = computed(
  () => theme.dynamicColors()?.light.tertiary ?? '#7d5260',
);
  • It comes from the host app, in its dynamicColors GlobalData value: { light, dark }, each with a hex color, such as #6750a4, for every role in DYNAMIC_COLOR_ROLES. A scheme with a role missing counts as none.
  • The Android app ng build --platform android builds sends it, and sends it again when the user changes their wallpaper or colors. iOS, the web preview and Lynx Explorer have none.
  • Both schemes come at once, so an app that keeps its own light or dark theme can use the right one.
  • To color the UI components with it, use Dynamic Color.

Types

LynxColorScheme

type LynxColorScheme = 'system' | 'light' | 'dark';

LynxAppearance

type LynxAppearance = 'light' | 'dark';

DynamicColors

type DynamicColors = {
  readonly light: DynamicColorScheme;
  readonly dark: DynamicColorScheme;
};

DynamicColorScheme

type DynamicColorScheme = { readonly [R in DynamicColorRole]: string };

Each role's color, as a hex color such as #6750a4.

DynamicColorRole

One of Material's color roles, as DYNAMIC_COLOR_ROLES lists them:

  • primary, onPrimary, primaryContainer, onPrimaryContainer, inversePrimary
  • secondary, onSecondary, secondaryContainer, onSecondaryContainer
  • tertiary, onTertiary, tertiaryContainer, onTertiaryContainer
  • background, onBackground, surface, onSurface, surfaceVariant, onSurfaceVariant
  • surfaceDim, surfaceBright, surfaceContainerLowest, surfaceContainerLow, surfaceContainer, surfaceContainerHigh, surfaceContainerHighest
  • inverseSurface, inverseOnSurface, outline, outlineVariant

The error roles aren't there: Material keeps errors red whatever the wallpaper.