diff --git a/mobile/app.json b/mobile/app.json index 411b2a7..ecd4fb6 100644 --- a/mobile/app.json +++ b/mobile/app.json @@ -69,7 +69,9 @@ "line": "#2A3566", "text": "#F4EFE3", "muted": "#A3ABCC", + "faint": "#8790B8", "accent": "#E3B45C", + "onAccent": "#0B1026", "danger": "#F0806A", "buttonBackground": "#FFFFFF", "buttonText": "#0B1026" @@ -81,7 +83,9 @@ "line": "#D9CDB3", "text": "#141A3A", "muted": "#4B5372", + "faint": "#5A6180", "accent": "#7D5B18", + "onAccent": "#FCF9F2", "danger": "#B03A25", "buttonBackground": "#0B1026", "buttonText": "#F4EFE3" diff --git a/mobile/src/components/buttons.tsx b/mobile/src/components/buttons.tsx index 63add7d..d75e7fb 100644 --- a/mobile/src/components/buttons.tsx +++ b/mobile/src/components/buttons.tsx @@ -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. */ @@ -78,7 +78,7 @@ export function Button({ const useButtonStyles = themed((c) => StyleSheet.create({ base: { - minHeight: 52, + minHeight: space.button, borderRadius: radius.full, alignItems: 'center', justifyContent: 'center', @@ -86,7 +86,7 @@ const useButtonStyles = themed((c) => }, 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 }, @@ -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 }, }), ); diff --git a/mobile/src/components/marks.tsx b/mobile/src/components/marks.tsx index 872bcc1..df244d7 100644 --- a/mobile/src/components/marks.tsx +++ b/mobile/src/components/marks.tsx @@ -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); @@ -218,7 +218,12 @@ 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, @@ -226,6 +231,11 @@ const useBadgeStyles = themed((c) => 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, + }, }), ); diff --git a/mobile/src/components/tabs.tsx b/mobile/src/components/tabs.tsx index b4d7fe3..1c3e36d 100644 --- a/mobile/src/components/tabs.tsx +++ b/mobile/src/components/tabs.tsx @@ -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 = { @@ -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, diff --git a/mobile/src/components/text.tsx b/mobile/src/components/text.tsx index 8e66378..e7f1af8 100644 --- a/mobile/src/components/text.tsx +++ b/mobile/src/components/text.tsx @@ -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 }, }), ); diff --git a/mobile/src/native-kit.test.ts b/mobile/src/native-kit.test.ts new file mode 100644 index 0000000..bce8e22 --- /dev/null +++ b/mobile/src/native-kit.test.ts @@ -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 {…}` (Swift) or `object {…}` (Kotlin). */ +function block(source: string, opener: string, line: RegExp): Record { + const start = source.indexOf(opener); + expect(start, `${opener} not found`).toBeGreaterThanOrEqual(0); + const body = source.slice(start, source.indexOf('\n}', start)); + const out: Record = {}; + 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 = { + 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()); + } + }); + } +}); diff --git a/mobile/src/theme.ts b/mobile/src/theme.ts index 92966ed..6b5c41c 100644 --- a/mobile/src/theme.ts +++ b/mobile/src/theme.ts @@ -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; diff --git a/wallet-native/README.md b/wallet-native/README.md index 4fc7fd4..fbe4de3 100644 --- a/wallet-native/README.md +++ b/wallet-native/README.md @@ -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` | `.phrase` | iOS Keychain service for the phrase. | | `ids.refreshTaskId`, `ids.processingTaskId` | `.refresh`, `.sync` | iOS background tasks; the plugin also adds them to `BGTaskSchedulerPermittedIdentifiers`. | @@ -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. diff --git a/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/ConfirmSheet.kt b/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/ConfirmSheet.kt index 9c95522..e690a29 100644 --- a/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/ConfirmSheet.kt +++ b/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/ConfirmSheet.kt @@ -1,18 +1,12 @@ package com.principlezerolabs.wizard.wallet import android.app.Activity -import android.app.Dialog -import android.graphics.Typeface -import android.graphics.drawable.GradientDrawable import android.view.Gravity import android.view.View -import android.view.ViewGroup.LayoutParams.MATCH_PARENT import android.view.ViewGroup.LayoutParams.WRAP_CONTENT -import android.view.WindowManager import android.widget.Button import android.widget.LinearLayout import android.widget.ProgressBar -import android.widget.TextView import java.util.Locale import kotlin.concurrent.thread import uniffi.wizard_wallet.WalletProposalInfo @@ -44,7 +38,7 @@ object Format { /** * The confirmation sheet (spec §7). Native code reads the proposal from Rust * by id, so what the user approves is what Rust will build, whatever - * JavaScript showed. Plain, no art (design guide §7). Call on the UI thread. + * JavaScript showed. No art (design guide §7); drawn with [Kit]. Call on the UI thread. * * `send` runs on a background thread and returns what the engine built, or * throws [PhraseException.Cancelled] if the prompt was dismissed. `onFinish` @@ -54,13 +48,6 @@ object Format { * dropped the proposal, so the user reviews the payment again (zspace#374). */ object ConfirmSheet { - private val NIGHT get() = Theme.background - private val DEEP get() = Theme.sheet - private val STAR get() = Theme.text - private val DUST get() = Theme.muted - private val GOLD get() = Theme.accent - private val CINNABAR get() = Theme.danger - fun show( activity: Activity, proposal: WalletProposalInfo, @@ -73,72 +60,25 @@ object ConfirmSheet { message: (Throwable) -> String, onFinish: (WalletSendOutcome?) -> Unit, ) { - Theme.use(activity) - val density = activity.resources.displayMetrics.density - fun dp(v: Int) = (v * density).toInt() - val dialog = Dialog(activity) - dialog.setCancelable(false) - val body = LinearLayout(activity).apply { - orientation = LinearLayout.VERTICAL - setPadding(dp(20), dp(20), dp(20), dp(28)) - background = GradientDrawable().apply { - setColor(DEEP) - cornerRadii = floatArrayOf(dp(20).toFloat(), dp(20).toFloat(), dp(20).toFloat(), dp(20).toFloat(), 0f, 0f, 0f, 0f) - } - } - dialog.setContentView(body) - dialog.window?.apply { - setLayout(MATCH_PARENT, WRAP_CONTENT) - setGravity(Gravity.BOTTOM) - setBackgroundDrawableResource(android.R.color.transparent) - setDimAmount(0.6f) - // The sheet shows an address and amounts; keep them out of the recent-apps preview. - addFlags(WindowManager.LayoutParams.FLAG_SECURE) - } - - val bodyFace = Face.of(activity, Face.BODY) - val strong = Face.of(activity, Face.BUTTON) - val labelFace = Face.of(activity, Face.LABEL) - val mono = Face.of(activity, Face.MONO) - - fun text(s: String, size: Float, color: Int, typeface: Typeface = bodyFace): TextView = - TextView(activity).apply { - text = s - textSize = size - setTextColor(color) - this.typeface = typeface - setPadding(0, dp(2), 0, dp(2)) - } - - fun add(v: View, top: Int = 12) = - body.addView(v, LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT).apply { topMargin = dp(top) }) - - fun button(label: String, primary: Boolean, onClick: () -> Unit) = - Face.button(activity, label, filled = primary, onClick) + // The sheet shows an address and amounts: it stays out of the recent-apps preview. + val (dialog, body) = Kit.bottomSheet(activity) + fun text(s: String, kind: TextKind = TextKind.BODY, color: Int? = null) = Kit.text(activity, s, kind, color) + fun add(v: View, top: Int = 12) = Kit.add(body, v, top) + fun field(name: String, value: View) = add(Kit.detail(activity, name, value), 14) + fun field(name: String, value: String, kind: TextKind = TextKind.BODY) = + add(Kit.detail(activity, name, value, kind), 14) fun header(title: String) { val row = LinearLayout(activity).apply { orientation = LinearLayout.HORIZONTAL gravity = Gravity.CENTER_VERTICAL - addView(text(title, 28f, STAR, Face.of(activity, Face.TITLE)), LinearLayout.LayoutParams(0, WRAP_CONTENT, 1f)) + addView(text(title, TextKind.TITLE), LinearLayout.LayoutParams(0, WRAP_CONTENT, 1f)) // Only the test network is named (issue #10): mainnet is the default people never need to see. - if (WalletSettings.testnet) addView(text("TESTNET", 11f, NIGHT, strong).apply { - letterSpacing = 0.05f - setPadding(dp(8), dp(3), dp(8), dp(3)) - background = GradientDrawable().apply { - setColor(GOLD) - cornerRadius = dp(12).toFloat() - } - }) + if (WalletSettings.testnet) addView(Kit.testnetBadge(activity)) } add(row, 0) } - fun field(name: String, value: View) { - add(text(name, 13f, DUST, labelFace), 14) - add(value, 2) - } - var finished = false fun finish(outcome: WalletSendOutcome?) { if (finished) return @@ -169,53 +109,56 @@ object ConfirmSheet { val d = Format.usd(z, usdPerZec) return if (usdFirst) "$d · $zz" else "$zz · $d" } - if (isShield) add(text("Arrived at your exchange address", 15f, DUST), 16) + if (isShield) add(text("Arrived at your exchange address", TextKind.DUST), 16) // The payment in the unit the person chose; the other one under it. A request's is its fee. - add(text(if (isRequest) "Fee ${both(proposal.fee)}" else if (usdFirst) usdAmount!! else zecAmount, 40f, STAR, Face.display(activity)), 16) + add(text(if (isRequest) "Fee ${both(proposal.fee)}" else if (usdFirst) usdAmount!! else zecAmount).apply { + textSize = 40f + typeface = Face.display(activity) + }, 16) if (usdPerZec != null && !isRequest) { val small = if (usdFirst) zecAmount else usdAmount!! - add(text(if (isShield) small else "$small at 1 ZEC = ${Format.usd(100_000_000uL, usdPerZec)}", 15f, DUST), 2) + add(text(if (isShield) small else "$small at 1 ZEC = ${Format.usd(100_000_000uL, usdPerZec)}", TextKind.DUST), 2) } if (isShield) { - field("From", text("Your public exchange address", 16f, STAR)) - field("To", text("Your private balance", 16f, STAR)) - field("Fee", text(both(proposal.fee), 16f, STAR)) - field("Private after", text(both(proposal.shielded), 17f, STAR, strong)) - add(text("The money stays yours: it moves from your public address to your private balance. Until then anyone can see it, and ${WalletSettings.appName} can’t pay with it.", 15f, DUST), 12) + field("From", "Your public exchange address") + field("To", "Your private balance") + field("Fee", both(proposal.fee)) + field("Private after", both(proposal.shielded), TextKind.STRONG) + add(text("The money stays yours: it moves from your public address to your private balance. Until then anyone can see it, and ${WalletSettings.appName} can’t pay with it.", TextKind.DUST), 12) } else { val to = LinearLayout(activity).apply { orientation = LinearLayout.VERTICAL } - if (label != null) to.addView(text(label, 17f, STAR, strong)) - for (a in proposal.to) to.addView(text(Format.grouped(a), 13f, STAR, mono).apply { setTextIsSelectable(true) }) + if (label != null) to.addView(text(label, TextKind.STRONG)) + for (a in proposal.to) to.addView(text(Format.grouped(a), TextKind.MONO).apply { setTextIsSelectable(true) }) // A public address says so (#54). when (proposal.recipient) { WalletRecipientKind.PUBLIC -> "Public address" WalletRecipientKind.TEX -> "Exchange address for public payments only" WalletRecipientKind.PRIVATE -> null - }?.let { to.addView(text(it, 13f, GOLD, strong)) } + }?.let { to.addView(text(it, TextKind.LABEL, Theme.accent).apply { typeface = Face.of(activity, Face.BUTTON) }) } field("To", to) if (isRequest) { - memoLines.firstOrNull()?.let { field("Request", text(it, 16f, STAR)) } - add(text("Only the fee leaves your wallet. They pay the request if they choose to.", 15f, DUST), 12) + memoLines.firstOrNull()?.let { field("Request", it) } + add(text("Only the fee leaves your wallet. They pay the request if they choose to.", TextKind.DUST), 12) } else { - proposal.memo?.takeIf { it.isNotEmpty() }?.let { field("Note", text(it, 16f, STAR)) } - field("Fee", text(both(proposal.fee), 16f, STAR)) - field("Total", text(both(proposal.total), 17f, STAR, strong)) + proposal.memo?.takeIf { it.isNotEmpty() }?.let { field("Note", it) } + field("Fee", both(proposal.fee)) + field("Total", both(proposal.total), TextKind.STRONG) } val seen = "This payment is public. Anyone can see the amount and the address it goes to. The rest of your money stays private." when (proposal.recipient) { WalletRecipientKind.PUBLIC -> seen WalletRecipientKind.TEX -> "$seen It goes in two steps, through a one-time public address of yours, so the fee covers two transactions." WalletRecipientKind.PRIVATE -> null - }?.let { add(text(it, 16f, STAR), 12) } + }?.let { add(text(it), 12) } } if (usdPerZec != null && !isRequest && !isShield) { - add(text("Exactly ${Format.zec(proposal.zatoshis)} ZEC is sent. Its dollar value moves with ZEC’s price after that.", 15f, DUST), 12) + add(text("Exactly ${Format.zec(proposal.zatoshis)} ZEC is sent. Its dollar value moves with ZEC’s price after that.", TextKind.DUST), 12) } - if (error != null) add(text(error, 16f, CINNABAR), 16) + if (error != null) add(text(error, color = Theme.danger), 16) val spinner = ProgressBar(activity).apply { visibility = View.GONE } add(spinner, 16) if (!canSend) { - add(button("Close", false) { finish(null) }, 20) + add(Kit.button(activity, "Close", Kit.ButtonKind.QUIET) { finish(null) }, 20) return } lateinit var sendButton: Button @@ -229,7 +172,7 @@ object ConfirmSheet { label != null && label.length <= Format.BUTTON_NAME -> "Pay $label $big" else -> "Pay $big" } - sendButton = button(payTitle, true) { + sendButton = Kit.button(activity, payTitle) { sendButton.isEnabled = false cancelButton.isEnabled = false spinner.visibility = View.VISIBLE @@ -247,7 +190,7 @@ object ConfirmSheet { } } add(sendButton, 20) - cancelButton = button(if (isShield) "Not now" else "Cancel", false) { finish(null) } + cancelButton = Kit.button(activity, if (isShield) "Not now" else "Cancel", Kit.ButtonKind.QUIET) { finish(null) } add(cancelButton, 4) } diff --git a/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/ContactSheet.kt b/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/ContactSheet.kt index d75b5ff..c0cb5f7 100644 --- a/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/ContactSheet.kt +++ b/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/ContactSheet.kt @@ -1,23 +1,14 @@ package com.principlezerolabs.wizard.wallet import android.app.Activity -import android.app.Dialog -import android.graphics.Typeface -import android.graphics.drawable.GradientDrawable -import android.view.Gravity import android.view.View -import android.view.ViewGroup.LayoutParams.MATCH_PARENT -import android.view.ViewGroup.LayoutParams.WRAP_CONTENT -import android.view.WindowManager -import android.widget.LinearLayout -import android.widget.TextView /** * The native sheet that saves a change to a contact (spec §7, issue zspace#335): * the name and the full address it will be paired with, then Save or Cancel. * Only this sheet writes contacts, so a contact name on the confirmation - * sheet is one the user saw beside that address here. Plain look, like the - * confirmation sheet. Call on the UI thread; `onResult` runs on it too. + * sheet is one the user saw beside that address here. Drawn with [Kit], like + * the confirmation sheet. Call on the UI thread; `onResult` runs on it too. */ object ContactSheet { /** One change for the user to approve. `was` is the old name or address, if it changes. */ @@ -35,50 +26,11 @@ object ContactSheet { ) fun show(activity: Activity, change: Change, onResult: (Boolean) -> Unit) { - Theme.use(activity) - val density = activity.resources.displayMetrics.density - fun dp(v: Int) = (v * density).toInt() - val dialog = Dialog(activity) - dialog.setCancelable(false) - val body = LinearLayout(activity).apply { - orientation = LinearLayout.VERTICAL - setPadding(dp(20), dp(20), dp(20), dp(28)) - background = GradientDrawable().apply { - setColor(Theme.sheet) - val r = dp(20).toFloat() - cornerRadii = floatArrayOf(r, r, r, r, 0f, 0f, 0f, 0f) - } - } - dialog.setContentView(body) - dialog.window?.apply { - setLayout(MATCH_PARENT, WRAP_CONTENT) - setGravity(Gravity.BOTTOM) - setBackgroundDrawableResource(android.R.color.transparent) - setDimAmount(0.6f) - // Who the user pays: keep it out of the recent-apps preview. - addFlags(WindowManager.LayoutParams.FLAG_SECURE) - } - - val bodyFace = Face.of(activity, Face.BODY) - val strong = Face.of(activity, Face.BUTTON) - - fun text(s: String, size: Float, color: Int, typeface: Typeface = bodyFace) = TextView(activity).apply { - text = s - textSize = size - setTextColor(color) - this.typeface = typeface - setPadding(0, dp(2), 0, dp(2)) - } - - fun add(v: View, top: Int = 12) = - body.addView(v, LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT).apply { topMargin = dp(top) }) - - fun field(label: String, value: View) { - add(text(label, 13f, Theme.muted, Face.of(activity, Face.LABEL)), 14) - add(value, 2) - } - - fun mono(s: String) = text(Format.grouped(s), 13f, Theme.text, Face.of(activity, Face.MONO)).apply { setTextIsSelectable(true) } + // Who the user pays: the sheet keeps it out of the recent-apps preview. + val (dialog, body) = Kit.bottomSheet(activity) + fun add(v: View, top: Int = 12) = Kit.add(body, v, top) + fun mono(s: String) = + Kit.text(activity, Format.grouped(s), TextKind.MONO).apply { setTextIsSelectable(true) } var done = false fun finish(ok: Boolean) { @@ -88,16 +40,22 @@ object ContactSheet { onResult(ok) } - add(text(change.title, 28f, Theme.text, Face.of(activity, Face.TITLE)), 0) - field("Name", text(change.name, 17f, Theme.text, strong)) + add(Kit.text(activity, change.title, TextKind.TITLE), 0) + add(Kit.detail(activity, "Name", change.name, TextKind.STRONG), 14) change.was?.let { (label, value) -> - field(label, if (change.wasAddress) mono(value) else text(value, 16f, Theme.muted)) + add( + Kit.detail( + activity, label, + if (change.wasAddress) mono(value) else Kit.text(activity, value, color = Theme.muted), + ), + 14, + ) } - change.zcashName?.let { field(".zcash name", text(it, 16f, Theme.text)) } - field(change.addressLabel, mono(change.address)) - change.note?.let { add(text(it, 15f, Theme.muted), 14) } - add(Face.button(activity, change.confirm, filled = true) { finish(true) }, 20) - add(Face.button(activity, "Cancel", filled = false) { finish(false) }, 4) + change.zcashName?.let { add(Kit.detail(activity, ".zcash name", it), 14) } + add(Kit.detail(activity, change.addressLabel, mono(change.address)), 14) + change.note?.let { add(Kit.text(activity, it, TextKind.DUST), 14) } + add(Kit.button(activity, change.confirm) { finish(true) }, 20) + add(Kit.button(activity, "Cancel", Kit.ButtonKind.QUIET) { finish(false) }, 4) dialog.show() } } diff --git a/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/Face.kt b/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/Face.kt index f1c2357..84c14c7 100644 --- a/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/Face.kt +++ b/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/Face.kt @@ -1,16 +1,14 @@ package com.principlezerolabs.wizard.wallet import android.app.Activity -import android.graphics.Color import android.graphics.Typeface -import android.graphics.drawable.GradientDrawable import android.util.Log -import android.widget.Button /** * The same faces as `mobile/src/theme.ts`. Gradle copies those files into this * module's assets (`copyWizardFaces`). [Typeface.create] does not see Expo's * JavaScript names, and this library does not compile against React Native. + * Screens take these through [Kit] and [TextKind]. */ object Face { const val TITLE = "Fraunces_400Regular" @@ -46,31 +44,4 @@ object Face { /** Fraunces when the amount setting is serif, otherwise Figtree. */ fun display(activity: Activity): Typeface = of(activity, if (WalletSettings.serifAmount) TITLE else BODY) - - fun dp(activity: Activity, v: Int) = (v * activity.resources.displayMetrics.density).toInt() - - fun capsule(activity: Activity, color: Int) = GradientDrawable().apply { - setColor(color) - cornerRadius = dp(activity, 999).toFloat() - } - - /** A full-width action: Figtree SemiBold 17, 52dp tall, a capsule when filled. */ - fun button(activity: Activity, label: String, filled: Boolean, onClick: () -> Unit) = - Button(activity).apply { - text = label - isAllCaps = false - textSize = 17f - typeface = of(activity, BUTTON) - includeFontPadding = false - minimumHeight = dp(activity, 52) - setPadding(dp(activity, 20), 0, dp(activity, 20), 0) - setTextColor(if (filled) Theme.buttonText else Theme.text) - if (filled) { - background = capsule(activity, Theme.buttonBackground) - } else { - background = null - setBackgroundColor(Color.TRANSPARENT) - } - setOnClickListener { onClick() } - } } diff --git a/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/Kit.kt b/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/Kit.kt new file mode 100644 index 0000000..6a2112e --- /dev/null +++ b/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/Kit.kt @@ -0,0 +1,322 @@ +package com.principlezerolabs.wizard.wallet + +import android.annotation.SuppressLint +import android.app.Activity +import android.app.Dialog +import android.graphics.Color +import android.graphics.drawable.GradientDrawable +import android.graphics.drawable.InsetDrawable +import android.view.Gravity +import android.view.View +import android.view.ViewGroup.LayoutParams.MATCH_PARENT +import android.view.ViewGroup.LayoutParams.WRAP_CONTENT +import android.view.WindowManager +import android.widget.Button +import android.widget.EditText +import android.widget.LinearLayout +import android.widget.Switch +import android.widget.TextView + +// The native screens' building blocks: the same type, sizes, buttons, rows +// and tabs as the React Native components in mobile/src/components, so a +// native sheet looks like the screen it opened from. Change the look here, +// not on a screen. Colours are [Theme] (WalletSettings.kt), faces [Face]. +// +// The numbers in [Size], [Radius] and [Space] are copies of +// mobile/src/theme.ts, under the same names. mobile/src/native-kit.test.ts +// fails when one stops matching, so change both together. Kit.swift is the +// iOS twin of this file. + +/** Type sizes in sp, from theme.ts `size`. */ +@Suppress("ConstPropertyName") +object Size { + const val title = 28f + const val body = 16f + const val dust = 15f + const val label = 13f + const val mono = 13f + const val monoLarge = 16f + const val button = 17f + const val tab = 15f + const val badge = 11f +} + +/** Corner radii in dp, from theme.ts `radius`. */ +@Suppress("ConstPropertyName") +object Radius { + const val field = 14 + const val sheetTop = 28 +} + +/** Spacing and control sizes in dp, from theme.ts `space`. */ +@Suppress("ConstPropertyName") +object Space { + const val gutter = 20 + const val touch = 48 + const val button = 52 + const val pillInset = 4 +} + +/** The text kinds. The first five are React Native's `T` kinds. */ +enum class TextKind(val face: String, val size: Float, val muted: Boolean = false) { + /** Fraunces 28: a screen's title. */ + TITLE(Face.TITLE, Size.title), + + /** Figtree 16 in the text colour. */ + BODY(Face.BODY, Size.body), + + /** Figtree 15, muted: a line under a figure or a block of text. */ + DUST(Face.BODY, Size.dust, muted = true), + + /** Figtree Medium 13, muted: a row's name, a step count. */ + LABEL(Face.LABEL, Size.label, muted = true), + + /** Plex Mono 13: an address or key. */ + MONO(Face.MONO, Size.mono), + + /** Plex Mono 16: a recovery-phrase word, or what is typed into a secret field. */ + MONO_LARGE(Face.MONO, Size.monoLarge), + + /** Figtree SemiBold 17: a value that matters most, such as a total or a name. */ + STRONG(Face.BUTTON, Size.button), +} + +/** + * React Native's press feedback on any view: dims to 0.8 while pressed and + * fades to 0.45 when disabled. Plain Android buttons show neither. + */ +@SuppressLint("AppCompatCustomView") +class KitButton(activity: Activity) : Button(activity) { + init { + isAllCaps = false + includeFontPadding = false + // No Material lift or shadow: the RN buttons are flat. + stateListAnimator = null + } + + override fun drawableStateChanged() { + super.drawableStateChanged() + alpha = when { + !isEnabled -> 0.45f + isPressed -> 0.8f + else -> 1f + } + } +} + +object Kit { + enum class ButtonKind { PRIMARY, SECONDARY, QUIET } + + fun dp(activity: Activity, v: Int) = (v * activity.resources.displayMetrics.density).toInt() + + /** A filled shape with rounded corners; `radius` in dp (999 for a capsule). */ + fun rounded(activity: Activity, color: Int, radius: Int) = GradientDrawable().apply { + setColor(color) + cornerRadius = dp(activity, radius).toFloat() + } + + private fun capsule(activity: Activity, color: Int) = rounded(activity, color, 999) + + /** Words in one of the kit's kinds, in its colour or in `color`. */ + fun text(activity: Activity, s: String, kind: TextKind = TextKind.BODY, color: Int? = null) = + TextView(activity).apply { + text = s + textSize = kind.size + typeface = Face.of(activity, kind.face) + setTextColor(color ?: if (kind.muted) Theme.muted else Theme.text) + } + + /** + * React Native's `Button`: a 52dp capsule in Figtree SemiBold 17. + * PRIMARY is the one filled button on a screen. SECONDARY has a hairline + * edge. QUIET is words only, for Cancel and Not now. `danger` gives a + * non-primary button cinnabar words, for an action that removes something. + */ + fun button( + activity: Activity, + label: String, + kind: ButtonKind = ButtonKind.PRIMARY, + danger: Boolean = false, + onClick: () -> Unit, + ): Button = KitButton(activity).apply { + text = label + textSize = Size.button + typeface = Face.of(activity, Face.BUTTON) + minimumHeight = dp(activity, Space.button) + minHeight = dp(activity, Space.button) + setPadding(dp(activity, 20), 0, dp(activity, 20), 0) + setTextColor( + when { + kind == ButtonKind.PRIMARY -> Theme.buttonText + danger -> Theme.danger + else -> Theme.text + }, + ) + background = when (kind) { + ButtonKind.PRIMARY -> capsule(activity, Theme.buttonBackground) + ButtonKind.SECONDARY -> capsule(activity, Color.TRANSPARENT).apply { + setStroke(dp(activity, 1), Theme.line) + } + ButtonKind.QUIET -> null + } + if (kind == ButtonKind.QUIET) setBackgroundColor(Color.TRANSPARENT) + setOnClickListener { onClick() } + } + + /** Gold words that lead somewhere, such as "Where do I find it?" (RN's strong `HeaderLink`). */ + fun link(activity: Activity, label: String, onClick: () -> Unit): Button = KitButton(activity).apply { + text = label + textSize = Size.button + typeface = Face.of(activity, Face.BUTTON) + setTextColor(Theme.accent) + setBackgroundColor(Color.TRANSPARENT) + minimumHeight = dp(activity, Space.touch) + minHeight = dp(activity, Space.touch) + setOnClickListener { onClick() } + } + + /** A small raised capsule: Paste, Scan, a word suggestion (`mono`). */ + fun chip(activity: Activity, label: String, mono: Boolean = false, onClick: () -> Unit): Button = + KitButton(activity).apply { + text = label + textSize = if (mono) Size.monoLarge else Size.button + typeface = Face.of(activity, if (mono) Face.MONO else Face.BUTTON) + setTextColor(Theme.text) + background = capsule(activity, Theme.raised) + minimumHeight = dp(activity, Space.touch) + minHeight = dp(activity, Space.touch) + setPadding(dp(activity, 16), 0, dp(activity, 16), 0) + setOnClickListener { onClick() } + } + + /** A word to pick from a grid, such as the backup check's choices. */ + fun wordChoice(activity: Activity, word: String, onClick: () -> Unit): Button = KitButton(activity).apply { + text = word + textSize = Size.monoLarge + typeface = Face.of(activity, Face.MONO) + setTextColor(Theme.text) + background = rounded(activity, Theme.raised, Radius.field) + minimumHeight = dp(activity, Space.touch) + minHeight = dp(activity, Space.touch) + setPadding(dp(activity, 16), dp(activity, 12), dp(activity, 16), dp(activity, 12)) + setOnClickListener { onClick() } + } + + /** + * React Native's `Tabs` with `variant="pill"`: a sheet-coloured track, the + * chosen word in the text colour on a raised pill, the others muted. + * Accent is never a fill. `onSelect` gets the index of a tab that wasn't chosen. + */ + fun pillTabs(activity: Activity, labels: List, selected: Int, onSelect: (Int) -> Unit) = + LinearLayout(activity).apply { + val inset = dp(activity, Space.pillInset) + orientation = LinearLayout.HORIZONTAL + gravity = Gravity.CENTER_VERTICAL + background = capsule(activity, Theme.sheet) + // The track's inset sits inside the 48dp minimum, so each tab's target + // is the full height, as in React Native; the pill itself stays inset. + setPadding(inset, 0, inset, 0) + minimumHeight = dp(activity, Space.touch) + labels.forEachIndexed { i, label -> + val on = i == selected + addView(KitButton(activity).apply { + text = label + textSize = Size.tab + typeface = Face.of(activity, Face.BUTTON) + maxLines = 1 + setTextColor(if (on) Theme.text else Theme.muted) + background = if (on) InsetDrawable(capsule(activity, Theme.raised), 0, inset, 0, inset) else null + minimumHeight = dp(activity, Space.touch) + minHeight = dp(activity, Space.touch) + isFocusable = false + isSelected = on + contentDescription = if (on) "$label, selected" else label + setOnClickListener { if (!on) onSelect(i) } + }, LinearLayout.LayoutParams(0, WRAP_CONTENT, 1f).apply { + if (i > 0) marginStart = inset + }) + } + } + + /** A named value on a review sheet: the name in a label, the value under it. */ + fun detail(activity: Activity, name: String, value: View) = LinearLayout(activity).apply { + orientation = LinearLayout.VERTICAL + addView(text(activity, name, TextKind.LABEL)) + addView(value, LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT).apply { topMargin = dp(activity, 4) }) + } + + /** A row whose value is plain words, in `kind` (STRONG for a total). */ + fun detail(activity: Activity, name: String, value: String, kind: TextKind = TextKind.BODY) = + detail(activity, name, text(activity, value, kind)) + + /** React Native's `TestnetBadge`. Only the test network is named (issue #10). */ + fun testnetBadge(activity: Activity) = TextView(activity).apply { + text = "TESTNET" + textSize = Size.badge + typeface = Face.of(activity, Face.BUTTON) + letterSpacing = 0.05f + setTextColor(Theme.onAccent) + setPadding(dp(activity, 8), dp(activity, 2), dp(activity, 8), dp(activity, 2)) + background = capsule(activity, Theme.accent) + } + + /** + * The look of React Native's `TextField` on an [EditText]: a raised ground, + * Plex Mono 16 (every native field takes a secret), a faint hint. + */ + fun field(activity: Activity, edit: EditText) = edit.apply { + setTextColor(Theme.text) + setHintTextColor(Theme.faint) + typeface = Face.of(activity, Face.MONO) + textSize = Size.monoLarge + background = rounded(activity, Theme.raised, Radius.field) + minimumHeight = dp(activity, Space.touch) + setPadding(dp(activity, 16), dp(activity, 14), dp(activity, 16), dp(activity, 14)) + } + + /** A switch with its words, in the body type. */ + fun switch(activity: Activity, label: String, on: Boolean) = Switch(activity).apply { + text = label + textSize = Size.body + typeface = Face.of(activity, Face.BODY) + setTextColor(Theme.text) + isChecked = on + } + + /** + * A sheet over the app, from the bottom of the screen, as the pay + * confirmation and contact sheets are: the sheet colour, its top corners + * rounded, a dim behind, and FLAG_SECURE so what it shows stays out of the + * recent-apps preview. Add views to the column it returns. + */ + fun bottomSheet(activity: Activity): Pair { + Theme.use(activity) + val dialog = Dialog(activity) + dialog.setCancelable(false) + val gutter = dp(activity, Space.gutter) + val body = LinearLayout(activity).apply { + orientation = LinearLayout.VERTICAL + setPadding(gutter, gutter, gutter, dp(activity, 28)) + background = GradientDrawable().apply { + setColor(Theme.sheet) + val r = dp(activity, Radius.sheetTop).toFloat() + cornerRadii = floatArrayOf(r, r, r, r, 0f, 0f, 0f, 0f) + } + } + dialog.setContentView(body) + dialog.window?.apply { + setLayout(MATCH_PARENT, WRAP_CONTENT) + setGravity(Gravity.BOTTOM) + setBackgroundDrawableResource(android.R.color.transparent) + setDimAmount(0.6f) + addFlags(WindowManager.LayoutParams.FLAG_SECURE) + } + return dialog to body + } + + /** Adds `v` to a column at full width, `top` dp below what's above it. */ + fun add(column: LinearLayout, v: View, top: Int = 12) = + column.addView(v, LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT).apply { + topMargin = (top * column.resources.displayMetrics.density).toInt() + }) +} diff --git a/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/PhraseScreens.kt b/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/PhraseScreens.kt index 4d13a6a..38453ae 100644 --- a/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/PhraseScreens.kt +++ b/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/PhraseScreens.kt @@ -7,7 +7,6 @@ import android.content.Context import android.graphics.Canvas import android.graphics.Color import android.graphics.Paint -import android.graphics.drawable.GradientDrawable import android.text.Editable import android.text.InputType import android.text.TextWatcher @@ -26,7 +25,6 @@ import android.widget.GridLayout import android.widget.LinearLayout import android.widget.NumberPicker import android.widget.ScrollView -import android.widget.Switch import android.widget.TextView import java.text.DateFormatSymbols import java.util.Calendar @@ -83,14 +81,9 @@ private class QrView(context: Context, private val qr: WalletQr) : View(context) * Native screens for the recovery phrase: show (with the backup check) and * restore. JavaScript never sees the words. Every screen sets FLAG_SECURE, so * screenshots, screen recording and the recent-apps preview show nothing. - * Colours come from the app's theme ([Theme], WalletSettings.kt). Call on the UI thread. + * Drawn with [Kit]; colours from the app's theme ([Theme]). Call on the UI thread. */ object PhraseScreens { - private val NIGHT get() = Theme.background - private val RAISED get() = Theme.raised - private val STAR get() = Theme.text - private val DUST get() = Theme.muted - private val CINNABAR get() = Theme.danger private const val TOTAL = 24 /** Sapling's activation (October 2018): no wallet has funds from before. */ @@ -107,16 +100,16 @@ object PhraseScreens { val dialog = Dialog(activity, android.R.style.Theme_Black_NoTitleBar_Fullscreen) val body = LinearLayout(activity).apply { orientation = LinearLayout.VERTICAL - setPadding(dp(20), dp(28), dp(20), dp(28)) + setPadding(dp(Space.gutter), dp(28), dp(Space.gutter), dp(28)) } init { Theme.use(activity) dialog.window?.apply { setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE) - decorView.setBackgroundColor(NIGHT) - statusBarColor = NIGHT - navigationBarColor = NIGHT + decorView.setBackgroundColor(Theme.background) + statusBarColor = Theme.background + navigationBarColor = Theme.background // Dark bar icons on a light screen (design guide §4a). val bars = WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS or WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS @@ -124,7 +117,7 @@ object PhraseScreens { } dialog.setCancelable(false) val scroll = ScrollView(activity).apply { - setBackgroundColor(NIGHT) + setBackgroundColor(Theme.background) clipToPadding = false addView(body, MATCH_PARENT, WRAP_CONTENT) } @@ -144,40 +137,21 @@ object PhraseScreens { fun clear() = body.removeAllViews() - fun title(s: String) = TextView(activity).apply { - text = s - textSize = 28f - setTextColor(STAR) - typeface = Face.of(activity, Face.TITLE) + fun title(s: String) = Kit.text(activity, s, TextKind.TITLE).apply { setPadding(0, dp(6), 0, dp(6)) }.also { body.addView(it) } - fun text(s: String, size: Float = 16f, color: Int = DUST, bold: Boolean = false): TextView = - TextView(activity).apply { - text = s - textSize = size - setTextColor(color) - typeface = Face.of( - activity, - when { - bold -> Face.BUTTON - size <= 14f -> Face.LABEL - else -> Face.BODY - }, - ) + /** Words under the title. Explanations here are muted unless `color` says otherwise. */ + fun text(s: String, kind: TextKind = TextKind.BODY, color: Int = Theme.muted): TextView = + Kit.text(activity, s, kind, color).apply { setPadding(0, dp(6), 0, dp(6)) }.also { body.addView(it) } - fun rounded(color: Int, radius: Int = 12) = GradientDrawable().apply { - setColor(color) - cornerRadius = dp(radius).toFloat() - } - fun primary(label: String, onClick: () -> Unit): Button = - Face.button(activity, label, filled = true, onClick).also { addSpaced(it) } + Kit.button(activity, label, onClick = onClick).also { addSpaced(it) } fun secondary(label: String, onClick: () -> Unit): Button = - Face.button(activity, label, filled = false, onClick).also { addSpaced(it) } + Kit.button(activity, label, Kit.ButtonKind.QUIET, onClick = onClick).also { addSpaced(it) } fun addSpaced(v: View) { body.addView(v, LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT).apply { topMargin = dp(12) }) @@ -187,22 +161,14 @@ object PhraseScreens { fun wordCell(index: Int, word: String) = LinearLayout(activity).apply { orientation = LinearLayout.HORIZONTAL gravity = Gravity.CENTER_VERTICAL - background = rounded(RAISED, 14) + background = Kit.rounded(activity, Theme.raised, Radius.field) setPadding(dp(12), dp(12), dp(12), dp(12)) - minimumHeight = dp(48) - addView(TextView(activity).apply { - text = "${index + 1}" - typeface = Face.of(activity, Face.MONO) - textSize = 13f - setTextColor(DUST) + minimumHeight = dp(Space.touch) + addView(Kit.text(activity, "${index + 1}", TextKind.MONO, Theme.muted).apply { gravity = Gravity.END minWidth = dp(24) }) - addView(TextView(activity).apply { - text = word - typeface = Face.of(activity, Face.MONO) - textSize = 16f - setTextColor(STAR) + addView(Kit.text(activity, word, TextKind.MONO_LARGE).apply { setPadding(dp(8), 0, 0, 0) }) } @@ -232,7 +198,7 @@ object PhraseScreens { s.title("Your recovery phrase") s.text("Write these 24 words on paper, in order, and keep it somewhere safe. Anyone who has them can take your money, and ${WalletSettings.appName} can't recover them for you.") s.wordGrid(words) - s.text("Screenshots are blocked here. Don't save the words in notes, email or a password app that syncs.", 15f) + s.text("Screenshots are blocked here. Don't save the words in notes, email or a password app that syncs.", TextKind.DUST) if (backup) { s.primary("I've written them down") { checkStep(s, words, onBack = { wordsStep() }, onPassed = { finish(true) }) } s.secondary("Not now") { finish(false) } @@ -269,11 +235,8 @@ object PhraseScreens { topMargin = s.dp(12) bottomMargin = s.dp(12) }) - s.text("On the other phone: ${WalletSettings.appName} → I have a wallet → Viewing key → Scan.", 15f) - val keyText = s.text(key, 13f, STAR).apply { - typeface = Face.of(activity, Face.MONO) - visibility = View.GONE - } + s.text("On the other phone: ${WalletSettings.appName} → I have a wallet → Viewing key → Scan.", TextKind.DUST) + val keyText = s.text(key, TextKind.MONO, Theme.text).apply { visibility = View.GONE } lateinit var reveal: Button reveal = s.secondary("Show it as text") { keyText.visibility = View.VISIBLE @@ -282,7 +245,7 @@ object PhraseScreens { // The text sits under its button. s.body.removeView(keyText) s.body.addView(keyText) - s.text("Screenshots are blocked here.", 15f) + s.text("Screenshots are blocked here.", TextKind.DUST) s.primary("Done") { finish() } s.dialog.setOnKeyListener { _, code, e -> if (code == KeyEvent.KEYCODE_BACK && e.action == KeyEvent.ACTION_UP) finish() @@ -298,28 +261,18 @@ object PhraseScreens { s.clear() s.title("Check your copy") val pos = positions[step] - s.text("Which is word ${pos + 1}?", 16f, STAR) - s.text("${step + 1} of ${positions.size}", 13f) + s.text("Which is word ${pos + 1}?", color = Theme.text) + s.text("${step + 1} of ${positions.size}", TextKind.LABEL) val answer = words[pos] val choices = (listOf(answer) + words.toSet().minus(answer).shuffled().take(5)).shuffled() val grid = GridLayout(s.activity).apply { columnCount = 2 } choices.forEachIndexed { i, w -> - val b = Button(s.activity).apply { - text = w - isAllCaps = false - typeface = Face.of(s.activity, Face.MONO) - textSize = 16f - setTextColor(STAR) - background = s.rounded(RAISED, 14) - minimumHeight = s.dp(48) - setPadding(s.dp(16), s.dp(12), s.dp(16), s.dp(12)) - setOnClickListener { - if (w == answer) { - step += 1 - if (step == positions.size) onPassed() else render(false) - } else { - render(true) - } + val b = Kit.wordChoice(s.activity, w) { + if (w == answer) { + step += 1 + if (step == positions.size) onPassed() else render(false) + } else { + render(true) } } grid.addView(b, GridLayout.LayoutParams(GridLayout.spec(i / 2), GridLayout.spec(i % 2, 1f)).apply { @@ -328,7 +281,7 @@ object PhraseScreens { }) } s.addSpaced(grid) - if (wrong) s.text("That's not word ${pos + 1}. Look at what you wrote down and try again.", 16f, CINNABAR) + if (wrong) s.text("That's not word ${pos + 1}. Look at what you wrote down and try again.", color = Theme.danger) s.secondary("Back to the words") { onBack() } } render(false) @@ -401,33 +354,9 @@ object PhraseScreens { // Same choice as the React Native pill tabs: a sheet track, a raised pill, // the chosen word in the text colour, the other muted. fun tabs() { - val row = LinearLayout(activity).apply { - orientation = LinearLayout.HORIZONTAL - gravity = Gravity.CENTER_VERTICAL - background = s.rounded(Theme.sheet, 999) - setPadding(s.dp(4), s.dp(4), s.dp(4), s.dp(4)) - minimumHeight = s.dp(48) - } - for ((label, isKey) in listOf("Recovery phrase" to false, "Viewing key" to true)) { - val on = isKey == viewingKey - row.addView(Button(activity).apply { - text = label - isAllCaps = false - textSize = 15f - typeface = Face.of(activity, Face.BUTTON) - includeFontPadding = false - setTextColor(if (on) STAR else DUST) - background = if (on) s.rounded(RAISED, 999) else null - minimumHeight = s.dp(40) - isFocusable = false - contentDescription = if (on) "$label, selected" else label - setOnClickListener { - if (isKey != viewingKey) { - viewingKey = isKey - if (isKey) keyStep() else wordStep() - } - } - }, LinearLayout.LayoutParams(0, WRAP_CONTENT, 1f)) + val row = Kit.pillTabs(activity, listOf("Recovery phrase", "Viewing key"), if (viewingKey) 1 else 0) { i -> + viewingKey = i == 1 + if (viewingKey) keyStep() else wordStep() } s.addSpaced(row) } @@ -461,25 +390,16 @@ object PhraseScreens { } s.addSpaced(row) val older = LinearLayout(activity).apply { orientation = LinearLayout.VERTICAL } - val olderSwitch = Switch(activity).apply { - text = "Look for older funds" - textSize = 16f - typeface = Face.of(activity, Face.BODY) - setTextColor(STAR) - isChecked = true - } + val olderSwitch = Kit.switch(activity, "Look for older funds", on = true) older.addView(olderSwitch, LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT)) - older.addView(TextView(activity).apply { - text = if (viewingKey) { - "If this wallet had ZEC before August 2026, some of it may be in an older part of Zcash. Looking for " + - "it takes longer and uses more data." - } else { - "If you used this phrase in another wallet before August 2026, some of your ZEC may be in an older " + - "part of Zcash. Looking for it takes longer and uses more data." - } - textSize = 16f - typeface = Face.of(activity, Face.BODY) - setTextColor(DUST) + val olderNote = if (viewingKey) { + "If this wallet had ZEC before August 2026, some of it may be in an older part of Zcash. Looking for " + + "it takes longer and uses more data." + } else { + "If you used this phrase in another wallet before August 2026, some of your ZEC may be in an older " + + "part of Zcash. Looking for it takes longer and uses more data." + } + older.addView(Kit.text(activity, olderNote, color = Theme.muted).apply { setPadding(0, s.dp(6), 0, s.dp(6)) }) s.addSpaced(older) @@ -491,7 +411,7 @@ object PhraseScreens { month.setOnValueChangedListener { _, _, _ -> showOlder() } year.setOnValueChangedListener { _, _, _ -> showOlder() } showOlder() - val status = s.text("", 16f, CINNABAR) + val status = s.text("", color = Theme.danger) lateinit var restoreButton: Button lateinit var unknownButton: Button lateinit var backButton: Button @@ -501,7 +421,7 @@ object PhraseScreens { backButton.isEnabled = false olderSwitch.isEnabled = false // The restore screen never moves (design guide §6). The words are the signal. - status.setTextColor(DUST) + status.setTextColor(Theme.muted) status.text = "Restoring…" // Read on the UI thread, before the work moves off it. val secret = if (viewingKey) WalletSecret.ViewingKey(key.trim()) else WalletSecret.Phrase(entered.joinToString(" ")) @@ -514,7 +434,7 @@ object PhraseScreens { closed = true s.dialog.dismiss() } else { - status.setTextColor(CINNABAR) + status.setTextColor(Theme.danger) status.text = problem restoreButton.isEnabled = true unknownButton.isEnabled = true @@ -543,15 +463,8 @@ object PhraseScreens { "${WalletSettings.appName} can show this wallet’s money, but paying from it isn’t ready yet. Your " + "phrase stays on this phone, so the wallet can pay once it is.") } - val counter = s.text("", 13f) - val field = EditText(activity).apply { - setHintTextColor(DUST) - setTextColor(STAR) - typeface = Face.of(activity, Face.MONO) - textSize = 16f - background = s.rounded(RAISED, 14) - minimumHeight = s.dp(48) - setPadding(s.dp(16), s.dp(14), s.dp(16), s.dp(14)) + val counter = s.text("", TextKind.LABEL) + val field = Kit.field(activity, EditText(activity)).apply { // No suggestions or learning: the keyboard must not remember the words. inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS @@ -561,7 +474,7 @@ object PhraseScreens { s.addSpaced(field) val suggestions = LinearLayout(activity).apply { orientation = LinearLayout.HORIZONTAL } s.addSpaced(suggestions) - val errorText = s.text("", 16f, CINNABAR) + val errorText = s.text("", color = Theme.danger) lateinit var removeButton: Button lateinit var nextButton: Button // Added after the buttons below, so the field never moves down the screen. @@ -611,18 +524,9 @@ object PhraseScreens { } suggestions.removeAllViews() for (w in matches()) { - suggestions.addView(Button(activity).apply { - text = w - isAllCaps = false - typeface = Face.of(activity, Face.MONO) - textSize = 16f - setTextColor(STAR) - background = s.rounded(RAISED, 999) - minimumHeight = s.dp(48) - setPadding(s.dp(16), 0, s.dp(16), 0) + suggestions.addView(Kit.chip(activity, w, mono = true) { accept(w) }.apply { // Tapping a suggestion must not take focus from the field. isFocusable = false - setOnClickListener { accept(w) } }, LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply { marginEnd = s.dp(8) }) } } @@ -656,12 +560,7 @@ object PhraseScreens { s.secondary("Cancel") { cancel() }.isFocusable = false val advanced = LinearLayout(activity).apply { orientation = LinearLayout.VERTICAL } - val toggle = Switch(activity).apply { - text = "Restore on the test network" - textSize = 16f - typeface = Face.of(activity, Face.BODY) - setTextColor(STAR) - isChecked = network == "testnet" + val toggle = Kit.switch(activity, "Restore on the test network", on = network == "testnet").apply { isFocusable = false setOnCheckedChangeListener { _, on -> network = if (on) "testnet" else "mainnet" @@ -670,11 +569,7 @@ object PhraseScreens { } } advanced.addView(toggle, LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT)) - advanced.addView(TextView(activity).apply { - text = "For developers. Test coins have no value." - textSize = 16f - typeface = Face.of(activity, Face.BODY) - setTextColor(DUST) + advanced.addView(Kit.text(activity, "For developers. Test coins have no value.", color = Theme.muted).apply { setPadding(0, s.dp(6), 0, s.dp(6)) }) lateinit var advancedButton: Button @@ -686,8 +581,8 @@ object PhraseScreens { advancedOpen = !advancedOpen showAdvanced() } - advancedButton.setTextColor(DUST) - advancedButton.textSize = 13f + advancedButton.setTextColor(Theme.muted) + advancedButton.textSize = Size.label advancedButton.typeface = Face.of(activity, Face.LABEL) advancedButton.isFocusable = false s.addSpaced(advanced) @@ -704,14 +599,8 @@ object PhraseScreens { s.text( "A viewing key lets ${WalletSettings.appName} see a wallet’s balance and payments. It can’t spend, so " + "this wallet won’t be able to pay.") - val field = EditText(activity).apply { + val field = Kit.field(activity, EditText(activity)).apply { hint = "uview1…" - setHintTextColor(DUST) - setTextColor(STAR) - typeface = Face.of(activity, Face.MONO) - textSize = 16f - background = s.rounded(RAISED, 14) - setPadding(s.dp(16), s.dp(14), s.dp(16), s.dp(14)) // No suggestions or learning: the keyboard must not remember the key. inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS @@ -722,7 +611,7 @@ object PhraseScreens { setText(key) } s.addSpaced(field) - val errorText = s.text("", 16f, CINNABAR) + val errorText = s.text("", color = Theme.danger) lateinit var nextButton: Button fun showNext() { nextButton.visibility = if (key.isBlank()) View.GONE else View.VISIBLE @@ -736,19 +625,8 @@ object PhraseScreens { showNext() } }) - fun chip(label: String, onClick: () -> Unit) = Button(activity).apply { - text = label - isAllCaps = false - textSize = 17f - typeface = Face.of(activity, Face.BUTTON) - includeFontPadding = false - setTextColor(STAR) - background = s.rounded(RAISED, 999) - minimumHeight = s.dp(48) - setPadding(s.dp(16), 0, s.dp(16), 0) - isFocusable = false - setOnClickListener { onClick() } - } + fun chip(label: String, onClick: () -> Unit) = + Kit.chip(activity, label, onClick = onClick).apply { isFocusable = false } val actions = LinearLayout(activity).apply { orientation = LinearLayout.HORIZONTAL gravity = Gravity.CENTER_VERTICAL @@ -769,18 +647,7 @@ object PhraseScreens { }, LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply { marginStart = s.dp(8) }) } actions.addView(View(activity), LinearLayout.LayoutParams(0, WRAP_CONTENT, 1f)) - val helpButton = Button(activity).apply { - text = "Where do I find it?" - isAllCaps = false - textSize = 17f - typeface = Face.of(activity, Face.BUTTON) - includeFontPadding = false - setTextColor(Theme.accent) - background = null - setBackgroundColor(Color.TRANSPARENT) - minimumHeight = s.dp(48) - isFocusable = false - } + val helpButton = Kit.link(activity, "Where do I find it?") {}.apply { isFocusable = false } actions.addView(helpButton) s.addSpaced(actions) nextButton = s.primary("Next") { diff --git a/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/WalletSettings.kt b/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/WalletSettings.kt index d7cdcdd..b67a802 100644 --- a/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/WalletSettings.kt +++ b/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/WalletSettings.kt @@ -233,9 +233,15 @@ object Theme { val muted get() = WalletSettings.color( "wallet_native_color_muted", "#A3ABCC", "wallet_native_color_light_muted", "#4B5372", light, ) + val faint get() = WalletSettings.color( + "wallet_native_color_faint", "#8790B8", "wallet_native_color_light_faint", "#5A6180", light, + ) val accent get() = WalletSettings.color( "wallet_native_color_accent", "#E3B45C", "wallet_native_color_light_accent", "#7D5B18", light, ) + val onAccent get() = WalletSettings.color( + "wallet_native_color_on_accent", "#0B1026", "wallet_native_color_light_on_accent", "#FCF9F2", light, + ) val danger get() = WalletSettings.color( "wallet_native_color_danger", "#F0806A", "wallet_native_color_light_danger", "#B03A25", light, ) diff --git a/wallet-native/ios/ConfirmSheet.swift b/wallet-native/ios/ConfirmSheet.swift index 5708925..fe98867 100644 --- a/wallet-native/ios/ConfirmSheet.swift +++ b/wallet-native/ios/ConfirmSheet.swift @@ -3,7 +3,7 @@ import UIKit // The confirmation sheet (spec §7). Native code reads the proposal from Rust // by id, so what the user approves is what Rust will build, whatever -// JavaScript showed. Plain system look, no art (design guide §7). +// JavaScript showed. No art (design guide §7); the look is Kit.swift's. enum Format { /// The longest name the review sheet's Pay button shows (issue #19). @@ -64,39 +64,32 @@ struct ConfirmSheet: View { @State private var phase: Phase = .review var body: some View { - ZStack { - Palette.deep.ignoresSafeArea() - VStack(alignment: .leading, spacing: 18) { - HStack { - Text(title).font(Face.title).foregroundColor(Palette.star) - Spacer() - // Only the test network is named (issue #10): mainnet is the default people never need to see. - if WalletSettings.testnet { - Text("TESTNET").font(Font.custom("Figtree-SemiBold", size: 11)).tracking(0.5).foregroundColor(Palette.night) - .padding(.horizontal, 8).padding(.vertical, 3).background(Palette.gold).clipShape(Capsule()) - } - } - details + KitPage(ground: .sheet, scrolls: false, spacing: 18) { + HStack { + Text(title).kit(.title) Spacer() - if case .failed(let message) = phase { - Text(message).font(Face.body).foregroundColor(Palette.cinnabar) - } - if phase == .sending { - HStack(spacing: 10) { - ProgressView().tint(Palette.star) - Text(isShield ? "Making it private…" : "Sending…").font(Face.body).foregroundColor(Palette.dust) - } - .frame(maxWidth: .infinity) - } else if case .failed = phase { - // The engine dropped the proposal, so it can't be sent again from - // here: the user reviews the payment again (zspace#374). - SecondaryButton(title: "Close") { onFinish(nil) } - } else { - PrimaryButton(title: payTitle) { runSend() } - SecondaryButton(title: isShield ? "Not now" : "Cancel") { onFinish(nil) } + // Only the test network is named (issue #10): mainnet is the default people never need to see. + if WalletSettings.testnet { TestnetBadge() } + } + details + Spacer() + if case .failed(let message) = phase { + Text(message).kit(.body, Palette.danger) + } + if phase == .sending { + HStack(spacing: 10) { + ProgressView().tint(Palette.text) + Text(isShield ? "Making it private…" : "Sending…").kit(.body, Palette.muted) } + .frame(maxWidth: .infinity) + } else if case .failed = phase { + // The engine dropped the proposal, so it can't be sent again from + // here: the user reviews the payment again (zspace#374). + KitButton("Close", .quiet) { onFinish(nil) } + } else { + KitButton(payTitle) { runSend() } + KitButton(isShield ? "Not now" : "Cancel", .quiet) { onFinish(nil) } } - .padding(20) } } @@ -131,65 +124,56 @@ struct ConfirmSheet: View { private var shieldDetails: some View { VStack(alignment: .leading, spacing: 14) { VStack(alignment: .leading, spacing: 2) { - Text("Arrived at your exchange address").font(Face.dust).foregroundColor(Palette.dust) - Text(big) - .font(Face.display(40)) - .foregroundColor(Palette.star) - if usdPerZec != nil { Text(small).font(Face.dust).foregroundColor(Palette.dust) } - } - row("From") { Text("Your public exchange address").foregroundColor(Palette.star) } - row("To") { Text("Your private balance").foregroundColor(Palette.star) } - row("Fee") { Text(both(proposal.fee)).foregroundColor(Palette.star) } - row("Private after") { - Text(both(proposal.shielded)).font(Face.button).foregroundColor(Palette.star) + Text("Arrived at your exchange address").kit(.dust) + Text(big).font(Face.display(40)).foregroundColor(Palette.text) + if usdPerZec != nil { Text(small).kit(.dust) } } + DetailRow("From", "Your public exchange address") + DetailRow("To", "Your private balance") + DetailRow("Fee", both(proposal.fee)) + DetailRow("Private after", both(proposal.shielded), .strong) Text("The money stays yours: it moves from your public address to your private balance. Until then anyone can see it, and \(WalletSettings.appName) can’t pay with it.") - .font(Face.dust).foregroundColor(Palette.dust) + .kit(.dust) } } private var paymentDetails: some View { VStack(alignment: .leading, spacing: 14) { VStack(alignment: .leading, spacing: 2) { - Text(big) - .font(Face.display(40)) - .foregroundColor(Palette.star) + Text(big).font(Face.display(40)).foregroundColor(Palette.text) if let usdPerZec, !isRequest { Text("\(small) at 1 ZEC = \(Format.usd(100_000_000, usdPerZec))") - .font(Face.dust).foregroundColor(Palette.dust) + .kit(.dust) } } - row("To") { + DetailRow("To") { VStack(alignment: .leading, spacing: 4) { - if let label { Text(label).font(Face.button).foregroundColor(Palette.star) } + if let label { Text(label).kit(.strong) } ForEach(proposal.to, id: \.self) { a in - Text(Format.grouped(a)).font(Face.monoSmall) - .foregroundColor(Palette.star).textSelection(.enabled) + Text(Format.grouped(a)).kit(.mono).textSelection(.enabled) } if let kind = publicKind { - Text(kind).font(Font.custom("Figtree-SemiBold", size: 13)).foregroundColor(Palette.gold) + Text(kind).font(Face.labelStrong).foregroundColor(Palette.accent) } } } if let memo = shownMemo { - row(isRequest ? "Request" : "Note") { Text(memo).foregroundColor(Palette.star) } + DetailRow(isRequest ? "Request" : "Note", memo) } // A request's big figure is already the fee, its only cost. if !isRequest { - row("Fee") { Text(both(proposal.fee)).foregroundColor(Palette.star) } - row("Total") { - Text(both(proposal.total)).font(Face.button).foregroundColor(Palette.star) - } + DetailRow("Fee", both(proposal.fee)) + DetailRow("Total", both(proposal.total), .strong) } if let note = publicNote { - Text(note).font(Face.body).foregroundColor(Palette.star) + Text(note).kit(.body) } if isRequest { Text("Only the fee leaves your wallet. They pay the request if they choose to.") - .font(Face.dust).foregroundColor(Palette.dust) + .kit(.dust) } else if usdPerZec != nil { Text("Exactly \(Format.zec(proposal.zatoshis)) ZEC is sent. Its dollar value moves with ZEC’s price after that.") - .font(Face.dust).foregroundColor(Palette.dust) + .kit(.dust) } } } @@ -246,13 +230,6 @@ struct ConfirmSheet: View { return usdFirst ? "\(d) · \(z)" : "\(z) · \(d)" } - private func row(_ name: String, @ViewBuilder _ content: () -> Content) -> some View { - VStack(alignment: .leading, spacing: 4) { - Text(name).font(Face.label).foregroundColor(Palette.dust) - content().font(Face.body).foregroundColor(Palette.star) - } - } - private func runSend() { phase = .sending DispatchQueue.global(qos: .userInitiated).async { diff --git a/wallet-native/ios/ContactSheet.swift b/wallet-native/ios/ContactSheet.swift index f0c8b64..c476ba9 100644 --- a/wallet-native/ios/ContactSheet.swift +++ b/wallet-native/ios/ContactSheet.swift @@ -3,8 +3,8 @@ import SwiftUI /// The native sheet that saves a change to a contact (spec §7, issue zspace#335): /// the name and the full address it will be paired with, then Save or /// Cancel. Only this sheet writes contacts, so a contact name on the -/// confirmation sheet is one the user saw beside that address here. Plain -/// look, like the confirmation sheet. +/// confirmation sheet is one the user saw beside that address here. Drawn +/// with Kit.swift, like the confirmation sheet. struct ContactChange { let title: String let name: String @@ -24,40 +24,28 @@ struct ContactSheet: View { let onResult: (Bool) -> Void var body: some View { - ZStack { - Palette.deep.ignoresSafeArea() - VStack(alignment: .leading, spacing: 16) { - Text(change.title).font(Face.title).foregroundColor(Palette.star) - row("Name") { Text(change.name).font(Face.button).foregroundColor(Palette.star) } - if let was = change.was { - row(was.label) { - if change.wasAddress { mono(was.value) } else { Text(was.value).foregroundColor(Palette.dust) } - } + KitPage(ground: .sheet, scrolls: false) { + Text(change.title).kit(.title) + DetailRow("Name", change.name, .strong) + if let was = change.was { + DetailRow(was.label) { + if change.wasAddress { mono(was.value) } else { Text(was.value).kit(.body, Palette.muted) } } - if let z = change.zcashName { - row(".zcash name") { Text(z).foregroundColor(Palette.star) } - } - row(change.addressLabel) { mono(change.address) } - if let note = change.note { - Text(note).font(Face.dust).foregroundColor(Palette.dust) - } - Spacer() - PrimaryButton(title: change.confirm) { onResult(true) } - SecondaryButton(title: "Cancel") { onResult(false) } } - .padding(20) + if let z = change.zcashName { + DetailRow(".zcash name", z) + } + DetailRow(change.addressLabel) { mono(change.address) } + if let note = change.note { + Text(note).kit(.dust) + } + Spacer() + KitButton(change.confirm) { onResult(true) } + KitButton("Cancel", .quiet) { onResult(false) } } } private func mono(_ address: String) -> some View { - Text(Format.grouped(address)).font(Face.monoSmall) - .foregroundColor(Palette.star).textSelection(.enabled) - } - - private func row(_ name: String, @ViewBuilder _ content: () -> Content) -> some View { - VStack(alignment: .leading, spacing: 4) { - Text(name).font(Face.label).foregroundColor(Palette.dust) - content().font(Face.body) - } + Text(Format.grouped(address)).kit(.mono).textSelection(.enabled) } } diff --git a/wallet-native/ios/Kit.swift b/wallet-native/ios/Kit.swift new file mode 100644 index 0000000..7222c7b --- /dev/null +++ b/wallet-native/ios/Kit.swift @@ -0,0 +1,385 @@ +import CoreText +import SwiftUI +import UIKit + +// The native screens' building blocks: the same type, sizes, buttons, rows +// and tabs as the React Native components in mobile/src/components, so a +// native sheet looks like the screen it opened from. Change the look here, +// not on a screen. Colours are `Palette` (WalletSettings.swift). +// +// The numbers in `Size`, `Radius` and `Space` are copies of +// mobile/src/theme.ts, under the same names. mobile/src/native-kit.test.ts +// fails when one stops matching, so change both together. Kit.kt is the +// Android twin of this file. + +/// Type sizes, from theme.ts `size`. +enum Size { + static let title: CGFloat = 28 + static let body: CGFloat = 16 + static let dust: CGFloat = 15 + static let label: CGFloat = 13 + static let mono: CGFloat = 13 + static let monoLarge: CGFloat = 16 + static let button: CGFloat = 17 + static let tab: CGFloat = 15 + static let badge: CGFloat = 11 +} + +/// Corner radii, from theme.ts `radius`. +enum Radius { + static let field: CGFloat = 14 + static let sheetTop: CGFloat = 28 +} + +/// Spacing and control sizes, from theme.ts `space`. +enum Space { + static let gutter: CGFloat = 20 + static let touch: CGFloat = 48 + static let button: CGFloat = 52 + static let pillInset: CGFloat = 4 +} + +/// The same faces as `mobile/src/theme.ts`. Expo's JavaScript names +/// (`Fraunces_400Regular`) are aliases. SwiftUI only finds the PostScript +/// name stored in the file, so the alias draws as the system font. +enum Face { + /// Expo registers these from JavaScript after launch. A sheet opened + /// before that, or a SwiftUI lookup that races it, would still draw the + /// system font. Register the cached files if the faces are not in yet. + private static func ensure() { + guard UIFont(name: "Fraunces-Regular", size: 12) == nil else { return } + guard let caches = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first, + let files = try? FileManager.default.contentsOfDirectory(at: caches, includingPropertiesForKeys: nil) + else { return } + for url in files where url.pathExtension.lowercased() == "ttf" { + CTFontManagerRegisterFontsForURL(url as CFURL, .process, nil) + } + } + + private static func custom(_ name: String, size: CGFloat) -> Font { + ensure() + return Font.custom(name, size: size) + } + + static var title: Font { custom("Fraunces-Regular", size: Size.title) } + static var body: Font { custom("Figtree-Regular", size: Size.body) } + static var dust: Font { custom("Figtree-Regular", size: Size.dust) } + static var label: Font { custom("Figtree-Medium", size: Size.label) } + static var labelStrong: Font { custom("Figtree-SemiBold", size: Size.label) } + static var button: Font { custom("Figtree-SemiBold", size: Size.button) } + static var tab: Font { custom("Figtree-SemiBold", size: Size.tab) } + static var badge: Font { custom("Figtree-SemiBold", size: Size.badge) } + static var mono: Font { custom("IBMPlexMono-Regular", size: Size.mono) } + static var monoLarge: Font { custom("IBMPlexMono-Regular", size: Size.monoLarge) } + + /// A large amount: Fraunces when the app's amount font is serif, otherwise Figtree. + static func display(_ size: CGFloat) -> Font { + custom(WalletSettings.serifAmount ? "Fraunces-Regular" : "Figtree-Regular", size: size) + } +} + +// MARK: - Text + +/// The text kinds. The first five are React Native's `T` kinds. +enum TextKind { + /// Fraunces 28: a screen's title. + case title + /// Figtree 16 in the text colour. + case body + /// Figtree 15, muted: a line under a figure or a block of text. + case dust + /// Figtree Medium 13, muted: a row's name, a step count. + case label + /// Plex Mono 13: an address or key. + case mono + /// Plex Mono 16: a recovery-phrase word, or what is typed into a secret field. + case monoLarge + /// Figtree SemiBold 17: a value that matters most, such as a total or a name. + case strong + + var font: Font { + switch self { + case .title: return Face.title + case .body: return Face.body + case .dust: return Face.dust + case .label: return Face.label + case .mono: return Face.mono + case .monoLarge: return Face.monoLarge + case .strong: return Face.button + } + } + + var color: Color { + switch self { + case .dust, .label: return Palette.muted + default: return Palette.text + } + } +} + +extension View { + /// Draws text in one of the kit's kinds, in its colour or in `color`. + func kit(_ kind: TextKind, _ color: Color? = nil) -> some View { + font(kind.font).foregroundColor(color ?? kind.color) + } + + /// A raised ground for typed text, as React Native's `TextField`. + func kitField(minHeight: CGFloat = Space.touch) -> some View { + padding(.horizontal, 16) + .padding(.vertical, 14) + .frame(minHeight: minHeight) + .background(Palette.raised) + .clipShape(RoundedRectangle(cornerRadius: Radius.field, style: .continuous)) + } + + /// A block set apart from the screen, such as a warning that replaces something hidden. + func kitCard() -> some View { + padding(16) + .frame(maxWidth: .infinity) + .background(Palette.sheet) + .clipShape(RoundedRectangle(cornerRadius: Radius.field, style: .continuous)) + } +} + +// MARK: - Screens + +/// A native screen's ground and margins. `.background` fills a full-screen +/// step (the phrase, restore); `.sheet` is a sheet over the app (pay, contact). +struct KitPage: View { + enum Ground { case background, sheet } + + var ground = Ground.background + /// Scrolls when the content is taller than the screen. + var scrolls = true + var spacing: CGFloat = 16 + @ViewBuilder let content: () -> Content + + var body: some View { + ZStack { + (ground == .sheet ? Palette.sheet : Palette.background).ignoresSafeArea() + if scrolls { + ScrollView { column } + } else { + column + } + } + } + + private var column: some View { + VStack(alignment: .leading, spacing: spacing, content: content) + .padding(Space.gutter) + } +} + +/// A named value on a review sheet: the name in a label, the value under it. +struct DetailRow: View { + let name: String + @ViewBuilder let value: () -> Value + + init(_ name: String, @ViewBuilder value: @escaping () -> Value) { + self.name = name + self.value = value + } + + var body: some View { + VStack(alignment: .leading, spacing: 4) { + Text(name).kit(.label) + value().kit(.body) + } + } +} + +extension DetailRow where Value == Text { + /// A row whose value is plain words, in `kind` (`.strong` for a total). + init(_ name: String, _ text: String, _ kind: TextKind = .body) { + self.init(name) { Text(text).font(kind.font).foregroundColor(kind.color) } + } +} + +/// React Native's `TestnetBadge`. Only the test network is named (issue #10). +struct TestnetBadge: View { + var body: some View { + Text("TESTNET").font(Face.badge).tracking(0.5).foregroundColor(Palette.onAccent) + .padding(.horizontal, 8).padding(.vertical, 2) + .background(Palette.accent).clipShape(Capsule()) + } +} + +// MARK: - Controls + +/// Same feedback as the React Native controls: a pressed control dims, it +/// does not scale; a disabled one fades. +struct PressedFade: ButtonStyle { + @Environment(\.isEnabled) private var enabled + + func makeBody(configuration: Configuration) -> some View { + configuration.label.opacity(enabled ? (configuration.isPressed ? 0.8 : 1) : 0.45) + } +} + +/// React Native's `Button`: a 52-point capsule in Figtree SemiBold 17. +/// `.primary` is the one filled button on a screen. `.secondary` has a +/// hairline edge. `.quiet` is words only, for Cancel and Not now. +struct KitButton: View { + enum Kind { case primary, secondary, quiet } + + let title: String + var kind = Kind.primary + /// Cinnabar words, for an action that removes something (not on a primary button). + var danger = false + /// A spinner in place of the words; the button can't be pressed. + var busy = false + let action: () -> Void + + init( + _ title: String, _ kind: Kind = .primary, danger: Bool = false, busy: Bool = false, + action: @escaping () -> Void + ) { + self.title = title + self.kind = kind + self.danger = danger + self.busy = busy + self.action = action + } + + var body: some View { + Button(action: action) { + ZStack { + if busy { + ProgressView().tint(kind == .primary ? Palette.buttonText : Palette.text) + } else { + Text(title).font(Face.button).foregroundColor(words) + } + } + .padding(.horizontal, 20) + .frame(maxWidth: .infinity, minHeight: Space.button) + .background(kind == .primary ? Palette.buttonBackground : Color.clear) + .overlay( + Capsule().strokeBorder(kind == .secondary ? Palette.line : Color.clear, lineWidth: 1) + ) + .clipShape(Capsule()) + .contentShape(Capsule()) + } + .buttonStyle(PressedFade()) + .disabled(busy) + .accessibilityLabel(title) + } + + private var words: Color { + if kind == .primary { return Palette.buttonText } + return danger ? Palette.danger : Palette.text + } +} + +/// Gold words that lead somewhere, such as "Where do I find it?": React +/// Native's strong `HeaderLink`, as a full touch target. +struct LinkButton: View { + let title: String + let action: () -> Void + + init(_ title: String, action: @escaping () -> Void) { + self.title = title + self.action = action + } + + var body: some View { + Button(action: action) { + Text(title).font(Face.button).foregroundColor(Palette.accent).frame(minHeight: Space.touch) + } + .buttonStyle(PressedFade()) + } +} + +/// A small raised capsule: Paste, Scan, a word suggestion. +struct Chip: View { + let title: String + /// Plex Mono 16 for a phrase word; otherwise Figtree SemiBold 17. + var mono = false + let action: () -> Void + + init(_ title: String, mono: Bool = false, action: @escaping () -> Void) { + self.title = title + self.mono = mono + self.action = action + } + + var body: some View { + Button(action: action) { + Text(title).font(mono ? Face.monoLarge : Face.button).foregroundColor(Palette.text) + .padding(.horizontal, 16) + .frame(minHeight: Space.touch) + .background(Palette.raised) + .clipShape(Capsule()) + } + .buttonStyle(PressedFade()) + } +} + +/// A word to pick from a grid, such as the backup check's choices: Plex Mono +/// on a raised ground, as a phrase word is shown. +struct WordChoice: View { + let word: String + let action: () -> Void + + var body: some View { + Button(action: action) { + Text(word).font(Face.monoLarge).foregroundColor(Palette.text) + .frame(maxWidth: .infinity, minHeight: Space.touch) + .background(Palette.raised) + .clipShape(RoundedRectangle(cornerRadius: Radius.field, style: .continuous)) + } + .buttonStyle(PressedFade()) + } +} + +/// React Native's `Tabs` with `variant="pill"`: a sheet-coloured track, the +/// chosen word in the text colour on a raised pill, the others muted. +/// Accent is never a fill. +struct PillTabs: View { + let items: [(label: String, value: Value)] + @Binding var selection: Value + + var body: some View { + HStack(spacing: Space.pillInset) { + ForEach(items.indices, id: \.self) { i in + let item = items[i] + let on = item.value == selection + Button { + if !on { selection = item.value } + } label: { + Text(item.label).font(Face.tab) + .foregroundColor(on ? Palette.text : Palette.muted) + .lineLimit(1) + .frame(maxWidth: .infinity, minHeight: Space.touch - 2 * Space.pillInset) + .background(on ? Palette.raised : Color.clear) + .clipShape(Capsule()) + // The track's inset sits inside the 48-point minimum, so it is + // part of the target, as in React Native. The pill stays inset. + .padding(.vertical, Space.pillInset) + .contentShape(Rectangle()) + } + .buttonStyle(PressedFade()) + .accessibilityAddTraits(on ? .isSelected : []) + } + } + .padding(.horizontal, Space.pillInset) + .frame(minHeight: Space.touch) + .background(Palette.sheet) + .clipShape(Capsule()) + } +} + +/// A switch with its words, in the body type with an accent track. +struct KitToggle: View { + let title: String + @Binding var isOn: Bool + + init(_ title: String, isOn: Binding) { + self.title = title + _isOn = isOn + } + + var body: some View { + Toggle(title, isOn: $isOn).kit(.body).tint(Palette.accent) + } +} diff --git a/wallet-native/ios/PhraseScreens.swift b/wallet-native/ios/PhraseScreens.swift index a8874e0..8f384a7 100644 --- a/wallet-native/ios/PhraseScreens.swift +++ b/wallet-native/ios/PhraseScreens.swift @@ -1,91 +1,10 @@ -import CoreText import SwiftUI import UIKit import VisionKit // Native screens for the recovery phrase: show (with the backup check) and // restore. JavaScript never sees the words; it only learns how a flow ended. -// Colours come from the app's theme (WalletSettings.swift, Palette). - -/// The same faces as `mobile/src/theme.ts`. Expo's JavaScript names -/// (`Fraunces_400Regular`) are aliases. SwiftUI only finds the PostScript -/// name stored in the file, so the alias draws as the system font. -enum Face { - /// Expo registers these from JavaScript after launch. A sheet opened - /// before that, or a SwiftUI lookup that races it, would still draw the - /// system font. Register the cached files if the faces are not in yet. - private static func ensure() { - guard UIFont(name: "Fraunces-Regular", size: 12) == nil else { return } - guard let caches = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first, - let files = try? FileManager.default.contentsOfDirectory(at: caches, includingPropertiesForKeys: nil) - else { return } - for url in files where url.pathExtension.lowercased() == "ttf" { - CTFontManagerRegisterFontsForURL(url as CFURL, .process, nil) - } - } - - private static func custom(_ name: String, size: CGFloat) -> Font { - ensure() - return Font.custom(name, size: size) - } - - static var title: Font { custom("Fraunces-Regular", size: 28) } - static var body: Font { custom("Figtree-Regular", size: 16) } - static var dust: Font { custom("Figtree-Regular", size: 15) } - static var label: Font { custom("Figtree-Medium", size: 13) } - static var button: Font { custom("Figtree-SemiBold", size: 17) } - static var tab: Font { custom("Figtree-SemiBold", size: 15) } - static var mono: Font { custom("IBMPlexMono-Regular", size: 16) } - static var monoSmall: Font { custom("IBMPlexMono-Regular", size: 13) } - - static func display(_ size: CGFloat) -> Font { - custom(WalletSettings.serifAmount ? "Fraunces-Regular" : "Figtree-Regular", size: size) - } -} - -/// Same press as the React Native button: the control dims, it does not scale. -private struct PressedFade: ButtonStyle { - func makeBody(configuration: Configuration) -> some View { - configuration.label.opacity(configuration.isPressed ? 0.8 : 1) - } -} - -struct PrimaryButton: View { - @Environment(\.isEnabled) private var enabled - let title: String - var disabled = false - let action: () -> Void - private var off: Bool { disabled || !enabled } - var body: some View { - Button(action: action) { - Text(title).font(Face.button) - .padding(.horizontal, 20) - .frame(maxWidth: .infinity, minHeight: 52) - .foregroundColor(Palette.buttonText) - .background(Palette.buttonBackground) - .clipShape(Capsule()) - } - .buttonStyle(PressedFade()) - .disabled(off) - .opacity(off ? 0.45 : 1) - } -} - -struct SecondaryButton: View { - @Environment(\.isEnabled) private var enabled - let title: String - let action: () -> Void - var body: some View { - Button(action: action) { - Text(title).font(Face.button) - .padding(.horizontal, 20) - .frame(maxWidth: .infinity, minHeight: 52) - .foregroundColor(Palette.star) - } - .buttonStyle(PressedFade()) - .opacity(enabled ? 1 : 0.45) - } -} +// The look comes from Kit.swift; colours from the app's theme (Palette). /// Watches for screen recording, mirroring and screenshots while a phrase is /// on screen. iOS can't block screenshots, so the words are hidden while the @@ -114,15 +33,15 @@ struct WordGrid: View { LazyVGrid(columns: [GridItem(.flexible(), spacing: 12), GridItem(.flexible(), spacing: 12)], spacing: 12) { ForEach(Array(words.enumerated()), id: \.offset) { i, w in HStack(spacing: 8) { - Text("\(i + 1)").font(Face.monoSmall).foregroundColor(Palette.dust) + Text("\(i + 1)").kit(.mono, Palette.muted) .frame(width: 24, alignment: .trailing) - Text(w).font(Face.mono).foregroundColor(Palette.star) + Text(w).kit(.monoLarge) Spacer(minLength: 0) } .padding(.vertical, 12).padding(.horizontal, 12) - .frame(minHeight: 48) + .frame(minHeight: Space.touch) .background(Palette.raised) - .clipShape(RoundedRectangle(cornerRadius: 14, style: .continuous)) + .clipShape(RoundedRectangle(cornerRadius: Radius.field, style: .continuous)) } } } @@ -139,35 +58,34 @@ struct PhraseView: View { var body: some View { ZStack { - Palette.night.ignoresSafeArea() + Palette.background.ignoresSafeArea() if checking { BackupCheckView(words: words, onBack: { checking = false }, onPassed: { onDone(true) }) } else { ScrollView { VStack(alignment: .leading, spacing: 16) { - Text("Your recovery phrase").font(Face.title).foregroundColor(Palette.star) + Text("Your recovery phrase").kit(.title) Text( "Write these 24 words on paper, in order, and keep it somewhere safe. Anyone who has them can take your money, and \(WalletSettings.appName) can't recover them for you." ) - .font(Face.body).foregroundColor(Palette.dust) + .kit(.body, Palette.muted) if capture.captured { Text("The words are hidden while the screen is being recorded or mirrored.") - .foregroundColor(Palette.gold).padding().frame(maxWidth: .infinity) - .background(Palette.deep).clipShape(RoundedRectangle(cornerRadius: 12)) + .kit(.body, Palette.accent).kitCard() } else { WordGrid(words: words).privacySensitive() } Text("Don't take a screenshot or save the words in Notes, email or a password app that syncs.") - .font(Face.dust).foregroundColor(Palette.dust) + .kit(.dust) switch mode { case .backup: - PrimaryButton(title: "I've written them down") { checking = true } - SecondaryButton(title: "Not now") { onDone(false) } + KitButton("I've written them down") { checking = true } + KitButton("Not now", .quiet) { onDone(false) } case .show: - PrimaryButton(title: "Done") { onDone(true) } + KitButton("Done") { onDone(true) } } } - .padding(20) + .padding(Space.gutter) } } } @@ -191,32 +109,24 @@ struct BackupCheckView: View { var body: some View { VStack(alignment: .leading, spacing: 16) { - Text("Check your copy").font(Face.title).foregroundColor(Palette.star) + Text("Check your copy").kit(.title) if step < positions.count { - Text("Which is word \(positions[step] + 1)?").font(Face.body).foregroundColor(Palette.star) - Text("\(step + 1) of \(positions.count)").font(Face.label).foregroundColor(Palette.dust) + Text("Which is word \(positions[step] + 1)?").kit(.body) + Text("\(step + 1) of \(positions.count)").kit(.label) LazyVGrid(columns: [GridItem(.flexible(), spacing: 12), GridItem(.flexible(), spacing: 12)], spacing: 12) { ForEach(choices, id: \.self) { w in - Button { - pick(w) - } label: { - Text(w).font(Face.mono).foregroundColor(Palette.star) - .frame(maxWidth: .infinity, minHeight: 48) - .background(Palette.raised) - .clipShape(RoundedRectangle(cornerRadius: 14, style: .continuous)) - } - .buttonStyle(PressedFade()) + WordChoice(word: w) { pick(w) } } } if wrong { Text("That's not word \(positions[step] + 1). Look at what you wrote down and try again.") - .font(Face.body).foregroundColor(Palette.cinnabar) + .kit(.body, Palette.danger) } } Spacer() - SecondaryButton(title: "Back to the words", action: onBack) + KitButton("Back to the words", .quiet, action: onBack) } - .padding(20) + .padding(Space.gutter) .onAppear(perform: start) } @@ -278,34 +188,27 @@ struct ViewingKeyView: View { @State private var showText = false var body: some View { - ZStack { - Palette.night.ignoresSafeArea() - ScrollView { - VStack(alignment: .leading, spacing: 16) { - Text("Your viewing key").font(Face.title).foregroundColor(Palette.star) - Text( - "Anyone who scans this sees this wallet’s balance and every payment it sends or receives, for good. It can’t spend. Show it only to your own phone or a wallet you trust." - ) - .font(Face.body).foregroundColor(Palette.dust) - if capture.captured { - Text("The key is hidden while the screen is being recorded or mirrored.") - .foregroundColor(Palette.gold).padding().frame(maxWidth: .infinity) - .background(Palette.deep).clipShape(RoundedRectangle(cornerRadius: 12)) - } else { - QRCodeView(qr: qr).privacySensitive().frame(maxWidth: 320).frame(maxWidth: .infinity) - Text("On the other phone: \(WalletSettings.appName) → I have a wallet → Viewing key → Scan.") - .font(Face.dust).foregroundColor(Palette.dust) - if showText { - Text(key).font(Face.monoSmall).foregroundColor(Palette.star) - .privacySensitive() - } else { - SecondaryButton(title: "Show it as text") { showText = true } - } - } - PrimaryButton(title: "Done", action: onDone) + KitPage { + Text("Your viewing key").kit(.title) + Text( + "Anyone who scans this sees this wallet’s balance and every payment it sends or receives, for good. It can’t spend. Show it only to your own phone or a wallet you trust." + ) + .kit(.body, Palette.muted) + if capture.captured { + Text("The key is hidden while the screen is being recorded or mirrored.") + .kit(.body, Palette.accent).kitCard() + } else { + QRCodeView(qr: qr).privacySensitive().frame(maxWidth: 320).frame(maxWidth: .infinity) + Text("On the other phone: \(WalletSettings.appName) → I have a wallet → Viewing key → Scan.") + .kit(.dust) + if showText { + Text(key).kit(.mono) + .privacySensitive() + } else { + KitButton("Show it as text", .quiet) { showText = true } } - .padding(20) } + KitButton("Done", action: onDone) } .alert("That screenshot shows your viewing key", isPresented: $capture.screenshotTaken) { Button("OK", role: .cancel) {} @@ -387,25 +290,19 @@ struct RestoreView: View { private var target: String { kind == .phrase ? network : keyNetworkFound } var body: some View { - ZStack { - Palette.night.ignoresSafeArea() - ScrollView { - VStack(alignment: .leading, spacing: 16) { - if askDate { - dateStep - } else { - if !keyOnly { kindTabs } - if kind == .phrase { wordStep } else { keyStep } - } - if let error { - Text(error).font(Face.body).foregroundColor(Palette.cinnabar) - .fixedSize(horizontal: false, vertical: true) - } - SecondaryButton(title: "Cancel", action: onCancel).disabled(working) - if !askDate && kind == .phrase { advanced } - } - .padding(20) + KitPage { + if askDate { + dateStep + } else { + if !keyOnly { kindTabs } + if kind == .phrase { wordStep } else { keyStep } + } + if let error { + Text(error).kit(.body, Palette.danger) + .fixedSize(horizontal: false, vertical: true) } + KitButton("Cancel", .quiet, action: onCancel).disabled(working) + if !askDate && kind == .phrase { advanced } } .onAppear { guard network.isEmpty else { return } @@ -429,66 +326,42 @@ struct RestoreView: View { private var advanced: some View { DisclosureGroup(isExpanded: $advancedOpen) { VStack(alignment: .leading, spacing: 8) { - Toggle("Restore on the test network", isOn: testnetBinding) - .font(Face.body) - .foregroundColor(Palette.star).tint(Palette.gold) + KitToggle("Restore on the test network", isOn: testnetBinding) .disabled(working) Text("For developers. Test coins have no value.") - .font(Face.body).foregroundColor(Palette.dust) + .kit(.body, Palette.muted) } .padding(.top, 8) } label: { - Text("Advanced").font(Face.label).foregroundColor(Palette.dust) - .frame(minHeight: 48) + Text("Advanced").kit(.label) + .frame(minHeight: Space.touch) } - .tint(Palette.dust) + .tint(Palette.muted) } - /// Same choice as the React Native pill tabs: a raised pill, the chosen - /// word in the text colour, the other muted. Accent is not a fill. private var kindTabs: some View { - HStack(spacing: 4) { - kindTab("Recovery phrase", .phrase) - kindTab("Viewing key", .viewingKey) - } - .padding(4) - .frame(minHeight: 48) - .background(Palette.deep) - .clipShape(Capsule()) - } - - private func kindTab(_ title: String, _ value: Kind) -> some View { - let on = kind == value - return Button { - kind = value - error = nil - } label: { - Text(title).font(Face.tab) - .foregroundColor(on ? Palette.star : Palette.dust) - .frame(maxWidth: .infinity, minHeight: 40) - .background(on ? Palette.raised : Color.clear) - .clipShape(Capsule()) - } - .buttonStyle(PressedFade()) + PillTabs( + items: [("Recovery phrase", Kind.phrase), ("Viewing key", Kind.viewingKey)], + selection: Binding(get: { kind }, set: { kind = $0; error = nil }) + ) .disabled(working) - .accessibilityAddTraits(on ? .isSelected : []) } private var wordStep: some View { VStack(alignment: .leading, spacing: 16) { - Text("Enter your recovery phrase").font(Face.title).foregroundColor(Palette.star) - Text("Type each of your 24 words in order.").font(Face.body).foregroundColor(Palette.dust) + Text("Enter your recovery phrase").kit(.title) + Text("Type each of your 24 words in order.").kit(.body, Palette.muted) if viewOnly { Text( "\(WalletSettings.appName) can show this wallet’s money, but paying from it isn’t ready yet. Your phrase stays on this iPhone, so the wallet can pay once it is." ) - .font(Face.body).foregroundColor(Palette.dust) + .kit(.body, Palette.muted) } if !entered.isEmpty { WordGrid(words: entered).privacySensitive() } if entered.count < total { - Text("Word \(entered.count + 1) of \(total)").font(Face.label).foregroundColor(Palette.dust) - TextField("", text: $current, prompt: Text("word \(entered.count + 1)").foregroundColor(Palette.dust)) - .font(Face.mono).foregroundColor(Palette.star) + Text("Word \(entered.count + 1) of \(total)").kit(.label) + TextField("", text: $current, prompt: Text("word \(entered.count + 1)").foregroundColor(Palette.faint)) + .kit(.monoLarge) .textInputAutocapitalization(.never).autocorrectionDisabled().keyboardType(.asciiCapable) .textContentType(.none).privacySensitive().focused($focused).submitLabel(.next) .textFieldStyle(.plain) @@ -501,35 +374,24 @@ struct RestoreView: View { kind = .viewingKey } } - .padding(.horizontal, 16) - .padding(.vertical, 14) - .frame(minHeight: 48) - .background(Palette.raised) - .clipShape(RoundedRectangle(cornerRadius: 14, style: .continuous)) + .kitField() .onAppear { focused = true } if !suggestions.isEmpty { HStack(spacing: 8) { ForEach(suggestions, id: \.self) { w in - Button { accept(w) } label: { - Text(w).font(Face.mono).foregroundColor(Palette.star) - .padding(.horizontal, 16) - .frame(minHeight: 48) - } - .buttonStyle(PressedFade()) - .background(Palette.raised) - .clipShape(Capsule()) + Chip(w, mono: true) { accept(w) } } } } } if !entered.isEmpty { - SecondaryButton(title: "Remove the last word") { + KitButton("Remove the last word", .quiet) { entered.removeLast() error = nil } } if entered.count == total { - PrimaryButton(title: "Next") { + KitButton("Next") { if let problem = check(entered.joined(separator: " ")) { error = "These words aren't a valid recovery phrase (\(problem)). Check each one against your copy." } else { @@ -544,55 +406,48 @@ struct RestoreView: View { private var keyStep: some View { VStack(alignment: .leading, spacing: 16) { Text(keyOnly ? "Add a view-only wallet" : "Enter your viewing key") - .font(Face.title).foregroundColor(Palette.star) + .kit(.title) Text( "A viewing key lets \(WalletSettings.appName) see a wallet’s balance and payments. It can’t spend, so this wallet won’t be able to pay." ) - .font(Face.body).foregroundColor(Palette.dust) + .kit(.body, Palette.muted) ZStack(alignment: .topLeading) { if capture.captured { // Hidden while the screen is recorded or mirrored. - Text("Hidden while the screen is being recorded.").font(Face.body).foregroundColor(Palette.dust).padding(16) + Text("Hidden while the screen is being recorded.").kit(.body, Palette.muted) } else { TextField( - "", text: $key, prompt: Text("uview1…").foregroundColor(Palette.dust), axis: .vertical + "", text: $key, prompt: Text("uview1…").foregroundColor(Palette.faint), axis: .vertical ) .lineLimit(3...8) - .font(Face.mono).foregroundColor(Palette.star) + .kit(.monoLarge) .textInputAutocapitalization(.never).autocorrectionDisabled().keyboardType(.asciiCapable) .textContentType(.none).privacySensitive() .textFieldStyle(.plain) - .padding(.horizontal, 16) - .padding(.vertical, 14) } } - .frame(maxWidth: .infinity, minHeight: 88, alignment: .topLeading) - .background(Palette.raised) - .clipShape(RoundedRectangle(cornerRadius: 14, style: .continuous)) + .frame(maxWidth: .infinity, alignment: .topLeading) + .kitField(minHeight: 88) HStack(spacing: 8) { - keyAction("Paste") { + Chip("Paste") { if let text = UIPasteboard.general.string { key = text.trimmingCharacters(in: .whitespacesAndNewlines) } error = nil } if KeyScanner.available { - keyAction("Scan") { scanning = true } + Chip("Scan") { scanning = true } } Spacer(minLength: 8) - Button { keyHelp.toggle() } label: { - Text("Where do I find it?").font(Face.button).foregroundColor(Palette.gold) - .frame(minHeight: 48) - } - .buttonStyle(PressedFade()) + LinkButton("Where do I find it?") { keyHelp.toggle() } } .disabled(working) if keyHelp { Text( "In \(WalletSettings.appName) on another phone: Me → Show viewing key, then tap Scan here. In another wallet, look in its settings for “Export viewing key” or “Unified full viewing key”. It’s one long line that starts with “uview”. Never enter a spending key here, and never give your recovery phrase to anyone." ) - .font(Face.body).foregroundColor(Palette.dust) + .kit(.body, Palette.muted) } if !key.isEmpty { - PrimaryButton(title: "Next") { + KitButton("Next") { guard let found = keyNetwork(key) else { error = "That isn’t a viewing key. A viewing key is one long line that starts with “uview”." return @@ -611,25 +466,14 @@ struct RestoreView: View { } } - private func keyAction(_ title: String, action: @escaping () -> Void) -> some View { - Button(action: action) { - Text(title).font(Face.button).foregroundColor(Palette.star) - .padding(.horizontal, 16) - .frame(minHeight: 48) - .background(Palette.raised) - .clipShape(Capsule()) - } - .buttonStyle(PressedFade()) - } - private var dateStep: some View { VStack(alignment: .leading, spacing: 16) { - Text("Roughly when did you create this wallet?").font(Face.title).foregroundColor(Palette.star) + Text("Roughly when did you create this wallet?").kit(.title) Text("\(WalletSettings.appName) looks for your payments from then on. If you're not sure, pick an earlier month.") - .font(Face.body).foregroundColor(Palette.dust) + .kit(.body, Palette.muted) if kind == .viewingKey && keyNetworkFound == "testnet" { Text("This key is for the test network. Test coins have no value.") - .font(Face.body).foregroundColor(Palette.dust) + .kit(.body, Palette.muted) } HStack { Picker("Month", selection: $month) { @@ -642,28 +486,26 @@ struct RestoreView: View { } } .font(Face.body) - .tint(Palette.gold) + .tint(Palette.accent) if beforeIronwood { VStack(alignment: .leading, spacing: 8) { - Toggle("Look for older funds", isOn: $olderPools) - .font(Face.body) - .foregroundColor(Palette.star).tint(Palette.gold) + KitToggle("Look for older funds", isOn: $olderPools) .disabled(working) Text( kind == .phrase ? "If you used this phrase in another wallet before August 2026, some of your ZEC may be in an older part of Zcash. Looking for it takes longer and uses more data." : "If this wallet had ZEC before August 2026, some of it may be in an older part of Zcash. Looking for it takes longer and uses more data." ) - .font(Face.body).foregroundColor(Palette.dust) + .kit(.body, Palette.muted) } } if working { // The restore screen never moves (design guide §6). The words are the signal. - Text("Restoring…").font(Face.body).foregroundColor(Palette.dust).frame(minHeight: 48) + Text("Restoring…").kit(.body, Palette.muted).frame(minHeight: Space.touch) } else { - PrimaryButton(title: "Restore") { run((year: year, month: month)) } - SecondaryButton(title: "I don't know") { run(nil) } - SecondaryButton(title: "Back") { + KitButton("Restore") { run((year: year, month: month)) } + KitButton("I don't know", .quiet) { run(nil) } + KitButton("Back", .quiet) { error = nil askDate = false } diff --git a/wallet-native/ios/WalletSettings.swift b/wallet-native/ios/WalletSettings.swift index d69c0e4..b6aa3ae 100644 --- a/wallet-native/ios/WalletSettings.swift +++ b/wallet-native/ios/WalletSettings.swift @@ -159,18 +159,22 @@ enum Networks { } /// The native screens' colours (`theme` and `themeLight` keys in -/// `app.plugin.js`), each following light and dark mode. The fallbacks are -/// Wizard's Night and Vellum, from docs/design/wizard-design-guide.md §4a. -/// The names are Night's; in Vellum, `star` is Ink, `gold` is Bronze and so on. +/// `app.plugin.js`), each following light and dark mode. The names are the +/// plugin's keys, which are `mobile/src/theme.ts`'s roles (`background` is +/// `page`, `buttonBackground` is `action`). The fallbacks are Wizard's Night +/// and Vellum, from docs/design/wizard-design-guide.md §4a. Screens use these +/// through Kit.swift. enum Palette { - static let night = WalletSettings.color("background", 0x0B1026, light: 0xF5EFE2) - static let deep = WalletSettings.color("sheet", 0x131B3D, light: 0xFCF9F2) + static let background = WalletSettings.color("background", 0x0B1026, light: 0xF5EFE2) + static let sheet = WalletSettings.color("sheet", 0x131B3D, light: 0xFCF9F2) static let raised = WalletSettings.color("raised", 0x1B2550, light: 0xECE4D2) static let line = WalletSettings.color("line", 0x2A3566, light: 0xD9CDB3) - static let star = WalletSettings.color("text", 0xF4EFE3, light: 0x141A3A) - static let dust = WalletSettings.color("muted", 0xA3ABCC, light: 0x4B5372) - static let gold = WalletSettings.color("accent", 0xE3B45C, light: 0x7D5B18) - static let cinnabar = WalletSettings.color("danger", 0xF0806A, light: 0xB03A25) + static let text = WalletSettings.color("text", 0xF4EFE3, light: 0x141A3A) + static let muted = WalletSettings.color("muted", 0xA3ABCC, light: 0x4B5372) + static let faint = WalletSettings.color("faint", 0x8790B8, light: 0x5A6180) + static let accent = WalletSettings.color("accent", 0xE3B45C, light: 0x7D5B18) + static let onAccent = WalletSettings.color("onAccent", 0x0B1026, light: 0xFCF9F2) + static let danger = WalletSettings.color("danger", 0xF0806A, light: 0xB03A25) static let buttonBackground = WalletSettings.color("buttonBackground", 0xFFFFFF, light: 0x0B1026) static let buttonText = WalletSettings.color("buttonText", 0x0B1026, light: 0xF4EFE3) } diff --git a/wallet-native/plugin/options.js b/wallet-native/plugin/options.js index 398144a..44a35b9 100644 --- a/wallet-native/plugin/options.js +++ b/wallet-native/plugin/options.js @@ -9,7 +9,9 @@ const THEME_KEYS = [ 'line', 'text', 'muted', // secondary text, labels - 'accent', // the network badge, the screen-recording warning + 'faint', // placeholders + 'accent', // the network badge, the screen-recording warning, links + 'onAccent', // words on the network badge 'danger', // errors 'buttonBackground', // the main button 'buttonText', @@ -23,7 +25,9 @@ const DEFAULT_THEME = { line: '#3A3A3C', text: '#FFFFFF', muted: '#8E8E93', + faint: '#636366', accent: '#0A84FF', + onAccent: '#FFFFFF', danger: '#FF453A', buttonBackground: '#FFFFFF', buttonText: '#000000',