Skip to content

Commit 895245f

Browse files
committed
feat(test-app): fit the lab to regular-width panels
The iPhone Duo's inner panel is 951pt wide, and the lab had no width discipline at all: prose spans ran the full window and the catalog kept a single column down the whole panel. Add `useLabLayout`, keyed to UIKit's own 600pt regular-width threshold so the content column and the system's tab bar placement change on the same rotation, and cap the column at 760pt so line length stays readable. The catalog grid takes two columns once each card still clears a comfortable target width. Also set `sidebarAdaptable` on the tab host. Placement was already side-docked by the system at this width; the mode additionally publishes selection state per tab item, which is what an automation driver needs to read which tab is active. Accessibility labels and testIDs are unchanged throughout.
1 parent 95d07b6 commit 895245f

7 files changed

Lines changed: 122 additions & 46 deletions

File tree

‎examples/test-app/app/(tabs)/_layout.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default function TabsLayout() {
1616
default: { color: colors.textSoft, fontSize: 11, fontWeight: '600' },
1717
selected: { color: colors.text, fontSize: 11, fontWeight: '700' },
1818
}}
19+
sidebarAdaptable
1920
tintColor={colors.text}
2021
>
2122
<NativeTabs.Trigger name="index">

‎examples/test-app/src/layout.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { useWindowDimensions } from 'react-native';
2+
3+
/**
4+
* UIKit treats a window this wide or wider as regular width, which is when it starts
5+
* side-docking the native tab bar. Matching the system threshold keeps the card grid
6+
* and the tab bar changing placement in the same rotation.
7+
*/
8+
const REGULAR_MIN_WIDTH = 600;
9+
10+
/** Prose in the lab cards reads badly across a 950pt panel, so the column is capped. */
11+
const READABLE_MAX_WIDTH = 760;
12+
13+
/** Two columns only once each card still clears a comfortable tap target width. */
14+
const GRID_MIN_WIDTH = 760;
15+
16+
export interface LabLayout {
17+
contentColumns: number;
18+
/** Undefined on compact width so the screen keeps its own full-bleed layout. */
19+
maxContentWidth: number | undefined;
20+
regular: boolean;
21+
width: number;
22+
}
23+
24+
export function useLabLayout(): LabLayout {
25+
const { width } = useWindowDimensions();
26+
const regular = width >= REGULAR_MIN_WIDTH;
27+
28+
return {
29+
contentColumns: width >= GRID_MIN_WIDTH ? 2 : 1,
30+
maxContentWidth: regular ? READABLE_MAX_WIDTH : undefined,
31+
regular,
32+
width,
33+
};
34+
}
35+
36+
/** Centers a capped-width column inside a wide window without changing compact layout. */
37+
export function useLabContentStyle() {
38+
const { maxContentWidth } = useLabLayout();
39+
40+
return maxContentWidth === undefined
41+
? undefined
42+
: { maxWidth: maxContentWidth, width: '100%' as const, alignSelf: 'center' as const };
43+
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createAudioPlayer, type AudioPlayer } from 'expo-audio';
33
import { Platform, ScrollView, StyleSheet, Text, View } from 'react-native';
44

55
import { ActionButton, InlineBadge, ScreenTitle, SectionCard } from '../components';
6+
import { useLabContentStyle } from '../layout';
67
import { useAppColors, type AppColors } from '../theme';
78

89
type BrowserAudioElement = {
@@ -22,6 +23,7 @@ const SAMPLE_FREQUENCY_HZ = 440;
2223
export function AudioScreen() {
2324
const colors = useAppColors();
2425
const styles = createStyles(colors);
26+
const contentStyle = useLabContentStyle();
2527
const audioRef = useRef<BrowserAudioElement | null>(null);
2628
const playbackRef = useRef<SamplePlayback | null>(null);
2729
const nativePlayerRef = useRef<AudioPlayer | null>(null);
@@ -125,7 +127,10 @@ export function AudioScreen() {
125127
}
126128

127129
return (
128-
<ScrollView contentContainerStyle={styles.content} showsVerticalScrollIndicator={false}>
130+
<ScrollView
131+
contentContainerStyle={[styles.content, contentStyle]}
132+
showsVerticalScrollIndicator={false}
133+
>
129134
<ScreenTitle
130135
badge="Media"
131136
subtitle="A short generated audio sample with a visible playback state."

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

Lines changed: 57 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
SectionCard,
1919
TextField,
2020
} from '../components';
21+
import { useLabContentStyle, useLabLayout } from '../layout';
2122
import { useAppColors, type AppColors } from '../theme';
2223

2324
export interface CatalogScreenProps {
@@ -36,6 +37,9 @@ export interface CatalogScreenProps {
3637
export function CatalogScreen(props: CatalogScreenProps) {
3738
const colors = useAppColors();
3839
const styles = createStyles(colors);
40+
const contentStyle = useLabContentStyle();
41+
const layout = useLabLayout();
42+
const gridded = layout.contentColumns > 1;
3943
const lastScrollOffset = useRef(0);
4044
const [scrollState, setScrollState] = useState<'top' | 'bottom' | 'down' | 'up'>('top');
4145

@@ -58,7 +62,7 @@ export function CatalogScreen(props: CatalogScreenProps) {
5862
return (
5963
<ScrollView
6064
bounces={false}
61-
contentContainerStyle={styles.content}
65+
contentContainerStyle={[styles.content, contentStyle]}
6266
onScroll={updateScrollState}
6367
scrollEventThrottle={16}
6468
showsVerticalScrollIndicator={false}
@@ -99,50 +103,53 @@ export function CatalogScreen(props: CatalogScreenProps) {
99103
</View>
100104
</SectionCard>
101105

102-
{props.products.map((product) => {
103-
const favoriteLabel = props.favorites.has(product.id) ? 'Saved' : 'Save';
104-
const cartCount = props.cart[product.id] ?? 0;
106+
<View style={gridded ? styles.productGrid : undefined}>
107+
{props.products.map((product) => {
108+
const favoriteLabel = props.favorites.has(product.id) ? 'Saved' : 'Save';
109+
const cartCount = props.cart[product.id] ?? 0;
105110

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}`}
111+
return (
112+
<View key={product.id} style={gridded ? styles.productCell : undefined}>
113+
<SectionCard
114+
subtitle={product.subtitle}
115+
testID={`product-card-${product.id}`}
116+
title={product.name}
125117
>
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-
/>
118+
<View style={styles.metaRow}>
119+
<InlineBadge label={product.badge} tone="info" />
120+
<Text style={styles.price}>{product.price}</Text>
121+
</View>
122+
<View style={styles.metaRow}>
123+
<Pressable
124+
accessibilityLabel={`${favoriteLabel} ${product.name}`}
125+
accessibilityRole="button"
126+
accessibilityState={{ selected: props.favorites.has(product.id) }}
127+
onPress={() => props.onToggleFavorite(product.id)}
128+
style={({ pressed }) => [styles.favoritePill, pressed ? styles.pressed : null]}
129+
testID={`favorite-${product.id}`}
130+
>
131+
<Text style={styles.favoriteLabel}>{favoriteLabel}</Text>
132+
</Pressable>
133+
<Text style={styles.cartCount}>In cart: {cartCount}</Text>
134+
</View>
135+
<View style={styles.buttonRow}>
136+
<ActionButton
137+
kind="secondary"
138+
label="View details"
139+
onPress={() => props.onOpenDetails(product.id)}
140+
testID={`details-${product.id}`}
141+
/>
142+
<ActionButton
143+
label="Add to cart"
144+
onPress={() => props.onAddToCart(product.id)}
145+
testID={`add-${product.id}`}
146+
/>
147+
</View>
148+
</SectionCard>
142149
</View>
143-
</SectionCard>
144-
);
145-
})}
150+
);
151+
})}
152+
</View>
146153

147154
<SectionCard
148155
subtitle="This footer card sits at the end of the list to force scroll-into-view on smaller screens."
@@ -163,6 +170,14 @@ function createStyles(colors: AppColors) {
163170
content: {
164171
paddingBottom: 28,
165172
},
173+
productGrid: {
174+
flexDirection: 'row',
175+
flexWrap: 'wrap',
176+
gap: 12,
177+
},
178+
productCell: {
179+
width: '48.6%',
180+
},
166181
chipRow: {
167182
flexDirection: 'row',
168183
flexWrap: 'wrap',

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
SectionCard,
99
TextField,
1010
} from '../components';
11+
import { useLabContentStyle } from '../layout';
1112
import { useAppColors, type AppColors } from '../theme';
1213

1314
export interface CheckoutFormState {
@@ -60,10 +61,11 @@ function CheckboxRow(props: {
6061
export function FormScreen(props: FormScreenProps) {
6162
const colors = useAppColors();
6263
const styles = createStyles(colors);
64+
const contentStyle = useLabContentStyle();
6365

6466
return (
6567
<ScrollView
66-
contentContainerStyle={styles.content}
68+
contentContainerStyle={[styles.content, contentStyle]}
6769
keyboardShouldPersistTaps="handled"
6870
showsVerticalScrollIndicator={false}
6971
>

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Alert, ActivityIndicator, ScrollView, StyleSheet, Text, View } from 'react-native';
22

33
import { ActionButton, InlineBadge, ScreenTitle, SectionCard, ToggleRow } from '../components';
4+
import { useLabContentStyle } from '../layout';
45
import { useAppColors, type AppColors } from '../theme';
56
import { GestureLab } from './GestureLab';
67

@@ -21,6 +22,7 @@ export interface HomeScreenProps {
2122
export function HomeScreen(props: HomeScreenProps) {
2223
const colors = useAppColors();
2324
const styles = createStyles(colors);
25+
const contentStyle = useLabContentStyle();
2426

2527
function showConfirmationAlert() {
2628
Alert.alert(
@@ -42,7 +44,10 @@ export function HomeScreen(props: HomeScreenProps) {
4244
}
4345

4446
return (
45-
<ScrollView contentContainerStyle={styles.content} showsVerticalScrollIndicator={false}>
47+
<ScrollView
48+
contentContainerStyle={[styles.content, contentStyle]}
49+
showsVerticalScrollIndicator={false}
50+
>
4651
<ScreenTitle
4752
badge={`${props.cartCount} in cart`}
4853
subtitle="An app for testing all the functionality of agent-device."

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from 'react-native';
1010

1111
import { ActionButton, InlineBadge, ScreenTitle, SectionCard, ToggleRow } from '../components';
12+
import { useLabContentStyle } from '../layout';
1213
import { useAppColors, type AppColors } from '../theme';
1314

1415
export interface SettingsScreenProps {
@@ -32,6 +33,7 @@ export interface SettingsScreenProps {
3233
export function SettingsScreen(props: SettingsScreenProps) {
3334
const colors = useAppColors();
3435
const styles = createStyles(colors);
36+
const contentStyle = useLabContentStyle();
3537

3638
function showResetAlert() {
3739
Alert.alert(
@@ -55,7 +57,10 @@ export function SettingsScreen(props: SettingsScreenProps) {
5557
}
5658

5759
return (
58-
<ScrollView contentContainerStyle={styles.content} showsVerticalScrollIndicator={false}>
60+
<ScrollView
61+
contentContainerStyle={[styles.content, contentStyle]}
62+
showsVerticalScrollIndicator={false}
63+
>
5964
<ScreenTitle
6065
badge="Debug"
6166
subtitle="Toggles, accordion content, loading states, retryable error banners, and native alerts."

0 commit comments

Comments
 (0)