Skip to content

Theming & Dark Mode ​

Token model ​

The native bloodline's token source of truth lives in lh-ui-core/tokens/*.json; codegen produces the HarmonyOS artifacts:

ArtifactContentsDark behavior
LhTokensFull light set: Button sizes, Color palette, Motion, Radius, Shadow, Spacing, Typography, ZIndex—
LhDarkTokensOnly the Color subclass (side-by-side object model)Dark overrides colors only; sizes / motion / radius are unchanged in dark
LhShadowArkUI shadow carrier interface (color/radius/offsetX/offsetY)—

This matches android / ios / windows (side-by-side objects) and differs from the docs site (shallow-merged JSON). The theme layer is designed accordingly: the LhColors interface carries colors only, while components read sizes straight from LhTokens.

LhColors ​

The LightLhColors() / DarkLhColors() factories flatten the two generated classes into a single interface object:

typescript
export interface LhColors {
  primary: ResourceColor
  onPrimary: ResourceColor
  // ... all semantic colors
}

export function LightLhColors(): LhColors {
  return { primary: LhTokens.Color.Primary.default, /* ... */ }
}
export function DarkLhColors(): LhColors {
  return { primary: LhDarkTokens.Color.Primary.default, /* ... */ }
}

The factory functions are public: unit tests can construct palettes directly for assertions, and the app side consumes them via LhTheme.apply.

AppStorage injection ​

ArkTS's AppStorage only accepts serializable types, so the palette is passed as JSON:

typescript
LhTheme.apply(isDark)  // setOrCreate(LH_COLORS_KEY, JSON.stringify(colors))

Components read and parse it in aboutToAppear, falling back to the light palette when nothing was injected.

Dark precomputation (important) ​

The web bloodline evaluates dark colors dynamically with CSS color-mix(); native has no CSS cascade, so core has precomputed the dark expressions into literals (#AARRGGBB strings such as '#403D649E' and '#FFB1C1D8'). Consequence (master plan R-n6):

When you change the preset primary color, the precomputed dark values do not follow automatically. You must recompute them by hand, update lh-ui-core/tokens/color-dark.json, and refresh the Design Language Baseline accordingly.

HarmonyOS-specific conventions ​

  • Durations are milliseconds: Motion.Duration.base = 300 (iOS uses seconds); consumed directly by curve / animateTo.
  • Color notation: '#AARRGGBB' strings (ResourceColor) with an alpha prefix ('#FF2B4C7C' is fully opaque).
  • Corner radius: Radius.circle is a 0.5 fraction; the device side converts it with min(width, height) / 2 — it cannot be used as a vp value.
  • Shadow: ArkUI does not support spread, so the generated LhShadow ignores spread and notes it in a comment.
  • AppStorage serialization: ResourceColor is not in the AppStorage type whitelist, so the palette travels as a JSON string.
  • Nested classes are not exported: only the root export class LhTokens is exported; nested class Color and friends carry no export (export declarations inside a class body are disallowed — the core harmony target already handles this).

Token quick reference ​

The full token table (light / dark / notes) lives in the core repo at dist/docs/tokens.md (generated by pnpm codegen). For component-level token mappings, see the Button token reference.

lh-ui native bloodline · HarmonyOS (ArkTS + ArkUI)