Skip to content

Commit 7fd35c0

Browse files
committed
feat(test-app): cap the lab's content column at regular width
The iPhone Duo's inner panel is 951pt wide, and the lab had no width discipline at all: prose ran the full window and the catalog kept a single column down the whole panel. `AppFrame` already wraps every route and owns frame geometry, so the capped, centered column lives there and every route inherits it, including the ones a per-screen pass leaves full-bleed (Product, AccessorySetup, AutomationLab, WebView). `useReadableColumn` reports both the width the column actually gets and whether the cap bound, so the extra view exists only where the cap changes something; at compact width the tree stays the one every e2e, smoke, and replay run uses today. The catalog takes two columns once a card clears 340pt. Cell width is arithmetic off the reported column width rather than a hand-tuned percentage, because `flexBasis: '50%'` beside a 12pt `columnGap` sums past the line and wraps one card per row. Cards keep their own 12pt bottom margin, so the grid owns only the column gutter and the vertical rhythm matches the compact list instead of doubling it. Compact width renders the same `SectionCard` element main renders: no container, no cell, identical testIDs, labels, roles, and `stickyHeaderIndices={[1]}` child order.
1 parent c2ecc46 commit 7fd35c0

2 files changed

Lines changed: 100 additions & 46 deletions

File tree

‎examples/test-app/src/components.tsx‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,32 @@ import {
55
Switch,
66
Text,
77
TextInput,
8+
useWindowDimensions,
89
View,
910
type TextInputProps,
1011
} from 'react-native';
1112
import { useSafeAreaInsets } from 'react-native-safe-area-context';
1213

1314
import { useAppColors, type AppColors } from './theme';
1415

16+
/** The widest column the lab's prose reads well in across a wide panel. */
17+
const READABLE_MAX_WIDTH = 760;
18+
19+
/** The frame's horizontal padding, which every route's content column sits inside. */
20+
const FRAME_PADDING_X = 18;
21+
22+
/**
23+
* The column a route's content actually gets once the frame's padding and the readable cap are
24+
* applied, plus whether that cap bound. `capped` is false anywhere the cap would render identically
25+
* to the frame, so nothing extra enters the tree at compact width.
26+
*/
27+
export function useReadableColumn(): { capped: boolean; width: number } {
28+
const { width } = useWindowDimensions();
29+
const available = width - FRAME_PADDING_X * 2;
30+
31+
return { capped: available > READABLE_MAX_WIDTH, width: Math.min(available, READABLE_MAX_WIDTH) };
32+
}
33+
1534
export function ScreenTitle(props: {
1635
title: string;
1736
subtitle: string;
@@ -208,6 +227,7 @@ export function InlineBadge(props: {
208227
export function AppFrame(props: { children: ReactNode }) {
209228
const colors = useAppColors();
210229
const insets = useSafeAreaInsets();
230+
const { capped } = useReadableColumn();
211231
const styles = createStyles(colors);
212232

213233
return (
@@ -220,7 +240,7 @@ export function AppFrame(props: { children: ReactNode }) {
220240
},
221241
]}
222242
>
223-
{props.children}
243+
{capped ? <View style={styles.readableColumn}>{props.children}</View> : props.children}
224244
</View>
225245
);
226246
}
@@ -435,7 +455,13 @@ function createStyles(colors: AppColors) {
435455
frame: {
436456
backgroundColor: colors.surface,
437457
flex: 1,
438-
paddingHorizontal: 18,
458+
paddingHorizontal: FRAME_PADDING_X,
459+
},
460+
readableColumn: {
461+
alignSelf: 'center',
462+
flex: 1,
463+
maxWidth: READABLE_MAX_WIDTH,
464+
width: '100%',
439465
},
440466
toastViewport: {
441467
left: 16,

‎examples/test-app/src/screens/CatalogScreen.tsx‎

Lines changed: 72 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,16 @@ import {
1717
ScreenTitle,
1818
SectionCard,
1919
TextField,
20+
useReadableColumn,
2021
} from '../components';
2122
import { useAppColors, type AppColors } from '../theme';
2223

24+
/** The gutter the grid owns; cards keep their own 12pt bottom margin for the vertical rhythm. */
25+
const GRID_GUTTER = 12;
26+
27+
/** A card narrower than this cannot fit its price row and both action buttons side by side. */
28+
const MIN_GRID_CARD_WIDTH = 340;
29+
2330
export interface CatalogScreenProps {
2431
activeCategory: ProductCategory;
2532
cart: Record<string, number>;
@@ -36,6 +43,9 @@ export interface CatalogScreenProps {
3643
export function CatalogScreen(props: CatalogScreenProps) {
3744
const colors = useAppColors();
3845
const styles = createStyles(colors);
46+
const { width: contentWidth } = useReadableColumn();
47+
const cellWidth = (contentWidth - GRID_GUTTER) / 2;
48+
const gridded = cellWidth >= MIN_GRID_CARD_WIDTH;
3949
const lastScrollOffset = useRef(0);
4050
const [scrollState, setScrollState] = useState<'top' | 'bottom' | 'down' | 'up'>('top');
4151

@@ -55,6 +65,60 @@ export function CatalogScreen(props: CatalogScreenProps) {
5565
}
5666
}
5767

68+
// Compact width renders the card itself, so the tree there stays the one every e2e, smoke, and
69+
// replay run against today. The cell only exists where there are actually two columns.
70+
const productCards = props.products.map((product) => {
71+
const favoriteLabel = props.favorites.has(product.id) ? 'Saved' : 'Save';
72+
const cartCount = props.cart[product.id] ?? 0;
73+
const card = (
74+
<SectionCard
75+
key={product.id}
76+
subtitle={product.subtitle}
77+
testID={`product-card-${product.id}`}
78+
title={product.name}
79+
>
80+
<View style={styles.metaRow}>
81+
<InlineBadge label={product.badge} tone="info" />
82+
<Text style={styles.price}>{product.price}</Text>
83+
</View>
84+
<View style={styles.metaRow}>
85+
<Pressable
86+
accessibilityLabel={`${favoriteLabel} ${product.name}`}
87+
accessibilityRole="button"
88+
accessibilityState={{ selected: props.favorites.has(product.id) }}
89+
onPress={() => props.onToggleFavorite(product.id)}
90+
style={({ pressed }) => [styles.favoritePill, pressed ? styles.pressed : null]}
91+
testID={`favorite-${product.id}`}
92+
>
93+
<Text style={styles.favoriteLabel}>{favoriteLabel}</Text>
94+
</Pressable>
95+
<Text style={styles.cartCount}>In cart: {cartCount}</Text>
96+
</View>
97+
<View style={styles.buttonRow}>
98+
<ActionButton
99+
kind="secondary"
100+
label="View details"
101+
onPress={() => props.onOpenDetails(product.id)}
102+
testID={`details-${product.id}`}
103+
/>
104+
<ActionButton
105+
label="Add to cart"
106+
onPress={() => props.onAddToCart(product.id)}
107+
testID={`add-${product.id}`}
108+
/>
109+
</View>
110+
</SectionCard>
111+
);
112+
113+
return gridded ? (
114+
<View key={product.id} style={{ width: cellWidth }}>
115+
{card}
116+
</View>
117+
) : (
118+
card
119+
);
120+
});
121+
58122
return (
59123
<ScrollView
60124
bounces={false}
@@ -99,50 +163,7 @@ export function CatalogScreen(props: CatalogScreenProps) {
99163
</View>
100164
</SectionCard>
101165

102-
{props.products.map((product) => {
103-
const favoriteLabel = props.favorites.has(product.id) ? 'Saved' : 'Save';
104-
const cartCount = props.cart[product.id] ?? 0;
105-
106-
return (
107-
<SectionCard
108-
key={product.id}
109-
subtitle={product.subtitle}
110-
testID={`product-card-${product.id}`}
111-
title={product.name}
112-
>
113-
<View style={styles.metaRow}>
114-
<InlineBadge label={product.badge} tone="info" />
115-
<Text style={styles.price}>{product.price}</Text>
116-
</View>
117-
<View style={styles.metaRow}>
118-
<Pressable
119-
accessibilityLabel={`${favoriteLabel} ${product.name}`}
120-
accessibilityRole="button"
121-
accessibilityState={{ selected: props.favorites.has(product.id) }}
122-
onPress={() => props.onToggleFavorite(product.id)}
123-
style={({ pressed }) => [styles.favoritePill, pressed ? styles.pressed : null]}
124-
testID={`favorite-${product.id}`}
125-
>
126-
<Text style={styles.favoriteLabel}>{favoriteLabel}</Text>
127-
</Pressable>
128-
<Text style={styles.cartCount}>In cart: {cartCount}</Text>
129-
</View>
130-
<View style={styles.buttonRow}>
131-
<ActionButton
132-
kind="secondary"
133-
label="View details"
134-
onPress={() => props.onOpenDetails(product.id)}
135-
testID={`details-${product.id}`}
136-
/>
137-
<ActionButton
138-
label="Add to cart"
139-
onPress={() => props.onAddToCart(product.id)}
140-
testID={`add-${product.id}`}
141-
/>
142-
</View>
143-
</SectionCard>
144-
);
145-
})}
166+
{gridded ? <View style={styles.productGrid}>{productCards}</View> : productCards}
146167

147168
<SectionCard
148169
subtitle="This footer card sits at the end of the list to force scroll-into-view on smaller screens."
@@ -163,6 +184,13 @@ function createStyles(colors: AppColors) {
163184
content: {
164185
paddingBottom: 28,
165186
},
187+
// Cards carry their own 12pt bottom margin, so the grid only owns the gutter between columns;
188+
// asking for both would double the vertical rhythm the compact list already has.
189+
productGrid: {
190+
columnGap: GRID_GUTTER,
191+
flexDirection: 'row',
192+
flexWrap: 'wrap',
193+
},
166194
chipRow: {
167195
flexDirection: 'row',
168196
flexWrap: 'wrap',

0 commit comments

Comments
 (0)