agentic-mobile-kit 0.0.1 → 0.1.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 +20 -8
- package/bin/cli.js +31 -5
- package/lib/init.js +199 -0
- package/package.json +17 -3
- package/stacks/react-native/template/.agents/skills/LICENSE-callstack +21 -0
- package/stacks/react-native/template/.agents/skills/THIRD_PARTY.md +9 -0
- package/stacks/react-native/template/.agents/skills/m-bugfix/SKILL.md +23 -0
- package/stacks/react-native/template/.agents/skills/m-bugfix/agents/openai.yaml +3 -0
- package/stacks/react-native/template/.agents/skills/m-continue/SKILL.md +22 -0
- package/stacks/react-native/template/.agents/skills/m-continue/agents/openai.yaml +3 -0
- package/stacks/react-native/template/.agents/skills/m-feature/SKILL.md +50 -0
- package/stacks/react-native/template/.agents/skills/m-feature/agents/openai.yaml +3 -0
- package/stacks/react-native/template/.agents/skills/m-pause/SKILL.md +14 -0
- package/stacks/react-native/template/.agents/skills/m-pause/agents/openai.yaml +3 -0
- package/stacks/react-native/template/.agents/skills/m-review/SKILL.md +29 -0
- package/stacks/react-native/template/.agents/skills/m-review/agents/openai.yaml +3 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/POWER.md +172 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/SKILL.md +238 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/agents/openai.yaml +4 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/bundle-analyze-app.md +208 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/bundle-analyze-js.md +264 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/bundle-barrel-exports.md +250 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/bundle-code-splitting.md +255 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/bundle-hermes-mmap.md +167 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/bundle-library-size.md +164 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/bundle-native-assets.md +208 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/bundle-r8-android.md +231 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/bundle-tree-shaking.md +215 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/js-animations-reanimated.md +273 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/js-atomic-state.md +190 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/js-bottomsheet.md +339 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/js-concurrent-react.md +238 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/js-lists-flatlist-flashlist.md +223 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/js-measure-fps.md +178 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/js-memory-leaks.md +168 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/js-profile-react.md +138 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/js-react-compiler.md +261 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/js-uncontrolled-components.md +219 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/native-android-16kb-alignment.md +114 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/native-measure-tti.md +221 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/native-memory-leaks.md +206 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/native-memory-patterns.md +240 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/native-platform-setup.md +112 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/native-profiling.md +140 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/native-sdks-over-polyfills.md +192 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/native-threading-model.md +230 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/native-turbo-modules.md +210 -0
- package/stacks/react-native/template/.agents/skills/react-native-best-practices/references/native-view-flattening.md +180 -0
- package/stacks/react-native/template/.agents/skills/react-navigation/SKILL.md +63 -0
- package/stacks/react-native/template/.agents/skills/react-navigation/agents/openai.yaml +4 -0
- package/stacks/react-native/template/.agents/skills/react-navigation/references/bottom-tabs.md +496 -0
- package/stacks/react-native/template/.agents/skills/react-navigation/references/drawers.md +474 -0
- package/stacks/react-native/template/.agents/skills/react-navigation/references/form-sheet.md +305 -0
- package/stacks/react-native/template/.agents/skills/react-navigation/references/header.md +270 -0
- package/stacks/react-native/template/.agents/skills/react-navigation/references/material-top-tabs.md +453 -0
- package/stacks/react-native/template/.agents/skills/react-navigation/references/native-bottom-tabs.md +365 -0
- package/stacks/react-native/template/.agents/skills/react-navigation/references/safe-areas.md +95 -0
- package/stacks/react-native/template/.agents/skills/react-navigation/references/stacks.md +392 -0
- package/stacks/react-native/template/.agents/skills/upgrading-react-native/SKILL.md +79 -0
- package/stacks/react-native/template/.agents/skills/upgrading-react-native/agents/openai.yaml +4 -0
- package/stacks/react-native/template/.agents/skills/upgrading-react-native/references/expo-sdk-upgrade.md +65 -0
- package/stacks/react-native/template/.agents/skills/upgrading-react-native/references/monorepo-singlerepo-targeting.md +34 -0
- package/stacks/react-native/template/.agents/skills/upgrading-react-native/references/react.md +42 -0
- package/stacks/react-native/template/.agents/skills/upgrading-react-native/references/upgrade-helper-core.md +122 -0
- package/stacks/react-native/template/.agents/skills/upgrading-react-native/references/upgrade-verification.md +53 -0
- package/stacks/react-native/template/.agents/skills/upgrading-react-native/references/upgrading-dependencies.md +41 -0
- package/stacks/react-native/template/.agents/skills/upgrading-react-native/references/upgrading-react-native.md +52 -0
- package/stacks/react-native/template/.githooks/pre-commit +49 -0
- package/stacks/react-native/template/.githooks/pre-push +5 -0
- package/stacks/react-native/template/.github/pull_request_template.md +19 -0
- package/stacks/react-native/template/.github/workflows/ci.yml +61 -0
- package/stacks/react-native/template/.github/workflows/ios.yml +43 -0
- package/stacks/react-native/template/.gitleaks.toml +12 -0
- package/stacks/react-native/template/.rulesync/hooks.jsonc +8 -0
- package/stacks/react-native/template/.rulesync/permissions.jsonc +36 -0
- package/stacks/react-native/template/.rulesync/subagents/m-reviewer.md +15 -0
- package/stacks/react-native/template/AGENTS.md +45 -0
- package/stacks/react-native/template/CLAUDE.md +1 -0
- package/stacks/react-native/template/docs/ai/conventions.md +8 -0
- package/stacks/react-native/template/docs/ai/decisions.md +6 -0
- package/stacks/react-native/template/docs/ai/known-issues.md +17 -0
- package/stacks/react-native/template/docs/ai/product.md +7 -0
- package/stacks/react-native/template/docs/ai/react-native.md +27 -0
- package/stacks/react-native/template/docs/ai/structure.md +7 -0
- package/stacks/react-native/template/docs/ai/team-process.md +9 -0
- package/stacks/react-native/template/docs/ai/tech.md +7 -0
- package/stacks/react-native/template/rulesync.jsonc +9 -0
- package/stacks/react-native/template/scripts/ai/guard.js +35 -0
- package/stacks/react-native/template/scripts/ai/handoff-check.js +28 -0
- package/stacks/react-native/template/scripts/ai/install-deps.sh +14 -0
- package/stacks/react-native/template/scripts/ai/ios-build.sh +11 -0
- package/stacks/react-native/template/scripts/ai/pm-run.sh +16 -0
- package/stacks/react-native/template/specs/_templates/design.md +15 -0
- package/stacks/react-native/template/specs/_templates/progress.md +14 -0
- package/stacks/react-native/template/specs/_templates/requirements.md +30 -0
- package/stacks/react-native/template/specs/_templates/tasks.md +6 -0
package/stacks/react-native/template/.agents/skills/react-navigation/references/material-top-tabs.md
ADDED
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Material Top Tabs
|
|
3
|
+
impact: MEDIUM
|
|
4
|
+
tags: react-navigation, material-top-tabs, swipe, pager-view, lazy, tab-animation
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Skill: Material Top Tabs
|
|
8
|
+
|
|
9
|
+
## Description
|
|
10
|
+
|
|
11
|
+
Use `createMaterialTopTabNavigator` for swipeable top tabs with a Material-style tab bar.
|
|
12
|
+
|
|
13
|
+
## When to Use
|
|
14
|
+
|
|
15
|
+
- Building segmented content that should switch by tap or horizontal swipe
|
|
16
|
+
- Having a scrollable tab bar at the top of the screen
|
|
17
|
+
|
|
18
|
+
## Prerequisites
|
|
19
|
+
|
|
20
|
+
Install `react-native-pager-view` for material top tabs to work on native platforms.
|
|
21
|
+
|
|
22
|
+
## Basic Example
|
|
23
|
+
|
|
24
|
+
**Static API**
|
|
25
|
+
|
|
26
|
+
```tsx
|
|
27
|
+
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
|
|
28
|
+
|
|
29
|
+
const HomeTabs = createMaterialTopTabNavigator({
|
|
30
|
+
screens: {
|
|
31
|
+
Feed: FeedScreen,
|
|
32
|
+
Updates: UpdatesScreen,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**Dynamic API**
|
|
38
|
+
|
|
39
|
+
```tsx
|
|
40
|
+
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
|
|
41
|
+
|
|
42
|
+
const Tab = createMaterialTopTabNavigator();
|
|
43
|
+
|
|
44
|
+
function HomeTabs() {
|
|
45
|
+
return (
|
|
46
|
+
<Tab.Navigator>
|
|
47
|
+
<Tab.Screen name="Feed" component={FeedScreen} />
|
|
48
|
+
<Tab.Screen name="Updates" component={UpdatesScreen} />
|
|
49
|
+
</Tab.Navigator>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Common Features
|
|
55
|
+
|
|
56
|
+
### Displaying Icons
|
|
57
|
+
|
|
58
|
+
Icons are hidden by default. Set `tabBarShowIcon: true`, then provide `tabBarIcon`. Optionally use `tabBarActiveTintColor` and `tabBarInactiveTintColor` to change the color passed to the icon.
|
|
59
|
+
|
|
60
|
+
**Static API**
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
import Ionicons from '@expo/vector-icons/Ionicons';
|
|
64
|
+
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
|
|
65
|
+
|
|
66
|
+
const HomeTabs = createMaterialTopTabNavigator({
|
|
67
|
+
screenOptions: ({ route }) => ({
|
|
68
|
+
tabBarShowIcon: true,
|
|
69
|
+
tabBarIcon: ({ focused, color }) => {
|
|
70
|
+
let iconName;
|
|
71
|
+
|
|
72
|
+
switch (route.name) {
|
|
73
|
+
case 'Feed':
|
|
74
|
+
iconName = focused ? 'newspaper' : 'newspaper-outline';
|
|
75
|
+
break;
|
|
76
|
+
default:
|
|
77
|
+
iconName = focused ? 'notifications' : 'notifications-outline';
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return <Ionicons name={iconName} size={18} color={color} />;
|
|
82
|
+
},
|
|
83
|
+
tabBarActiveTintColor: 'tomato',
|
|
84
|
+
tabBarInactiveTintColor: 'gray',
|
|
85
|
+
}),
|
|
86
|
+
screens: {
|
|
87
|
+
Feed: FeedScreen,
|
|
88
|
+
Updates: UpdatesScreen,
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**Dynamic API**
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
import Ionicons from '@expo/vector-icons/Ionicons';
|
|
97
|
+
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
|
|
98
|
+
|
|
99
|
+
const Tab = createMaterialTopTabNavigator();
|
|
100
|
+
|
|
101
|
+
function HomeTabs() {
|
|
102
|
+
return (
|
|
103
|
+
<Tab.Navigator
|
|
104
|
+
screenOptions={({ route }) => ({
|
|
105
|
+
tabBarShowIcon: true,
|
|
106
|
+
tabBarIcon: ({ focused, color }) => {
|
|
107
|
+
let iconName;
|
|
108
|
+
|
|
109
|
+
switch (route.name) {
|
|
110
|
+
case 'Feed':
|
|
111
|
+
iconName = focused ? 'newspaper' : 'newspaper-outline';
|
|
112
|
+
break;
|
|
113
|
+
default:
|
|
114
|
+
iconName = focused ? 'notifications' : 'notifications-outline';
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return <Ionicons name={iconName} size={18} color={color} />;
|
|
119
|
+
},
|
|
120
|
+
tabBarActiveTintColor: 'tomato',
|
|
121
|
+
tabBarInactiveTintColor: 'gray',
|
|
122
|
+
})}
|
|
123
|
+
>
|
|
124
|
+
<Tab.Screen name="Feed" component={FeedScreen} />
|
|
125
|
+
<Tab.Screen name="Updates" component={UpdatesScreen} />
|
|
126
|
+
</Tab.Navigator>
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
The `tabBarIcon` option can render any React element. Choose between the icon libraries that best fit the app's design and environment:
|
|
132
|
+
|
|
133
|
+
- `@expo/vector-icons` if Expo SDK is configured in the app
|
|
134
|
+
- `react-native-vector-icons` for an app using React Native Community CLI
|
|
135
|
+
- `<Image>` for local images
|
|
136
|
+
|
|
137
|
+
### Scrollable Tab Bar
|
|
138
|
+
|
|
139
|
+
Use `tabBarScrollEnabled: true` if the list of tabs won't fit on the screen to make the tab bar scrollable. Set a fixed width for each tab with `tabBarItemStyle` to make the scrollable tab bar work better.
|
|
140
|
+
|
|
141
|
+
Use `tabBarItemStyle` with `{ width: 'auto' }` if the tab button width should fit the label instead of being equally divided.
|
|
142
|
+
|
|
143
|
+
**Static API**
|
|
144
|
+
|
|
145
|
+
```tsx
|
|
146
|
+
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
|
|
147
|
+
|
|
148
|
+
const HomeTabs = createMaterialTopTabNavigator({
|
|
149
|
+
screenOptions: {
|
|
150
|
+
tabBarScrollEnabled: true,
|
|
151
|
+
},
|
|
152
|
+
screens: {
|
|
153
|
+
Feed: FeedScreen,
|
|
154
|
+
Updates: UpdatesScreen,
|
|
155
|
+
Mentions: MentionsScreen,
|
|
156
|
+
Saved: SavedScreen,
|
|
157
|
+
Archive: ArchiveScreen,
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
**Dynamic API**
|
|
163
|
+
|
|
164
|
+
```tsx
|
|
165
|
+
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
|
|
166
|
+
|
|
167
|
+
const Tab = createMaterialTopTabNavigator();
|
|
168
|
+
|
|
169
|
+
function HomeTabs() {
|
|
170
|
+
return (
|
|
171
|
+
<Tab.Navigator
|
|
172
|
+
screenOptions={{
|
|
173
|
+
tabBarScrollEnabled: true,
|
|
174
|
+
}}
|
|
175
|
+
>
|
|
176
|
+
<Tab.Screen name="Feed" component={FeedScreen} />
|
|
177
|
+
<Tab.Screen name="Updates" component={UpdatesScreen} />
|
|
178
|
+
<Tab.Screen name="Mentions" component={MentionsScreen} />
|
|
179
|
+
<Tab.Screen name="Saved" component={SavedScreen} />
|
|
180
|
+
<Tab.Screen name="Archive" component={ArchiveScreen} />
|
|
181
|
+
</Tab.Navigator>
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Badges
|
|
187
|
+
|
|
188
|
+
Use `tabBarBadge` to render a custom badge element for a tab.
|
|
189
|
+
|
|
190
|
+
**Static API**
|
|
191
|
+
|
|
192
|
+
```tsx
|
|
193
|
+
import { Text, View } from 'react-native';
|
|
194
|
+
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
|
|
195
|
+
|
|
196
|
+
const HomeTabs = createMaterialTopTabNavigator({
|
|
197
|
+
screens: {
|
|
198
|
+
Inbox: {
|
|
199
|
+
screen: InboxScreen,
|
|
200
|
+
options: {
|
|
201
|
+
tabBarBadge: () => (
|
|
202
|
+
<View
|
|
203
|
+
style={{
|
|
204
|
+
minWidth: 18,
|
|
205
|
+
height: 18,
|
|
206
|
+
borderRadius: 9,
|
|
207
|
+
backgroundColor: 'tomato',
|
|
208
|
+
alignItems: 'center',
|
|
209
|
+
justifyContent: 'center',
|
|
210
|
+
}}
|
|
211
|
+
>
|
|
212
|
+
<Text style={{ color: 'white', fontSize: 12 }}>3</Text>
|
|
213
|
+
</View>
|
|
214
|
+
),
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
Settings: SettingsScreen,
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
**Dynamic API**
|
|
223
|
+
|
|
224
|
+
```tsx
|
|
225
|
+
import { Text, View } from 'react-native';
|
|
226
|
+
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
|
|
227
|
+
|
|
228
|
+
const Tab = createMaterialTopTabNavigator();
|
|
229
|
+
|
|
230
|
+
function HomeTabs() {
|
|
231
|
+
return (
|
|
232
|
+
<Tab.Navigator>
|
|
233
|
+
<Tab.Screen
|
|
234
|
+
name="Inbox"
|
|
235
|
+
component={InboxScreen}
|
|
236
|
+
options={{
|
|
237
|
+
tabBarBadge: () => (
|
|
238
|
+
<View
|
|
239
|
+
style={{
|
|
240
|
+
minWidth: 18,
|
|
241
|
+
height: 18,
|
|
242
|
+
borderRadius: 9,
|
|
243
|
+
backgroundColor: 'tomato',
|
|
244
|
+
alignItems: 'center',
|
|
245
|
+
justifyContent: 'center',
|
|
246
|
+
}}
|
|
247
|
+
>
|
|
248
|
+
<Text style={{ color: 'white', fontSize: 12 }}>3</Text>
|
|
249
|
+
</View>
|
|
250
|
+
),
|
|
251
|
+
}}
|
|
252
|
+
/>
|
|
253
|
+
<Tab.Screen name="Settings" component={SettingsScreen} />
|
|
254
|
+
</Tab.Navigator>
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Indicators
|
|
260
|
+
|
|
261
|
+
Use `tabBarIndicatorStyle` to customize the indicator:
|
|
262
|
+
|
|
263
|
+
- Use horizontal margin (`{ marginHorizontal: 16 }`) to make the indicator shorter than the tab button width.
|
|
264
|
+
- Set width (`{ width: 24 }`) for a fixed-width indicator, with `marginHorizontal: 'auto'` to center it under the tab button.
|
|
265
|
+
- Don't set `borderRadius` if `tabBarItemStyle` has `'auto'` width as it's not supported.
|
|
266
|
+
|
|
267
|
+
If the default styling options aren't sufficient, use `tabBarIndicator` to render a custom indicator.
|
|
268
|
+
|
|
269
|
+
**Static API**
|
|
270
|
+
|
|
271
|
+
```tsx
|
|
272
|
+
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
|
|
273
|
+
|
|
274
|
+
const HomeTabs = createMaterialTopTabNavigator({
|
|
275
|
+
screenOptions: {
|
|
276
|
+
tabBarIndicatorStyle: {
|
|
277
|
+
backgroundColor: '#111827',
|
|
278
|
+
height: 3,
|
|
279
|
+
marginHorizontal: 16,
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
screens: {
|
|
283
|
+
Feed: FeedScreen,
|
|
284
|
+
Updates: UpdatesScreen,
|
|
285
|
+
},
|
|
286
|
+
});
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
**Dynamic API**
|
|
290
|
+
|
|
291
|
+
```tsx
|
|
292
|
+
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
|
|
293
|
+
|
|
294
|
+
const Tab = createMaterialTopTabNavigator();
|
|
295
|
+
|
|
296
|
+
function HomeTabs() {
|
|
297
|
+
return (
|
|
298
|
+
<Tab.Navigator
|
|
299
|
+
screenOptions={{
|
|
300
|
+
tabBarIndicatorStyle: {
|
|
301
|
+
backgroundColor: '#111827',
|
|
302
|
+
height: 3,
|
|
303
|
+
marginHorizontal: 16,
|
|
304
|
+
},
|
|
305
|
+
}}
|
|
306
|
+
>
|
|
307
|
+
<Tab.Screen name="Feed" component={FeedScreen} />
|
|
308
|
+
<Tab.Screen name="Updates" component={UpdatesScreen} />
|
|
309
|
+
</Tab.Navigator>
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### Custom Tab Bar
|
|
315
|
+
|
|
316
|
+
Use the `tabBar` option if a custom design is needed. Use the `navigation` prop passed to the tab bar instead of `useNavigation`.
|
|
317
|
+
|
|
318
|
+
```tsx
|
|
319
|
+
import { Text, View } from 'react-native';
|
|
320
|
+
import { useLinkBuilder } from '@react-navigation/native';
|
|
321
|
+
import { PlatformPressable } from '@react-navigation/elements';
|
|
322
|
+
|
|
323
|
+
function MyTabBar({ state, descriptors, navigation }) {
|
|
324
|
+
const { buildHref } = useLinkBuilder();
|
|
325
|
+
|
|
326
|
+
return (
|
|
327
|
+
<View style={{ flexDirection: 'row' }}>
|
|
328
|
+
{state.routes.map((route, index) => {
|
|
329
|
+
const { options } = descriptors[route.key];
|
|
330
|
+
const label =
|
|
331
|
+
options.tabBarLabel !== undefined
|
|
332
|
+
? options.tabBarLabel
|
|
333
|
+
: options.title !== undefined
|
|
334
|
+
? options.title
|
|
335
|
+
: route.name;
|
|
336
|
+
|
|
337
|
+
const isFocused = state.index === index;
|
|
338
|
+
|
|
339
|
+
return (
|
|
340
|
+
<PlatformPressable
|
|
341
|
+
key={route.key}
|
|
342
|
+
href={buildHref(route.name, route.params)}
|
|
343
|
+
onPress={() => {
|
|
344
|
+
const event = navigation.emit({
|
|
345
|
+
type: 'tabPress',
|
|
346
|
+
target: route.key,
|
|
347
|
+
canPreventDefault: true,
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
if (!isFocused && !event.defaultPrevented) {
|
|
351
|
+
navigation.navigate(route.name, route.params);
|
|
352
|
+
}
|
|
353
|
+
}}
|
|
354
|
+
onLongPress={() =>
|
|
355
|
+
navigation.emit({
|
|
356
|
+
type: 'tabLongPress',
|
|
357
|
+
target: route.key,
|
|
358
|
+
})
|
|
359
|
+
}
|
|
360
|
+
style={{ flex: 1, alignItems: 'center', paddingVertical: 12 }}
|
|
361
|
+
>
|
|
362
|
+
<Text style={{ opacity: isFocused ? 1 : 0.6 }}>{label}</Text>
|
|
363
|
+
</PlatformPressable>
|
|
364
|
+
);
|
|
365
|
+
})}
|
|
366
|
+
</View>
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
**Static API**
|
|
372
|
+
|
|
373
|
+
```tsx
|
|
374
|
+
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
|
|
375
|
+
|
|
376
|
+
const HomeTabs = createMaterialTopTabNavigator({
|
|
377
|
+
tabBar: (props) => <MyTabBar {...props} />,
|
|
378
|
+
screens: {
|
|
379
|
+
Feed: FeedScreen,
|
|
380
|
+
Updates: UpdatesScreen,
|
|
381
|
+
},
|
|
382
|
+
});
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
**Dynamic API**
|
|
386
|
+
|
|
387
|
+
```tsx
|
|
388
|
+
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
|
|
389
|
+
|
|
390
|
+
const Tab = createMaterialTopTabNavigator();
|
|
391
|
+
|
|
392
|
+
function HomeTabs() {
|
|
393
|
+
return (
|
|
394
|
+
<Tab.Navigator tabBar={(props) => <MyTabBar {...props} />}>
|
|
395
|
+
<Tab.Screen name="Feed" component={FeedScreen} />
|
|
396
|
+
<Tab.Screen name="Updates" component={UpdatesScreen} />
|
|
397
|
+
</Tab.Navigator>
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
If the custom tab bar also needs proper web links, use `useLinkBuilder` when building each tab button.
|
|
403
|
+
|
|
404
|
+
### Lazy Rendering
|
|
405
|
+
|
|
406
|
+
All screens are mounted immediately by default for smoother swiping. Enable `lazy` only when rendering tabs upfront is too expensive.
|
|
407
|
+
|
|
408
|
+
**Static API**
|
|
409
|
+
|
|
410
|
+
```tsx
|
|
411
|
+
import { ActivityIndicator, View } from 'react-native';
|
|
412
|
+
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
|
|
413
|
+
|
|
414
|
+
const HomeTabs = createMaterialTopTabNavigator({
|
|
415
|
+
screenOptions: {
|
|
416
|
+
lazy: true,
|
|
417
|
+
},
|
|
418
|
+
screens: {
|
|
419
|
+
Feed: FeedScreen,
|
|
420
|
+
Updates: UpdatesScreen,
|
|
421
|
+
Mentions: MentionsScreen,
|
|
422
|
+
},
|
|
423
|
+
});
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
**Dynamic API**
|
|
427
|
+
|
|
428
|
+
```tsx
|
|
429
|
+
import { ActivityIndicator, View } from 'react-native';
|
|
430
|
+
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
|
|
431
|
+
|
|
432
|
+
const Tab = createMaterialTopTabNavigator();
|
|
433
|
+
|
|
434
|
+
function HomeTabs() {
|
|
435
|
+
return (
|
|
436
|
+
<Tab.Navigator
|
|
437
|
+
screenOptions={{
|
|
438
|
+
lazy: true,
|
|
439
|
+
}}
|
|
440
|
+
>
|
|
441
|
+
<Tab.Screen name="Feed" component={FeedScreen} />
|
|
442
|
+
<Tab.Screen name="Updates" component={UpdatesScreen} />
|
|
443
|
+
<Tab.Screen name="Mentions" component={MentionsScreen} />
|
|
444
|
+
</Tab.Navigator>
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
Customize lazy loading behavior with `lazyPlaceholder` to show a custom placeholder before the screen is loaded and `lazyPreloadDistance` to control how many screens away from the focused screen should be preloaded.
|
|
450
|
+
|
|
451
|
+
## Canonical Docs
|
|
452
|
+
|
|
453
|
+
- [Material Top Tabs Navigator](https://reactnavigation.org/docs/material-top-tab-navigator)
|