Skip to content
TypeScript

refactor(mobile): adopt shared text shape and motion tokens (#19953)

Julius Marminge68eb28dce020
diff --git a/apps/mobile/src/components/AppText.tsx b/apps/mobile/src/components/AppText.tsx
index 7423ff67854..9ca351a50d6 100644
--- a/apps/mobile/src/components/AppText.tsx
+++ b/apps/mobile/src/components/AppText.tsx
@@ -7,18 +7,27 @@ import {
type TextProps as RNTextProps,
} from "react-native";
+import { MOBILE_TEXT_CLASSES } from "../lib/typography";
+
import { cn } from "../lib/cn";
-export type AppTextProps = RNTextProps & { readonly className?: string };
+export type AppTextProps = RNTextProps & {
+ readonly className?: string;
+ readonly textRole?: keyof typeof MOBILE_TEXT_CLASSES;
+};
/**
* Thin wrapper around RN Text with default font-family and foreground color.
* Uses Uniwind className — no manual style parsing.
*/
-export function AppText({ className, ...props }: AppTextProps) {
+export function AppText({ className, textRole, ...props }: AppTextProps) {
return (
<RNText
- className={cn("font-sans text-foreground", className)}
+ className={cn(
+ "font-sans text-foreground",
+ textRole && MOBILE_TEXT_CLASSES[textRole],
+ className,
+ )}
selectionColorClassName={Platform.OS === "android" ? "accent-focus/32" : undefined}
{...props}
/>
diff --git a/apps/mobile/src/components/GlassSurface.tsx b/apps/mobile/src/components/GlassSurface.tsx
index bea8d39f06d..f0cf26fda8b 100644
--- a/apps/mobile/src/components/GlassSurface.tsx
+++ b/apps/mobile/src/components/GlassSurface.tsx
@@ -10,6 +10,7 @@ import {
} from "react-native";
import { withUniwind } from "uniwind";
+import { MOBILE_SHAPE } from "../lib/designTokens";
import { cn } from "../lib/cn";
import { useAppearancePreferences } from "../features/settings/appearance/AppearancePreferencesProvider";
import { GlassBackdrop } from "./GlassBackdrop";
@@ -51,7 +52,7 @@ export function GlassSurface({
const supportsGlass = Platform.OS === "ios" && isGlassEffectAPIAvailable();
const hasShadow = chrome !== "none" && Platform.OS !== "android";
const surfaceStyle: ViewStyle = {
- borderRadius: 32,
+ borderRadius: MOBILE_SHAPE.glass,
overflow: "hidden",
shadowColor: hasShadow ? "#000000" : "transparent",
shadowOpacity: hasShadow ? (isDarkMode ? 0.22 : 0.08) : 0,
diff --git a/apps/mobile/src/components/ListRowLayout.tsx b/apps/mobile/src/components/ListRowLayout.tsx
index 9464e9d13ec..64ff80cc223 100644
--- a/apps/mobile/src/components/ListRowLayout.tsx
+++ b/apps/mobile/src/components/ListRowLayout.tsx
@@ -47,22 +47,26 @@ export function ListRowLayout({
) : null}
<View className="min-w-0 flex-1 gap-1">
<AppText
- className={
- tone === "danger" ? "text-base text-danger-foreground" : "text-base text-foreground"
- }
+ textRole="body"
+ className={tone === "danger" ? "text-danger-foreground" : "text-foreground"}
>
{label}
</AppText>
{description ? (
- <AppText className="text-sm text-foreground-muted">{description}</AppText>
+ <AppText textRole="footnote" className="text-foreground-muted">
+ {description}
+ </AppText>
) : null}
{detail && stackDetail ? (
- <AppText className="text-sm text-foreground-muted">{detail}</AppText>
+ <AppText textRole="footnote" className="text-foreground-muted">
+ {detail}
+ </AppText>
) : null}
</View>
{detail && !stackDetail ? (
<AppText
- className="max-w-[40%] shrink text-right text-sm text-foreground-muted"
+ textRole="footnote"
+ className="max-w-[40%] shrink text-right text-foreground-muted"
numberOfLines={1}
ellipsizeMode="middle"
>
diff --git a/apps/mobile/src/components/ListSection.tsx b/apps/mobile/src/components/ListSection.tsx
index 99e07d05e9b..0d478fa4aa2 100644
--- a/apps/mobile/src/components/ListSection.tsx
+++ b/apps/mobile/src/components/ListSection.tsx
@@ -1,3 +1,4 @@
+import { MOBILE_SHAPE } from "../lib/designTokens";
import type { ReactNode } from "react";
import { Platform, View } from "react-native";
@@ -22,7 +23,7 @@ export function ListSection(props: {
}
>
{props.titleIcon}
- <Text className="shrink text-sm font-t3-medium text-foreground-muted">
+ <Text textRole="footnote" className="shrink font-t3-medium text-foreground-muted">
{props.title}
</Text>
</View>
@@ -30,16 +31,18 @@ export function ListSection(props: {
</View>
) : null}
<View
- className={
- Platform.OS === "android"
- ? "overflow-hidden rounded-[28px] bg-grouped-card"
- : "overflow-hidden rounded-[24px] border-continuous bg-grouped-card"
- }
+ className="overflow-hidden border-continuous bg-grouped-card"
+ style={{
+ borderRadius:
+ Platform.OS === "android" ? MOBILE_SHAPE.group.android : MOBILE_SHAPE.group.ios,
+ }}
>
{props.children}
</View>
{props.footer ? (
- <Text className="px-4 text-sm text-foreground-muted">{props.footer}</Text>
+ <Text textRole="footnote" className="px-4 text-foreground-muted">
+ {props.footer}
+ </Text>
) : null}
</View>
);
diff --git a/apps/mobile/src/components/Progress.android.tsx b/apps/mobile/src/components/Progress.android.tsx
index 652ccef2fa2..619e13ea51a 100644
--- a/apps/mobile/src/components/Progress.android.tsx
+++ b/apps/mobile/src/components/Progress.android.tsx
@@ -1,12 +1,14 @@
import { LinearProgressIndicator } from "@expo/ui/jetpack-compose";
import { fillMaxWidth } from "@expo/ui/jetpack-compose/modifiers";
import { View } from "react-native";
+import { useReducedMotion } from "react-native-reanimated";
import { NativeThemeHost } from "./NativeThemeHost.android";
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
@@ -19,16 +21,20 @@ export function Progress(props: ProgressProps) {
}
accessibilityState={{ busy: value === undefined }}
>
- <View importantForAccessibility="no-hide-descendants">
- <NativeThemeHost matchContents={{ vertical: true }} style={{ width: "100%" }}>
- <LinearProgressIndicator
- progress={value}
- color={colors["--color-primary"]}
- trackColor={colors["--color-subtle"]}
- modifiers={[fillMaxWidth()]}
- />
- </NativeThemeHost>
- </View>
+ {reducedMotion && value === undefined ? (
+ <View className="h-1 rounded-full bg-primary/30" />
+ ) : (
+ <View importantForAccessibility="no-hide-descendants">
+ <NativeThemeHost matchContents={{ vertical: true }} style={{ width: "100%" }}>
+ <LinearProgressIndicator
+ progress={value}
+ color={colors["--color-primary"]}
+ trackColor={colors["--color-subtle"]}
+ modifiers={[fillMaxWidth()]}
+ />
+ </NativeThemeHost>
+ </View>
+ )}
</View>
);
}
diff --git a/apps/mobile/src/components/Progress.ios.tsx b/apps/mobile/src/components/Progress.ios.tsx
index f342d1cfb03..b73625b6b23 100644
--- a/apps/mobile/src/components/Progress.ios.tsx
+++ b/apps/mobile/src/components/Progress.ios.tsx
@@ -1,12 +1,14 @@
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
@@ -19,12 +21,16 @@ export function Progress(props: ProgressProps) {
}
accessibilityState={{ busy: value === undefined }}
>
- <NativeThemeHost matchContents={{ vertical: true }} style={{ width: "100%" }}>
- <ProgressView
- value={value}
- modifiers={[progressViewStyle("linear"), tint(colors["--color-primary"])]}
- />
- </NativeThemeHost>
+ {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/Toast.tsx b/apps/mobile/src/components/Toast.tsx
index 08ced0ff051..9949ec1371a 100644
--- a/apps/mobile/src/components/Toast.tsx
+++ b/apps/mobile/src/components/Toast.tsx
@@ -1,3 +1,4 @@
+import { MOBILE_SHAPE } from "../lib/designTokens";
import { useEffect } from "react";
import { AccessibilityInfo, Platform, View } from "react-native";
@@ -23,7 +24,7 @@ export function Toast(props: ToastProps) {
if (Platform.OS === "ios") AccessibilityInfo.announceForAccessibility(props.message);
}, [props.message]);
return (
- <GlassSurface className="p-3">
+ <GlassSurface className="p-3" style={{ borderRadius: MOBILE_SHAPE.toast }}>
<View className="flex-row items-center gap-3">
{props.busy ? (
<AppActivityIndicator />
@@ -37,9 +38,13 @@ export function Toast(props: ToastProps) {
/>
)}
<View className="min-w-0 flex-1" accessibilityLiveRegion="polite">
- <AppText className="text-sm font-t3-semibold">{props.message}</AppText>
+ <AppText textRole="footnote" className="font-t3-semibold">
+ {props.message}
+ </AppText>
{props.description ? (
- <AppText className="text-xs text-foreground-muted">{props.description}</AppText>
+ <AppText textRole="label" className="text-foreground-muted">
+ {props.description}
+ </AppText>
) : null}
</View>
{props.onDismiss ? (
diff --git a/apps/mobile/src/features/threads/GitActionProgressOverlay.tsx b/apps/mobile/src/features/threads/GitActionProgressOverlay.tsx
index 7faf434bd2a..1bdc42b9553 100644
--- a/apps/mobile/src/features/threads/GitActionProgressOverlay.tsx
+++ b/apps/mobile/src/features/threads/GitActionProgressOverlay.tsx
@@ -4,6 +4,7 @@ import { useEffect, useRef } from "react";
import Animated, { FadeIn, FadeOut, ReduceMotion } from "react-native-reanimated";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { Toast } from "../../components/Toast";
+import { MOBILE_MOTION } from "../../lib/designTokens";
import { APP_BAR_HEIGHT } from "../../lib/layoutMetrics";
import type { GitActionProgress } from "../../state/use-vcs-action-state";
@@ -46,8 +47,8 @@ export function GitActionProgressOverlay(props: {
return (
<Animated.View
- entering={FadeIn.duration(200).reduceMotion(ReduceMotion.System)}
- exiting={FadeOut.duration(150).reduceMotion(ReduceMotion.System)}
+ entering={FadeIn.duration(MOBILE_MOTION.enter).reduceMotion(ReduceMotion.System)}
+ exiting={FadeOut.duration(MOBILE_MOTION.exit).reduceMotion(ReduceMotion.System)}
className="absolute inset-x-3 z-[100]"
style={{ top: insets.top + APP_BAR_HEIGHT + 8 }}
pointerEvents="box-none"
diff --git a/apps/mobile/src/lib/designTokens.ts b/apps/mobile/src/lib/designTokens.ts
new file mode 100644
index 00000000000..a1a8a9c4039
--- /dev/null
+++ b/apps/mobile/src/lib/designTokens.ts
@@ -0,0 +1,9 @@
+/** Named shapes belong to components; native controls retain platform geometry. */
+export const MOBILE_SHAPE = {
+ group: { ios: 24, android: 28 },
+ toast: 26,
+ glass: 32,
+} as const;
+
+/** Finite transitions only; each animation must opt into system reduced motion. */
+export const MOBILE_MOTION = { enter: 200, exit: 150 } as const;
diff --git a/apps/mobile/src/lib/typography.ts b/apps/mobile/src/lib/typography.ts
index 6572f38dde2..a320e9ca37f 100644
--- a/apps/mobile/src/lib/typography.ts
+++ b/apps/mobile/src/lib/typography.ts
@@ -19,3 +19,16 @@ export const MOBILE_CODE_SURFACE = {
fontSize: MOBILE_TYPOGRAPHY.caption.fontSize,
lineNumberFontSize: MOBILE_TYPOGRAPHY.micro.fontSize,
} as const;
+
+/** Class names share the same scaled CSS variables as native text roles. */
+export const MOBILE_TEXT_CLASSES = {
+ micro: "text-3xs",
+ caption: "text-2xs",
+ label: "text-xs",
+ footnote: "text-sm",
+ body: "text-base",
+ headline: "text-lg",
+ title: "text-xl",
+ largeTitle: "text-2xl",
+ display: "text-3xl",
+} as const satisfies Record<keyof typeof MOBILE_TYPOGRAPHY, string>;