TypeScript
refactor(mobile): finish shared control token adoption (#19996)
Julius Marminge4b8fb2e2372c
diff --git a/apps/mobile/src/components/Chip.tsx b/apps/mobile/src/components/Chip.tsxindex 9f46e7ffd3b..14fe8f2086a 100644--- a/apps/mobile/src/components/Chip.tsx+++ b/apps/mobile/src/components/Chip.tsx@@ -37,11 +37,12 @@ export function Chip(props: {<SymbolView name={props.icon} size={15} tintColorClassName={iconColor} />) : null}<AppText+ textRole={small ? "caption" : "footnote"}numberOfLines={small ? undefined : 1}className={cn("shrink",!small && "max-w-[180px]",- small ? "text-2xs" : "text-sm font-t3-medium",+ !small && "font-t3-medium",props.selected ? "text-primary-foreground" : "text-foreground-muted",)}>diff --git a/apps/mobile/src/components/EmptyState.tsx b/apps/mobile/src/components/EmptyState.tsxindex 24aa0242b28..74e7b315759 100644--- a/apps/mobile/src/components/EmptyState.tsx+++ b/apps/mobile/src/components/EmptyState.tsx@@ -15,8 +15,13 @@ export function EmptyState(props: {if (props.variant === "plain") {return (<View className="items-center px-8 py-8">- <Text className="text-center text-xl font-t3-bold text-foreground">{props.title}</Text>- <Text className="mt-2 text-center font-sans text-base leading-normal text-foreground-muted">+ <Text textRole="title" className="text-center font-t3-bold text-foreground">+ {props.title}+ </Text>+ <Text+ textRole="body"+ className="mt-2 text-center font-sans leading-normal text-foreground-muted"+ >{props.detail}</Text>{props.action ? (@@ -32,8 +37,10 @@ export function EmptyState(props: {return (<View className="rounded-[22px] border border-border bg-card p-5">- <Text className="font-t3-bold text-lg text-foreground">{props.title}</Text>- <Text className="mt-2 font-sans text-sm leading-relaxed text-foreground-muted">+ <Text textRole="headline" className="font-t3-bold text-foreground">+ {props.title}+ </Text>+ <Text textRole="footnote" className="mt-2 font-sans leading-relaxed text-foreground-muted">{props.detail}</Text>{props.action ? (diff --git a/apps/mobile/src/components/FloatingActionButton.tsx b/apps/mobile/src/components/FloatingActionButton.tsxindex a6f970d467f..ffd7ef23d18 100644--- a/apps/mobile/src/components/FloatingActionButton.tsx+++ b/apps/mobile/src/components/FloatingActionButton.tsx@@ -26,8 +26,8 @@ export function FloatingActionButton(props: FloatingActionButtonProps) {/>{props.variant === "extended" && props.expanded !== false ? (<AppText+ textRole="footnote"className={cn(- "text-sm",props.tone === "primary" ? "text-primary-foreground" : "text-secondary-foreground",)}>diff --git a/apps/mobile/src/components/Notice.tsx b/apps/mobile/src/components/Notice.tsxindex d6cf26d40c3..d2a3cbdd18b 100644--- a/apps/mobile/src/components/Notice.tsx+++ b/apps/mobile/src/components/Notice.tsx@@ -39,9 +39,10 @@ export function Notice(props: {) : null}<AppTextselectable+ textRole="footnote"accessibilityLiveRegion="polite"className={cn(- "min-w-0 flex-1 text-sm",+ "min-w-0 flex-1",danger ? "text-danger-foreground" : "text-foreground",!props.floating && "font-t3-medium",)}diff --git a/apps/mobile/src/components/NumberField.android.tsx b/apps/mobile/src/components/NumberField.android.tsxindex 1a4f9b750bb..8eb4708dd56 100644--- a/apps/mobile/src/components/NumberField.android.tsx+++ b/apps/mobile/src/components/NumberField.android.tsx@@ -2,7 +2,7 @@ import { View } from "react-native";import { AppText } from "./AppText";import { IconButton } from "./IconButton";-import type { NumberFieldProps } from "./NumberField";+import type { NumberFieldProps } from "./NumberField.types";export function NumberField(props: NumberFieldProps) {const adjust = (amount: number) => {@@ -26,7 +26,8 @@ export function NumberField(props: NumberFieldProps) {onPress={() => adjust(-1)}/><AppText- className="min-w-8 text-center text-base"+ textRole="body"+ className="min-w-8 text-center"style={{ fontVariant: ["tabular-nums"] }}accessibilityLabel={`${props.label}: ${props.formatValue?.(props.value) ?? props.value}`}accessibilityLiveRegion="polite"diff --git a/apps/mobile/src/components/NumberField.ios.tsx b/apps/mobile/src/components/NumberField.ios.tsxdeleted file mode 100644index 666af6e160d..00000000000--- a/apps/mobile/src/components/NumberField.ios.tsx+++ /dev/null@@ -1,92 +0,0 @@-import { Button, HStack, Picker, Popover, Text, VStack } from "@expo/ui/swift-ui";-import {- accessibilityLabel,- buttonStyle,- disabled,- font,- foregroundStyle,- frame,- padding,- pickerStyle,- presentationBackground,- tag,-} from "@expo/ui/swift-ui/modifiers";-import { useState } from "react";--import { NativeThemeHost } from "./NativeThemeHost";-import { useControlTheme } from "./useControlTheme";-import type { NumberFieldProps } from "./NumberField";--export function NumberField(props: NumberFieldProps) {- const { colors, fontSize } = useControlTheme();- const values = Array.from({ length: props.max - props.min + 1 }, (_, index) => props.min + index);- const [open, setOpen] = useState(false);- const [draft, setDraft] = useState(props.value);- return (- <NativeThemeHost matchContents>- <Popover isPresented={open} onIsPresentedChange={setOpen}>- <Popover.Trigger>- <Button- onPress={() => {- if (props.disabled) return;- setDraft(props.value);- setOpen(true);- }}- modifiers={[- buttonStyle("bordered"),- disabled(props.disabled),- accessibilityLabel(- `${props.label}: ${props.formatValue?.(props.value) ?? props.value}`,- ),- frame({ minWidth: 64, minHeight: 44 }),- foregroundStyle(colors["--color-primary-text"]),- font({ size: fontSize }),- ]}- >- <Text>{String(props.value)}</Text>- </Button>- </Popover.Trigger>- <Popover.Content>- <VStack- modifiers={[- padding({ all: 12 }),- frame({ width: 240 }),- presentationBackground(colors["--color-sheet-solid"]),- ]}- >- <Picker- label={props.label}- selection={draft}- onSelectionChange={setDraft}- modifiers={[pickerStyle("wheel"), frame({ height: 180 })]}- >- {values.map((value) => (- <Text- key={value}- modifiers={[tag(value), foregroundStyle(colors["--color-foreground"])]}- >- {props.formatValue?.(value) ?? String(value)}- </Text>- ))}- </Picker>- <HStack spacing={24}>- <Button- label="Cancel"- onPress={() => setOpen(false)}- modifiers={[foregroundStyle(colors["--color-primary-text"])]}- />- <Button- label="Done"- onPress={() => {- setOpen(false);- if (!props.disabled && draft !== props.value) props.onValueChange(draft);- }}- modifiers={[foregroundStyle(colors["--color-primary-text"])]}- />- </HStack>- </VStack>- </Popover.Content>- </Popover>- </NativeThemeHost>- );-}diff --git a/apps/mobile/src/components/NumberField.tsx b/apps/mobile/src/components/NumberField.tsxindex cbffd8ba1eb..1f95ca0d0e8 100644--- a/apps/mobile/src/components/NumberField.tsx+++ b/apps/mobile/src/components/NumberField.tsx@@ -1,47 +1,96 @@+import { Button, HStack, Picker, Popover, Text, VStack } from "@expo/ui/swift-ui";+import {+ accessibilityLabel,+ buttonStyle,+ disabled,+ font,+ foregroundStyle,+ frame,+ padding,+ pickerStyle,+ presentationBackground,+ tag,+} from "@expo/ui/swift-ui/modifiers";import { useState } from "react";-import { AppTextInput } from "./AppText";-export interface NumberFieldProps {- readonly label: string;- readonly min: number;- readonly max: number;- readonly formatValue?: (value: number) => string;- readonly value: number;- readonly onValueChange: (value: number) => void;- readonly disabled?: boolean;-}+import { NativeThemeHost } from "./NativeThemeHost";+import { useControlTheme } from "./useControlTheme";+import type { NumberFieldProps } from "./NumberField.types";export function NumberField(props: NumberFieldProps) {- const [draft, setDraft] = useState<string | null>(null);- const commit = () => {- if (props.disabled) {- setDraft(null);- return;- }- const text = (draft ?? "").trim();- setDraft(null);- // Validate the whole input; decimals and trailing text must not become whole days.- const parsed = /^\d+$/.test(text) ? Number(text) : Number.NaN;- if (- Number.isInteger(parsed) &&- parsed >= props.min &&- parsed <= props.max &&- parsed !== props.value- ) {- props.onValueChange(parsed);- }- };+ const { colors, fontSize } = useControlTheme();+ const [open, setOpen] = useState(false);+ const [draft, setDraft] = useState(props.value);+ const values = Array.from({ length: props.max - props.min + 1 }, (_, index) => props.min + index);+ if (!values.includes(draft)) values.push(draft);+ values.sort((a, b) => a - b);return (- <AppTextInput- className="min-h-10 w-20 rounded-xl px-3 py-2 text-center text-base"- keyboardType="number-pad"- returnKeyType="done"- value={draft ?? String(props.value)}- onChangeText={setDraft}- onBlur={commit}- onSubmitEditing={commit}- accessibilityLabel={props.label}- editable={!props.disabled}- />+ <NativeThemeHost matchContents>+ <Popover isPresented={open} onIsPresentedChange={setOpen}>+ <Popover.Trigger>+ <Button+ onPress={() => {+ if (props.disabled) return;+ setDraft(props.value);+ setOpen(true);+ }}+ modifiers={[+ buttonStyle("bordered"),+ disabled(props.disabled),+ accessibilityLabel(+ `${props.label}: ${props.formatValue?.(props.value) ?? props.value}`,+ ),+ frame({ minWidth: 64, minHeight: 44 }),+ foregroundStyle(colors["--color-primary-text"]),+ font({ size: fontSize }),+ ]}+ >+ <Text>{String(props.value)}</Text>+ </Button>+ </Popover.Trigger>+ <Popover.Content>+ <VStack+ modifiers={[+ padding({ all: 12 }),+ frame({ width: 240 }),+ presentationBackground(colors["--color-sheet-solid"]),+ ]}+ >+ <Picker+ label={props.label}+ selection={draft}+ onSelectionChange={setDraft}+ modifiers={[pickerStyle("wheel"), frame({ height: 180 })]}+ >+ {values.map((value) => (+ <Text+ key={value}+ modifiers={[tag(value), foregroundStyle(colors["--color-foreground"])]}+ >+ {props.formatValue?.(value) ?? String(value)}+ </Text>+ ))}+ </Picker>+ <HStack spacing={24}>+ <Button+ label="Cancel"+ onPress={() => setOpen(false)}+ modifiers={[foregroundStyle(colors["--color-primary-text"])]}+ />+ <Button+ label="Done"+ onPress={() => {+ setOpen(false);+ if (!props.disabled && draft !== props.value) props.onValueChange(draft);+ }}+ modifiers={[foregroundStyle(colors["--color-primary-text"])]}+ />+ </HStack>+ </VStack>+ </Popover.Content>+ </Popover>+ </NativeThemeHost>);}++export type { NumberFieldProps } from "./NumberField.types";diff --git a/apps/mobile/src/components/NumberField.types.ts b/apps/mobile/src/components/NumberField.types.tsnew file mode 100644index 00000000000..792d7904b78--- /dev/null+++ b/apps/mobile/src/components/NumberField.types.ts@@ -0,0 +1,9 @@+export interface NumberFieldProps {+ readonly label: string;+ readonly min: number;+ readonly max: number;+ readonly formatValue?: (value: number) => string;+ readonly value: number;+ readonly onValueChange: (value: number) => void;+ readonly disabled?: boolean;+}diff --git a/apps/mobile/src/components/Progress.ios.tsx b/apps/mobile/src/components/Progress.ios.tsxdeleted file mode 100644index b73625b6b23..00000000000--- a/apps/mobile/src/components/Progress.ios.tsx+++ /dev/null@@ -1,36 +0,0 @@-import { ProgressView } from "@expo/ui/swift-ui";-import { progressViewStyle, tint } from "@expo/ui/swift-ui/modifiers";-import { View } from "react-native";-import { useReducedMotion } from "react-native-reanimated";-import { NativeThemeHost } from "./NativeThemeHost";-import { useControlTheme } from "./useControlTheme";-import { clampProgress, type ProgressProps } from "./Progress.types";--export function Progress(props: ProgressProps) {- const value = clampProgress(props.value);- const reducedMotion = useReducedMotion();- const { colors } = useControlTheme();- return (- <View- className={props.className}- accessible- accessibilityRole="progressbar"- accessibilityLabel={props.label}- accessibilityValue={- value === undefined ? undefined : { min: 0, max: 100, now: Math.round(value * 100) }- }- accessibilityState={{ busy: value === undefined }}- >- {reducedMotion && value === undefined ? (- <View className="h-1 rounded-full bg-primary/30" />- ) : (- <NativeThemeHost matchContents={{ vertical: true }} style={{ width: "100%" }}>- <ProgressView- value={value}- modifiers={[progressViewStyle("linear"), tint(colors["--color-primary"])]}- />- </NativeThemeHost>- )}- </View>- );-}diff --git a/apps/mobile/src/components/Progress.tsx b/apps/mobile/src/components/Progress.tsxindex 5f1accf71a5..c7155213900 100644--- a/apps/mobile/src/components/Progress.tsx+++ b/apps/mobile/src/components/Progress.tsx@@ -1,2 +1,38 @@-export { Progress } from "./Progress.ios";+import { ProgressView } from "@expo/ui/swift-ui";+import { progressViewStyle, tint } from "@expo/ui/swift-ui/modifiers";+import { View } from "react-native";+import { useReducedMotion } from "react-native-reanimated";+import { NativeThemeHost } from "./NativeThemeHost";+import { useControlTheme } from "./useControlTheme";+import { clampProgress, type ProgressProps } from "./Progress.types";++export function Progress(props: ProgressProps) {+ const value = clampProgress(props.value);+ const reducedMotion = useReducedMotion();+ const { colors } = useControlTheme();+ return (+ <View+ className={props.className}+ accessible+ accessibilityRole="progressbar"+ accessibilityLabel={props.label}+ accessibilityValue={+ value === undefined ? undefined : { min: 0, max: 100, now: Math.round(value * 100) }+ }+ accessibilityState={{ busy: value === undefined }}+ >+ {reducedMotion && value === undefined ? (+ <View className="h-1 rounded-full bg-primary/30" />+ ) : (+ <NativeThemeHost matchContents={{ vertical: true }} style={{ width: "100%" }}>+ <ProgressView+ value={value}+ modifiers={[progressViewStyle("linear"), tint(colors["--color-primary"])]}+ />+ </NativeThemeHost>+ )}+ </View>+ );+}+export type { ProgressProps } from "./Progress.types";diff --git a/apps/mobile/src/components/SliderRow.tsx b/apps/mobile/src/components/SliderRow.tsxindex 789eefdd270..11ff3019d0a 100644--- a/apps/mobile/src/components/SliderRow.tsx+++ b/apps/mobile/src/components/SliderRow.tsx@@ -1,3 +1,4 @@+import { MOBILE_MOTION } from "../lib/designTokens";import * as Haptics from "expo-haptics";import { SymbolView } from "./AppSymbol";import { useCallback, useEffect, useMemo, useRef } from "react";@@ -8,6 +9,7 @@ import Animated, {useAnimatedStyle,useSharedValue,withTiming,+ ReduceMotion,} from "react-native-reanimated";import type { ComponentProps } from "react";@@ -17,7 +19,10 @@ type SymbolName = ComponentProps<typeof SymbolView>["name"];const THUMB_SIZE = 26;const TRACK_HEIGHT = 4;-const SNAP_ANIMATION = { duration: 120 } as const;+const SNAP_ANIMATION = {+ duration: MOBILE_MOTION.adjust,+ reduceMotion: ReduceMotion.System,+} as const;function clampFraction(value: number): number {"worklet";diff --git a/apps/mobile/src/lib/designTokens.ts b/apps/mobile/src/lib/designTokens.tsindex a1a8a9c4039..d2c50399854 100644--- a/apps/mobile/src/lib/designTokens.ts+++ b/apps/mobile/src/lib/designTokens.ts@@ -6,4 +6,8 @@ export const MOBILE_SHAPE = {} as const;/** Finite transitions only; each animation must opt into system reduced motion. */-export const MOBILE_MOTION = { enter: 200, exit: 150 } as const;+export const MOBILE_MOTION = {+ adjust: 120,+ enter: 200,+ exit: 150,+} as const;