Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mobile/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@
"line": "#2A3566",
"text": "#F4EFE3",
"muted": "#A3ABCC",
"faint": "#8790B8",
"accent": "#E3B45C",
"onAccent": "#0B1026",
"danger": "#F0806A",
"buttonBackground": "#FFFFFF",
"buttonText": "#0B1026"
Expand All @@ -81,7 +83,9 @@
"line": "#D9CDB3",
"text": "#141A3A",
"muted": "#4B5372",
"faint": "#5A6180",
"accent": "#7D5B18",
"onAccent": "#FCF9F2",
"danger": "#B03A25",
"buttonBackground": "#0B1026",
"buttonText": "#F4EFE3"
Expand Down
8 changes: 4 additions & 4 deletions mobile/src/components/buttons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from 'react-native';
import { Art, type ArtName } from '../art';
import { usePress } from '../motion';
import { font, radius, space } from '../theme';
import { font, radius, size, space } from '../theme';
import { themed, useTheme } from '../use-theme';

/** Shared press feedback: a pressed control dims; a disabled one fades. */
Expand Down Expand Up @@ -78,15 +78,15 @@ export function Button({
const useButtonStyles = themed((c) =>
StyleSheet.create({
base: {
minHeight: 52,
minHeight: space.button,
borderRadius: radius.full,
alignItems: 'center',
justifyContent: 'center',
paddingHorizontal: 20,
},
primary: { backgroundColor: c.action },
secondary: { borderWidth: 1, borderColor: c.line },
text: { fontFamily: font.textBold, fontSize: 17 },
text: { fontFamily: font.textBold, fontSize: size.button },
primaryText: { color: c.onAction },
otherText: { color: c.text },
dangerText: { color: c.danger },
Expand Down Expand Up @@ -166,7 +166,7 @@ const useHeaderLinkStyles = themed((c) =>
alignItems: 'center',
justifyContent: 'center',
},
linkText: { fontFamily: font.text, fontSize: 17, color: c.text },
linkText: { fontFamily: font.text, fontSize: size.button, color: c.text },
linkStrong: { fontFamily: font.textBold, color: c.accent },
}),
);
16 changes: 13 additions & 3 deletions mobile/src/components/marks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Svg, { Circle, Line } from 'react-native-svg';
import { addressLook, hash } from '../address-look';
import { Art } from '../art';
import { useDraw } from '../motion';
import { avatarInk, avatarTints, font, night } from '../theme';
import { avatarInk, avatarTints, font, night, size } from '../theme';
import { ThemeScope, themed, useTheme } from '../use-theme';

const AnimatedCircle = Animated.createAnimatedComponent(Circle);
Expand Down Expand Up @@ -218,14 +218,24 @@ const useBadgeStyles = themed((c) =>
paddingHorizontal: 8,
paddingVertical: 2,
},
text: { fontFamily: font.textBold, fontSize: 11, color: c.onAccent, letterSpacing: 0.5 },
text: {
fontFamily: font.textBold,
fontSize: size.badge,
color: c.onAccent,
letterSpacing: 0.5,
},
outline: {
borderColor: c.muted,
borderWidth: StyleSheet.hairlineWidth * 2,
borderRadius: 999,
paddingHorizontal: 8,
paddingVertical: 1,
},
outlineText: { fontFamily: font.textBold, fontSize: 11, color: c.muted, letterSpacing: 0.5 },
outlineText: {
fontFamily: font.textBold,
fontSize: size.badge,
color: c.muted,
letterSpacing: 0.5,
},
}),
);
6 changes: 3 additions & 3 deletions mobile/src/components/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import {
View,
type ViewStyle,
} from 'react-native';
import { font, radius, space } from '../theme';
import { font, radius, size, space } from '../theme';
import { themed } from '../use-theme';
import { touch } from './buttons';
import { T } from './text';

const PILL_INSET = 4;
const PILL_INSET = space.pillInset;

/** One choice. `value` is what `onChange` reports. */
export type TabItem<T extends string> = {
Expand Down Expand Up @@ -149,7 +149,7 @@ const useStyles = themed((c) =>
},
pillOn: { backgroundColor: c.raised },
words: { flexDirection: 'row', alignItems: 'center', gap: 6, maxWidth: '100%' },
label: { flexShrink: 1, fontFamily: font.textBold, fontSize: 15, color: c.muted },
label: { flexShrink: 1, fontFamily: font.textBold, fontSize: size.tab, color: c.muted },
on: { color: c.text },
count: {
minWidth: 22,
Expand Down
2 changes: 1 addition & 1 deletion mobile/src/components/text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const useTextStyles = themed((c) =>
label: { fontFamily: font.textMedium, fontSize: size.label, color: c.muted },
title: { fontFamily: font.display, fontSize: size.title, color: c.text },
mono: { fontFamily: font.mono, fontSize: size.mono, color: c.text },
dust: { fontFamily: font.text, fontSize: 15, color: c.muted },
dust: { fontFamily: font.text, fontSize: size.dust, color: c.muted },
}),
);

Expand Down
94 changes: 94 additions & 0 deletions mobile/src/native-kit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// The native screens (wallet-native's Kit.swift and Kit.kt) copy the look of
// the React Native components: the same sizes, radii, faces and colours. They
// can't import theme.ts, so these tests read their source and fail when a
// copy stops matching. Change theme.ts and both kits together.
import { readFileSync } from 'node:fs';
import { createRequire } from 'node:module';
import { join } from 'node:path';
import { describe, expect, it } from 'vitest';
import { font, night, type Palette, radius, size, space, vellum } from './theme';

const require = createRequire(import.meta.url);
const { THEME_KEYS } = require('../../wallet-native/plugin/options.js') as {
THEME_KEYS: string[];
};

const native = join(__dirname, '../../wallet-native');
const swift = readFileSync(join(native, 'ios/Kit.swift'), 'utf8');
const kotlinDir = join(native, 'android/src/main/java/com/principlezerolabs/wizard/wallet');
const kotlin = readFileSync(join(kotlinDir, 'Kit.kt'), 'utf8');
const kotlinFace = readFileSync(join(kotlinDir, 'Face.kt'), 'utf8');

/** `name = value` pairs inside `enum <block> {…}` (Swift) or `object <block> {…}` (Kotlin). */
function block(source: string, opener: string, line: RegExp): Record<string, number> {
const start = source.indexOf(opener);
expect(start, `${opener} not found`).toBeGreaterThanOrEqual(0);
const body = source.slice(start, source.indexOf('\n}', start));
const out: Record<string, number> = {};
for (const m of body.matchAll(line)) out[m[1]] = Number(m[2]);
return out;
}

const swiftLine = /static let (\w+): CGFloat = ([\d.]+)/g;
const kotlinLine = /const val (\w+) = ([\d.]+)f?/g;

describe('the native kits use theme.ts values', () => {
const groups = [
['Size', size],
['Radius', radius],
['Space', space],
] as const;

for (const [name, tokens] of groups) {
it(`${name} on iOS and Android`, () => {
const ios = block(swift, `enum ${name} {`, swiftLine);
const android = block(kotlin, `object ${name} {`, kotlinLine);
expect(Object.keys(ios).length).toBeGreaterThan(0);
// Both platforms carry the same names, and each is theme.ts's value.
expect(Object.keys(android).sort()).toEqual(Object.keys(ios).sort());
for (const [k, v] of Object.entries(ios)) {
expect(tokens, `${name}.${k} is not in theme.ts`).toHaveProperty(k);
expect(v, `Kit.swift ${name}.${k}`).toBe(tokens[k as keyof typeof tokens]);
expect(android[k], `Kit.kt ${name}.${k}`).toBe(tokens[k as keyof typeof tokens]);
}
});
}

it('the same faces as React Native', () => {
// Android loads the files by Expo's names. iOS asks for each file's
// PostScript name: Figtree_600SemiBold is Figtree-SemiBold.
for (const name of new Set(Object.values(font))) {
if (name === font.displayMedium) continue; // not used on a native screen
expect(kotlinFace).toContain(`"fonts/${name}.ttf"`);
expect(swift).toContain(`"${name.replace(/_\d+/, '-')}"`);
}
});
});

describe("app.json's native colours are theme.ts's", () => {
const appJson = JSON.parse(readFileSync(join(__dirname, '../app.json'), 'utf8'));
const entry = appJson.expo.plugins.find(
(p: unknown) => Array.isArray(p) && p[0] === '@wizard/wallet-native',
)[1];

/** The plugin's key for each Palette role, where the names differ. */
const role: Record<string, keyof Palette> = {
background: 'page',
buttonBackground: 'action',
buttonText: 'onAction',
};

for (const [key, palette] of [
['theme', night],
['themeLight', vellum],
] as const) {
it(`${key} is ${palette === night ? 'Night' : 'Vellum'}, every key`, () => {
expect(Object.keys(entry[key]).sort()).toEqual([...THEME_KEYS].sort());
for (const k of THEME_KEYS) {
const r = role[k] ?? (k as keyof Palette);
expect(palette, `no Palette role for ${k}`).toHaveProperty(r);
expect(entry[key][k].toUpperCase(), `${key}.${k}`).toBe(String(palette[r]).toUpperCase());
}
});
}
});
23 changes: 22 additions & 1 deletion mobile/src/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,36 @@ export const font = {
mono: 'IBMPlexMono_400Regular',
} as const;

// The native screens' kits (wallet-native/ios/Kit.swift, .../Kit.kt) copy the
// values below that they use, by the same names; native-kit.test.ts checks
// they still match. Change a value here and there together.

export const size = {
balance: 56,
amountEntry: 64,
title: 28,
body: 16,
/** Secondary lines under a figure or a block of text (T kind "dust"). */
dust: 15,
label: 13,
mono: 13,
/** A recovery-phrase word, and what is typed into a secret field. */
monoLarge: 16,
/** Button words, and a strong value such as a total. */
button: 17,
/** In-screen tab words. */
tab: 15,
/** TESTNET and VIEW ONLY. */
badge: 11,
} as const;

export const radius = { card: 20, field: 14, sheetTop: 28, full: 999 } as const;

export const space = { gutter: 20, touch: 48 } as const;
export const space = {
gutter: 20,
touch: 48,
/** A full-width button's height. */
button: 52,
/** The gap between a pill tab track's edge and its pills. */
pillInset: 4,
} as const;
8 changes: 7 additions & 1 deletion wallet-native/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Then `pnpm engine` (from this package or the app) builds the engine into the pac
| `amountFont` | `default` | `serif` for the confirmation sheet's large amount. |
| `lanternRelay` | `https://relay.oblivious.network/lz-staging` | The OHTTP relay for Lantern Zero requests (issue zspace#336). Wallet vendors pick relays, never the server operator. |
| `lanternGateway` | empty | The push gateway holding the app's APNs and FCM credentials, as an `https://` origin. Empty: no pushes; the app wakes the server on open, from its background tasks, and long-polls while on screen. |
| `theme` | plain dark | `background`, `sheet`, `raised`, `line`, `text`, `muted`, `accent`, `danger`, `buttonBackground`, `buttonText`, each `#RRGGBB`. |
| `theme` | plain dark | `background`, `sheet`, `raised`, `line`, `text`, `muted`, `faint`, `accent`, `onAccent`, `danger`, `buttonBackground`, `buttonText`, each `#RRGGBB`. |
| `ids.dataDirs` | `{ mainnet: "wallet-mainnet", testnet: "wallet-testnet" }` | Each network's wallet database folder. |
| `ids.keychainService` | `<bundle id>.phrase` | iOS Keychain service for the phrase. |
| `ids.refreshTaskId`, `ids.processingTaskId` | `<bundle id>.refresh`, `.sync` | iOS background tasks; the plugin also adds them to `BGTaskSchedulerPermittedIdentifiers`. |
Expand All @@ -61,4 +61,10 @@ src/ JS API (native.ts), WalletProvider and hooks, recipient
scripts/sync-engine.sh builds the engine (../engine) and copies it in (git-ignored)
```

## Changing the native screens' look

The native screens are built from one kit per platform: `ios/Kit.swift` and `android/.../Kit.kt`. Each has the same pieces under the same names: text kinds (`title`, `body`, `dust`, `label`, `mono`, `monoLarge`, `strong`), buttons (`primary`, `secondary`, `quiet`, plus `danger`), link, chip, word choice, pill tabs, detail row, Testnet badge, field, switch, and the sheet or page ground. A screen picks pieces and lays them out. It sets no fonts, sizes, radii or colours of its own, so a change to the look is made once in each kit.

The kits copy their numbers from Wizard's `mobile/src/theme.ts` (`size`, `radius`, `space`), under the same names. Colours come from the plugin's `theme` and `themeLight`, which Wizard's `app.json` sets to the same Night and Vellum palettes. `mobile/src/native-kit.test.ts` fails when a kit, `app.json` or `theme.ts` stops matching the others. To change a size, change `theme.ts` and both kits. To change a colour, change `theme.ts` and `app.json`; the native fallbacks are covered by `plugin/options.test.ts`.

Tests: `pnpm test` (vitest, with the native module mocked). The native side is checked on devices; see the `wizard-phone-testing` skill.
Loading
Loading