agentic-mobile-kit 0.5.4 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -1
- package/bin/cli.js +1 -1
- package/lib/doctor.js +26 -5
- package/lib/init.js +235 -49
- package/package.json +4 -2
- package/stacks/react-native/expo/.agents/skills/LICENSE-expo +21 -0
- package/stacks/react-native/expo/.agents/skills/THIRD_PARTY.md +11 -0
- package/stacks/react-native/expo/.agents/skills/expo-module/SKILL.md +151 -0
- package/stacks/react-native/expo/.agents/skills/expo-module/agents/openai.yaml +4 -0
- package/stacks/react-native/expo/.agents/skills/expo-module/references/config-plugin.md +90 -0
- package/stacks/react-native/expo/.agents/skills/expo-module/references/create-expo-module.md +206 -0
- package/stacks/react-native/expo/.agents/skills/expo-module/references/lifecycle.md +127 -0
- package/stacks/react-native/expo/.agents/skills/expo-module/references/module-config.md +48 -0
- package/stacks/react-native/expo/.agents/skills/expo-module/references/native-module.md +286 -0
- package/stacks/react-native/expo/.agents/skills/expo-module/references/native-view.md +171 -0
- package/stacks/react-native/expo/.agents/skills/expo-router/SKILL.md +240 -0
- package/stacks/react-native/expo/.agents/skills/expo-router/agents/openai.yaml +4 -0
- package/stacks/react-native/expo/.agents/skills/expo-router/references/form-sheet.md +253 -0
- package/stacks/react-native/expo/.agents/skills/expo-router/references/route-structure.md +229 -0
- package/stacks/react-native/expo/.agents/skills/expo-router/references/search.md +248 -0
- package/stacks/react-native/expo/.agents/skills/expo-router/references/tabs.md +433 -0
- package/stacks/react-native/expo/.agents/skills/expo-router/references/toolbar-and-headers.md +284 -0
- package/stacks/react-native/expo/.agents/skills/expo-router/references/zoom-transitions.md +158 -0
- package/stacks/react-native/expo/.agents/skills/expo-upgrade/SKILL.md +150 -0
- package/stacks/react-native/expo/.agents/skills/expo-upgrade/agents/openai.yaml +4 -0
- package/stacks/react-native/expo/.agents/skills/expo-upgrade/references/expo-av-to-audio.md +132 -0
- package/stacks/react-native/expo/.agents/skills/expo-upgrade/references/expo-av-to-video.md +160 -0
- package/stacks/react-native/expo/.agents/skills/expo-upgrade/references/native-tabs.md +124 -0
- package/stacks/react-native/expo/.agents/skills/expo-upgrade/references/new-architecture.md +79 -0
- package/stacks/react-native/expo/.agents/skills/expo-upgrade/references/react-19.md +79 -0
- package/stacks/react-native/expo/.agents/skills/expo-upgrade/references/react-compiler.md +59 -0
- package/stacks/react-native/expo/.agents/skills/expo-upgrade/references/react-navigation-to-expo-router.md +61 -0
- package/stacks/react-native/expo/.rulesync/permissions.jsonc +40 -0
- package/stacks/react-native/expo/AGENTS.md +52 -0
- package/stacks/react-native/expo/docs/ai/expo.md +35 -0
- package/stacks/react-native/expo/docs/ai/known-issues.md +32 -0
- package/stacks/react-native/template/.agents/skills/m-release/SKILL.md +5 -4
- package/stacks/react-native/template/.githooks/pre-commit +7 -2
- package/stacks/react-native/template/.github/workflows/e2e.yml +2 -0
- package/stacks/react-native/template/.github/workflows/ios.yml +3 -5
- package/stacks/react-native/template/AGENTS.md +4 -4
- package/stacks/react-native/template/codemagic.yaml +2 -1
- package/stacks/react-native/template/docs/ai/known-issues.md +12 -2
- package/stacks/react-native/template/docs/ai/react-native.md +5 -4
- package/stacks/react-native/template/scripts/ai/android-flavors.js +41 -0
- package/stacks/react-native/template/scripts/ai/case-check.js +35 -0
- package/stacks/react-native/template/scripts/ai/install-deps.sh +4 -1
- package/stacks/react-native/template/scripts/ai/ios-build.sh +10 -3
- package/stacks/react-native/template/scripts/ai/pm-run.sh +12 -0
- package/stacks/react-native/template/scripts/ai/pod-install.sh +12 -0
- package/stacks/react-native/template/scripts/ai/prebuild.sh +28 -0
- package/stacks/react-native/template/scripts/ai/release-build.sh +32 -8
- package/stacks/react-native/template/scripts/ai/release-check.js +98 -18
- package/stacks/react-native/template/scripts/ai/set-version.sh +19 -1
- package/stacks/react-native/template/scripts/ai/verify.sh +69 -16
- package/stacks/react-native/template/specs/_templates/flow.yaml +9 -0
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
# Form Sheets in Expo Router
|
|
2
|
+
|
|
3
|
+
This skill covers implementing form sheets with footers using Expo Router's Stack navigator and react-native-screens.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Form sheets are modal presentations that appear as a card sliding up from the bottom of the screen. They're ideal for:
|
|
8
|
+
|
|
9
|
+
- Quick actions and confirmations
|
|
10
|
+
- Settings panels
|
|
11
|
+
- Login/signup flows
|
|
12
|
+
- Action sheets with custom content
|
|
13
|
+
|
|
14
|
+
**Requirements:**
|
|
15
|
+
|
|
16
|
+
- Expo Router Stack navigator
|
|
17
|
+
|
|
18
|
+
## Basic Usage
|
|
19
|
+
|
|
20
|
+
### Form Sheet with Footer
|
|
21
|
+
|
|
22
|
+
Configure the Stack.Screen with transparent backgrounds and sheet presentation:
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
// app/_layout.tsx
|
|
26
|
+
import { Stack } from "expo-router";
|
|
27
|
+
|
|
28
|
+
export default function Layout() {
|
|
29
|
+
return (
|
|
30
|
+
<Stack>
|
|
31
|
+
<Stack.Screen name="index" />
|
|
32
|
+
<Stack.Screen
|
|
33
|
+
name="about"
|
|
34
|
+
options={{
|
|
35
|
+
presentation: "formSheet",
|
|
36
|
+
sheetAllowedDetents: [0.25],
|
|
37
|
+
headerTransparent: true,
|
|
38
|
+
contentStyle: { backgroundColor: "transparent" },
|
|
39
|
+
sheetGrabberVisible: true,
|
|
40
|
+
}}
|
|
41
|
+
>
|
|
42
|
+
<Stack.Header style={{ backgroundColor: "transparent" }}></Stack.Header>
|
|
43
|
+
</Stack.Screen>
|
|
44
|
+
</Stack>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Form Sheet Screen Content
|
|
50
|
+
|
|
51
|
+
> Requires Expo SDK 55 or later.
|
|
52
|
+
|
|
53
|
+
Use `flex: 1` to allow the content to fill available space, enabling footer positioning:
|
|
54
|
+
|
|
55
|
+
```tsx
|
|
56
|
+
// app/about.tsx
|
|
57
|
+
import { View, Text, StyleSheet } from "react-native";
|
|
58
|
+
|
|
59
|
+
export default function AboutSheet() {
|
|
60
|
+
return (
|
|
61
|
+
<View style={styles.container}>
|
|
62
|
+
{/* Main content */}
|
|
63
|
+
<View style={styles.content}>
|
|
64
|
+
<Text>Sheet Content</Text>
|
|
65
|
+
</View>
|
|
66
|
+
|
|
67
|
+
{/* Footer - stays at bottom */}
|
|
68
|
+
<View style={styles.footer}>
|
|
69
|
+
<Text>Footer Content</Text>
|
|
70
|
+
</View>
|
|
71
|
+
</View>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const styles = StyleSheet.create({
|
|
76
|
+
container: {
|
|
77
|
+
flex: 1,
|
|
78
|
+
},
|
|
79
|
+
content: {
|
|
80
|
+
flex: 1,
|
|
81
|
+
padding: 16,
|
|
82
|
+
},
|
|
83
|
+
footer: {
|
|
84
|
+
padding: 16,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Formsheet with interactive content below
|
|
90
|
+
|
|
91
|
+
Use `sheetLargestUndimmedDetentIndex` (zero-indexed) to keep content behind the form sheet interactive — e.g. letting users pan a map beneath it. Setting it to `1` allows interaction at the first two detents but dims on the third.
|
|
92
|
+
|
|
93
|
+
```tsx
|
|
94
|
+
// app/_layout.tsx
|
|
95
|
+
import { Stack } from 'expo-router';
|
|
96
|
+
|
|
97
|
+
export default function Layout() {
|
|
98
|
+
return (
|
|
99
|
+
<Stack screenOptions={{ headerShown: false }}>
|
|
100
|
+
<Stack.Screen name="index" />
|
|
101
|
+
<Stack.Screen
|
|
102
|
+
name="info-sheet"
|
|
103
|
+
options={{
|
|
104
|
+
presentation: "formSheet",
|
|
105
|
+
sheetAllowedDetents: [0.2, 0.5, 1.0],
|
|
106
|
+
sheetLargestUndimmedDetentIndex: 1,
|
|
107
|
+
/* other options */
|
|
108
|
+
}}
|
|
109
|
+
/>
|
|
110
|
+
</Stack>
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Key Options
|
|
116
|
+
|
|
117
|
+
| Option | Type | Description |
|
|
118
|
+
| --------------------- | ---------- | ----------------------------------------------------------- |
|
|
119
|
+
| `presentation` | `string` | Set to `'formSheet'` for sheet presentation |
|
|
120
|
+
| `sheetGrabberVisible` | `boolean` | Shows the drag handle at the top of the sheet |
|
|
121
|
+
| `sheetAllowedDetents` | `number[]` | Array of detent heights (0-1 range, e.g., `[0.25]` for 25%) |
|
|
122
|
+
| `headerTransparent` | `boolean` | Makes header background transparent |
|
|
123
|
+
| `contentStyle` | `object` | Style object for the screen content container |
|
|
124
|
+
| `title` | `string` | Screen title (set to `''` for no title) |
|
|
125
|
+
|
|
126
|
+
## Common Detent Values
|
|
127
|
+
|
|
128
|
+
- `[0.25]` - Quarter sheet (compact actions)
|
|
129
|
+
- `[0.5]` - Half sheet (medium content)
|
|
130
|
+
- `[0.75]` - Three-quarter sheet (detailed forms)
|
|
131
|
+
- `[0.25, 0.5, 1]` - Multiple stops (expandable sheet)
|
|
132
|
+
|
|
133
|
+
## Complete Example
|
|
134
|
+
|
|
135
|
+
```tsx
|
|
136
|
+
// _layout.tsx
|
|
137
|
+
import { Stack } from "expo-router";
|
|
138
|
+
|
|
139
|
+
export default function Layout() {
|
|
140
|
+
return (
|
|
141
|
+
<Stack>
|
|
142
|
+
<Stack.Screen name="index" options={{ title: "Home" }} />
|
|
143
|
+
<Stack.Screen
|
|
144
|
+
name="confirm"
|
|
145
|
+
options={{
|
|
146
|
+
contentStyle: { backgroundColor: "transparent" },
|
|
147
|
+
presentation: "formSheet",
|
|
148
|
+
title: "",
|
|
149
|
+
sheetGrabberVisible: true,
|
|
150
|
+
sheetAllowedDetents: [0.25],
|
|
151
|
+
headerTransparent: true,
|
|
152
|
+
}}
|
|
153
|
+
>
|
|
154
|
+
<Stack.Header style={{ backgroundColor: "transparent" }}>
|
|
155
|
+
<Stack.Header.Right />
|
|
156
|
+
</Stack.Header>
|
|
157
|
+
</Stack.Screen>
|
|
158
|
+
</Stack>
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
```tsx
|
|
164
|
+
// app/confirm.tsx
|
|
165
|
+
import { View, Text, Pressable, StyleSheet } from "react-native";
|
|
166
|
+
import { router } from "expo-router";
|
|
167
|
+
|
|
168
|
+
export default function ConfirmSheet() {
|
|
169
|
+
return (
|
|
170
|
+
<View style={styles.container}>
|
|
171
|
+
<View style={styles.content}>
|
|
172
|
+
<Text style={styles.title}>Confirm Action</Text>
|
|
173
|
+
<Text style={styles.description}>
|
|
174
|
+
Are you sure you want to proceed?
|
|
175
|
+
</Text>
|
|
176
|
+
</View>
|
|
177
|
+
|
|
178
|
+
<View style={styles.footer}>
|
|
179
|
+
<Pressable style={styles.cancelButton} onPress={() => router.back()}>
|
|
180
|
+
<Text style={styles.cancelText}>Cancel</Text>
|
|
181
|
+
</Pressable>
|
|
182
|
+
<Pressable style={styles.confirmButton} onPress={() => router.back()}>
|
|
183
|
+
<Text style={styles.confirmText}>Confirm</Text>
|
|
184
|
+
</Pressable>
|
|
185
|
+
</View>
|
|
186
|
+
</View>
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const styles = StyleSheet.create({
|
|
191
|
+
container: {
|
|
192
|
+
flex: 1,
|
|
193
|
+
},
|
|
194
|
+
content: {
|
|
195
|
+
flex: 1,
|
|
196
|
+
padding: 20,
|
|
197
|
+
alignItems: "center",
|
|
198
|
+
justifyContent: "center",
|
|
199
|
+
},
|
|
200
|
+
title: {
|
|
201
|
+
fontSize: 18,
|
|
202
|
+
fontWeight: "600",
|
|
203
|
+
marginBottom: 8,
|
|
204
|
+
},
|
|
205
|
+
description: {
|
|
206
|
+
fontSize: 14,
|
|
207
|
+
color: "#666",
|
|
208
|
+
textAlign: "center",
|
|
209
|
+
},
|
|
210
|
+
footer: {
|
|
211
|
+
flexDirection: "row",
|
|
212
|
+
padding: 16,
|
|
213
|
+
gap: 12,
|
|
214
|
+
},
|
|
215
|
+
cancelButton: {
|
|
216
|
+
flex: 1,
|
|
217
|
+
padding: 14,
|
|
218
|
+
borderRadius: 10,
|
|
219
|
+
backgroundColor: "#f0f0f0",
|
|
220
|
+
alignItems: "center",
|
|
221
|
+
},
|
|
222
|
+
cancelText: {
|
|
223
|
+
fontSize: 16,
|
|
224
|
+
fontWeight: "500",
|
|
225
|
+
},
|
|
226
|
+
confirmButton: {
|
|
227
|
+
flex: 1,
|
|
228
|
+
padding: 14,
|
|
229
|
+
borderRadius: 10,
|
|
230
|
+
backgroundColor: "#007AFF",
|
|
231
|
+
alignItems: "center",
|
|
232
|
+
},
|
|
233
|
+
confirmText: {
|
|
234
|
+
fontSize: 16,
|
|
235
|
+
fontWeight: "500",
|
|
236
|
+
color: "white",
|
|
237
|
+
},
|
|
238
|
+
});
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Troubleshooting
|
|
242
|
+
|
|
243
|
+
### Content not filling sheet
|
|
244
|
+
|
|
245
|
+
Make sure the root View uses `flex: 1`:
|
|
246
|
+
|
|
247
|
+
```tsx
|
|
248
|
+
<View style={{ flex: 1 }}>{/* content */}</View>
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### Sheet background showing through
|
|
252
|
+
|
|
253
|
+
Set `contentStyle: { backgroundColor: 'transparent' }` in options and style your content container with the desired background color instead.
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
# Route Structure
|
|
2
|
+
|
|
3
|
+
## File Conventions
|
|
4
|
+
|
|
5
|
+
- Routes belong in the `app` directory
|
|
6
|
+
- Use `[]` for dynamic routes, e.g. `[id].tsx`
|
|
7
|
+
- Routes can never be named `(foo).tsx` - use `(foo)/index.tsx` instead
|
|
8
|
+
- Use `(group)` routes to simplify the public URL structure
|
|
9
|
+
- NEVER co-locate components, types, or utilities in the app directory - these should be in separate directories like `components/`, `utils/`, etc.
|
|
10
|
+
- The app directory should only contain route and `_layout` files; every file should export a default component
|
|
11
|
+
- Ensure the app always has a route that matches "/" so the app is never blank
|
|
12
|
+
- ALWAYS use `_layout.tsx` files to define stacks
|
|
13
|
+
|
|
14
|
+
## Dynamic Routes
|
|
15
|
+
|
|
16
|
+
Use square brackets for dynamic segments:
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
app/
|
|
20
|
+
users/
|
|
21
|
+
[id].tsx # Matches /users/123, /users/abc
|
|
22
|
+
[id]/
|
|
23
|
+
posts.tsx # Matches /users/123/posts
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Catch-All Routes
|
|
27
|
+
|
|
28
|
+
Use `[...slug]` for catch-all routes:
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
app/
|
|
32
|
+
docs/
|
|
33
|
+
[...slug].tsx # Matches /docs/a, /docs/a/b, /docs/a/b/c
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Query Parameters
|
|
37
|
+
|
|
38
|
+
Access query parameters with the `useLocalSearchParams` hook:
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
import { useLocalSearchParams } from "expo-router";
|
|
42
|
+
|
|
43
|
+
function Page() {
|
|
44
|
+
const { id } = useLocalSearchParams<{ id: string }>();
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
For dynamic routes, the parameter name matches the file name:
|
|
49
|
+
|
|
50
|
+
- `[id].tsx` → `useLocalSearchParams<{ id: string }>()`
|
|
51
|
+
- `[slug].tsx` → `useLocalSearchParams<{ slug: string }>()`
|
|
52
|
+
|
|
53
|
+
## Pathname
|
|
54
|
+
|
|
55
|
+
Access the current pathname with the `usePathname` hook:
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
import { usePathname } from "expo-router";
|
|
59
|
+
|
|
60
|
+
function Component() {
|
|
61
|
+
const pathname = usePathname(); // e.g. "/users/123"
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Group Routes
|
|
66
|
+
|
|
67
|
+
Use parentheses for groups that don't affect the URL:
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
app/
|
|
71
|
+
(auth)/
|
|
72
|
+
login.tsx # URL: /login
|
|
73
|
+
register.tsx # URL: /register
|
|
74
|
+
(main)/
|
|
75
|
+
index.tsx # URL: /
|
|
76
|
+
settings.tsx # URL: /settings
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Groups are useful for:
|
|
80
|
+
|
|
81
|
+
- Organizing related routes
|
|
82
|
+
- Applying different layouts to route groups
|
|
83
|
+
- Keeping URLs clean
|
|
84
|
+
|
|
85
|
+
## Stacks and Tabs Structure
|
|
86
|
+
|
|
87
|
+
When an app has tabs, the header and title should be set in a Stack that is nested INSIDE each tab. This allows tabs to have their own headers and distinct histories. The root layout should often not have a header.
|
|
88
|
+
|
|
89
|
+
- Set the 'headerShown' option to false on the tab layout
|
|
90
|
+
- Use (group) routes to simplify the public URL structure
|
|
91
|
+
- You may need to delete or refactor existing routes to fit this structure
|
|
92
|
+
|
|
93
|
+
Example structure:
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
app/
|
|
97
|
+
_layout.tsx — <Tabs />
|
|
98
|
+
(home)/
|
|
99
|
+
_layout.tsx — <Stack />
|
|
100
|
+
index.tsx — <ScrollView />
|
|
101
|
+
(settings)/
|
|
102
|
+
_layout.tsx — <Stack />
|
|
103
|
+
index.tsx — <ScrollView />
|
|
104
|
+
(home,settings)/
|
|
105
|
+
info.tsx — <ScrollView /> (shared across tabs)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Array Routes for Multiple Stacks
|
|
109
|
+
|
|
110
|
+
Use array routes '(index,settings)' to create multiple stacks. This is useful for tabs that need to share screens across stacks.
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
app/
|
|
114
|
+
_layout.tsx — <Tabs />
|
|
115
|
+
(index,settings)/
|
|
116
|
+
_layout.tsx — <Stack />
|
|
117
|
+
index.tsx — <ScrollView />
|
|
118
|
+
settings.tsx — <ScrollView />
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
This requires a specialized layout with explicit anchor routes:
|
|
122
|
+
|
|
123
|
+
```tsx
|
|
124
|
+
// app/(index,settings)/_layout.tsx
|
|
125
|
+
import { useMemo } from "react";
|
|
126
|
+
import Stack from "expo-router/stack";
|
|
127
|
+
|
|
128
|
+
export const unstable_settings = {
|
|
129
|
+
index: { anchor: "index" },
|
|
130
|
+
settings: { anchor: "settings" },
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export default function Layout({ segment }: { segment: string }) {
|
|
134
|
+
const screen = segment.match(/\((.*)\)/)?.[1]!;
|
|
135
|
+
|
|
136
|
+
const options = useMemo(() => {
|
|
137
|
+
switch (screen) {
|
|
138
|
+
case "index":
|
|
139
|
+
return { headerRight: () => <></> };
|
|
140
|
+
default:
|
|
141
|
+
return {};
|
|
142
|
+
}
|
|
143
|
+
}, [screen]);
|
|
144
|
+
|
|
145
|
+
return (
|
|
146
|
+
<Stack>
|
|
147
|
+
<Stack.Screen name={screen} options={options} />
|
|
148
|
+
</Stack>
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Complete App Structure Example
|
|
154
|
+
|
|
155
|
+
```
|
|
156
|
+
app/
|
|
157
|
+
_layout.tsx — <NativeTabs />
|
|
158
|
+
(index,search)/
|
|
159
|
+
_layout.tsx — <Stack />
|
|
160
|
+
index.tsx — Main list
|
|
161
|
+
search.tsx — Search view
|
|
162
|
+
i/[id].tsx — Detail page
|
|
163
|
+
components/
|
|
164
|
+
theme.tsx
|
|
165
|
+
list.tsx
|
|
166
|
+
utils/
|
|
167
|
+
storage.ts
|
|
168
|
+
use-search.ts
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Layout Files
|
|
172
|
+
|
|
173
|
+
Every directory can have a `_layout.tsx` file that wraps all routes in that directory:
|
|
174
|
+
|
|
175
|
+
```tsx
|
|
176
|
+
// app/_layout.tsx
|
|
177
|
+
import { Stack } from "expo-router/stack";
|
|
178
|
+
|
|
179
|
+
export default function RootLayout() {
|
|
180
|
+
return <Stack />;
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
```tsx
|
|
185
|
+
// app/(tabs)/_layout.tsx
|
|
186
|
+
import { NativeTabs, Icon, Label } from "expo-router/unstable-native-tabs";
|
|
187
|
+
|
|
188
|
+
export default function TabLayout() {
|
|
189
|
+
return (
|
|
190
|
+
<NativeTabs>
|
|
191
|
+
<NativeTabs.Trigger name="index">
|
|
192
|
+
<Label>Home</Label>
|
|
193
|
+
<Icon sf="house.fill" />
|
|
194
|
+
</NativeTabs.Trigger>
|
|
195
|
+
</NativeTabs>
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Route Settings
|
|
201
|
+
|
|
202
|
+
Export `unstable_settings` to configure route behavior:
|
|
203
|
+
|
|
204
|
+
```tsx
|
|
205
|
+
export const unstable_settings = {
|
|
206
|
+
anchor: "index",
|
|
207
|
+
};
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
- `initialRouteName` was renamed to `anchor` in v4
|
|
211
|
+
|
|
212
|
+
## Not Found Routes
|
|
213
|
+
|
|
214
|
+
Create a `+not-found.tsx` file to handle unmatched routes:
|
|
215
|
+
|
|
216
|
+
```tsx
|
|
217
|
+
// app/+not-found.tsx
|
|
218
|
+
import { Link } from "expo-router";
|
|
219
|
+
import { View, Text } from "react-native";
|
|
220
|
+
|
|
221
|
+
export default function NotFound() {
|
|
222
|
+
return (
|
|
223
|
+
<View>
|
|
224
|
+
<Text>Page not found</Text>
|
|
225
|
+
<Link href="/">Go home</Link>
|
|
226
|
+
</View>
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
```
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
# Search
|
|
2
|
+
|
|
3
|
+
## Header Search Bar
|
|
4
|
+
|
|
5
|
+
Add a search bar to the stack header with `headerSearchBarOptions`:
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
<Stack.Screen
|
|
9
|
+
name="index"
|
|
10
|
+
options={{
|
|
11
|
+
headerSearchBarOptions: {
|
|
12
|
+
placeholder: "Search",
|
|
13
|
+
onChangeText: (event) => console.log(event.nativeEvent.text),
|
|
14
|
+
},
|
|
15
|
+
}}
|
|
16
|
+
/>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Options
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
headerSearchBarOptions: {
|
|
23
|
+
// Placeholder text
|
|
24
|
+
placeholder: "Search items...",
|
|
25
|
+
|
|
26
|
+
// Auto-capitalize behavior
|
|
27
|
+
autoCapitalize: "none",
|
|
28
|
+
|
|
29
|
+
// Input type
|
|
30
|
+
inputType: "text", // "text" | "phone" | "number" | "email"
|
|
31
|
+
|
|
32
|
+
// Cancel button text (iOS)
|
|
33
|
+
cancelButtonText: "Cancel",
|
|
34
|
+
|
|
35
|
+
// Hide when scrolling (iOS)
|
|
36
|
+
hideWhenScrolling: true,
|
|
37
|
+
|
|
38
|
+
// Hide navigation bar during search (iOS)
|
|
39
|
+
hideNavigationBar: true,
|
|
40
|
+
|
|
41
|
+
// Obscure background during search (iOS)
|
|
42
|
+
obscureBackground: true,
|
|
43
|
+
|
|
44
|
+
// Placement
|
|
45
|
+
placement: "automatic", // "automatic" | "inline" | "stacked"
|
|
46
|
+
|
|
47
|
+
// Callbacks
|
|
48
|
+
onChangeText: (event) => {},
|
|
49
|
+
onSearchButtonPress: (event) => {},
|
|
50
|
+
onCancelButtonPress: (event) => {},
|
|
51
|
+
onFocus: () => {},
|
|
52
|
+
onBlur: () => {},
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## useSearch Hook
|
|
57
|
+
|
|
58
|
+
Reusable hook for search state management:
|
|
59
|
+
|
|
60
|
+
```tsx
|
|
61
|
+
import { useEffect, useState } from "react";
|
|
62
|
+
import { useNavigation } from "expo-router";
|
|
63
|
+
|
|
64
|
+
export function useSearch(options: any = {}) {
|
|
65
|
+
const [search, setSearch] = useState("");
|
|
66
|
+
const navigation = useNavigation();
|
|
67
|
+
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
navigation.setOptions({
|
|
70
|
+
headerShown: true,
|
|
71
|
+
headerSearchBarOptions: {
|
|
72
|
+
...options,
|
|
73
|
+
onChangeText(e: any) {
|
|
74
|
+
setSearch(e.nativeEvent.text);
|
|
75
|
+
options.onChangeText?.(e);
|
|
76
|
+
},
|
|
77
|
+
onSearchButtonPress(e: any) {
|
|
78
|
+
setSearch(e.nativeEvent.text);
|
|
79
|
+
options.onSearchButtonPress?.(e);
|
|
80
|
+
},
|
|
81
|
+
onCancelButtonPress(e: any) {
|
|
82
|
+
setSearch("");
|
|
83
|
+
options.onCancelButtonPress?.(e);
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}, [options, navigation]);
|
|
88
|
+
|
|
89
|
+
return search;
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Usage
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
function SearchScreen() {
|
|
97
|
+
const search = useSearch({ placeholder: "Search items..." });
|
|
98
|
+
|
|
99
|
+
const filteredItems = items.filter(item =>
|
|
100
|
+
item.name.toLowerCase().includes(search.toLowerCase())
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<FlatList
|
|
105
|
+
data={filteredItems}
|
|
106
|
+
renderItem={({ item }) => <ItemRow item={item} />}
|
|
107
|
+
/>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Filtering Patterns
|
|
113
|
+
|
|
114
|
+
### Simple Text Filter
|
|
115
|
+
|
|
116
|
+
```tsx
|
|
117
|
+
const filtered = items.filter(item =>
|
|
118
|
+
item.name.toLowerCase().includes(search.toLowerCase())
|
|
119
|
+
);
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Multiple Fields
|
|
123
|
+
|
|
124
|
+
```tsx
|
|
125
|
+
const filtered = items.filter(item => {
|
|
126
|
+
const query = search.toLowerCase();
|
|
127
|
+
return (
|
|
128
|
+
item.name.toLowerCase().includes(query) ||
|
|
129
|
+
item.description.toLowerCase().includes(query) ||
|
|
130
|
+
item.tags.some(tag => tag.toLowerCase().includes(query))
|
|
131
|
+
);
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Debounced Search
|
|
136
|
+
|
|
137
|
+
For expensive filtering or API calls:
|
|
138
|
+
|
|
139
|
+
```tsx
|
|
140
|
+
import { useState, useEffect, useMemo } from "react";
|
|
141
|
+
|
|
142
|
+
function useDebounce<T>(value: T, delay: number): T {
|
|
143
|
+
const [debounced, setDebounced] = useState(value);
|
|
144
|
+
|
|
145
|
+
useEffect(() => {
|
|
146
|
+
const timer = setTimeout(() => setDebounced(value), delay);
|
|
147
|
+
return () => clearTimeout(timer);
|
|
148
|
+
}, [value, delay]);
|
|
149
|
+
|
|
150
|
+
return debounced;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function SearchScreen() {
|
|
154
|
+
const search = useSearch();
|
|
155
|
+
const debouncedSearch = useDebounce(search, 300);
|
|
156
|
+
|
|
157
|
+
const filteredItems = useMemo(() =>
|
|
158
|
+
items.filter(item =>
|
|
159
|
+
item.name.toLowerCase().includes(debouncedSearch.toLowerCase())
|
|
160
|
+
),
|
|
161
|
+
[debouncedSearch]
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
return <FlatList data={filteredItems} />;
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Search with Native Tabs
|
|
169
|
+
|
|
170
|
+
When using NativeTabs with a search role, the search bar integrates with the tab bar:
|
|
171
|
+
|
|
172
|
+
```tsx
|
|
173
|
+
// app/_layout.tsx
|
|
174
|
+
<NativeTabs>
|
|
175
|
+
<NativeTabs.Trigger name="(home)">
|
|
176
|
+
<Label>Home</Label>
|
|
177
|
+
<Icon sf="house.fill" />
|
|
178
|
+
</NativeTabs.Trigger>
|
|
179
|
+
<NativeTabs.Trigger name="(search)" role="search">
|
|
180
|
+
<Label>Search</Label>
|
|
181
|
+
</NativeTabs.Trigger>
|
|
182
|
+
</NativeTabs>
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
```tsx
|
|
186
|
+
// app/(search)/_layout.tsx
|
|
187
|
+
<Stack>
|
|
188
|
+
<Stack.Screen
|
|
189
|
+
name="index"
|
|
190
|
+
options={{
|
|
191
|
+
headerSearchBarOptions: {
|
|
192
|
+
placeholder: "Search...",
|
|
193
|
+
onChangeText: (e) => setSearch(e.nativeEvent.text),
|
|
194
|
+
},
|
|
195
|
+
}}
|
|
196
|
+
/>
|
|
197
|
+
</Stack>
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Empty States
|
|
201
|
+
|
|
202
|
+
Show appropriate UI when search returns no results:
|
|
203
|
+
|
|
204
|
+
```tsx
|
|
205
|
+
function SearchResults({ search, items }) {
|
|
206
|
+
const filtered = items.filter(/* ... */);
|
|
207
|
+
|
|
208
|
+
if (search && filtered.length === 0) {
|
|
209
|
+
return (
|
|
210
|
+
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
|
|
211
|
+
<Text style={{ color: colors.secondaryLabel }}>
|
|
212
|
+
No results for "{search}"
|
|
213
|
+
</Text>
|
|
214
|
+
</View>
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return <FlatList data={filtered} />;
|
|
219
|
+
}
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## Search Suggestions
|
|
223
|
+
|
|
224
|
+
Show recent searches or suggestions:
|
|
225
|
+
|
|
226
|
+
```tsx
|
|
227
|
+
function SearchScreen() {
|
|
228
|
+
const search = useSearch();
|
|
229
|
+
const [recentSearches, setRecentSearches] = useState<string[]>([]);
|
|
230
|
+
|
|
231
|
+
if (!search && recentSearches.length > 0) {
|
|
232
|
+
return (
|
|
233
|
+
<View>
|
|
234
|
+
<Text style={{ color: colors.secondaryLabel }}>
|
|
235
|
+
Recent Searches
|
|
236
|
+
</Text>
|
|
237
|
+
{recentSearches.map((term) => (
|
|
238
|
+
<Pressable key={term} onPress={() => /* apply search */}>
|
|
239
|
+
<Text>{term}</Text>
|
|
240
|
+
</Pressable>
|
|
241
|
+
))}
|
|
242
|
+
</View>
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return <SearchResults search={search} />;
|
|
247
|
+
}
|
|
248
|
+
```
|