Skip to content

Commit 3d11d94

Browse files
authored
feat: add snacks to api reference docs (#616)
* feat: add snacks to api reference docs * fix: add requested changes
1 parent 9653265 commit 3d11d94

File tree

75 files changed

+3042
-89
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+3042
-89
lines changed

docs/bottom-tab-navigator.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,24 @@ yarn add @react-navigation/bottom-tabs@next
1616

1717
To use this tab navigator, import it from `@react-navigation/bottom-tabs`:
1818

19+
<samp id="tab-based-navigation-minimal" />
20+
1921
```js
2022
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
2123

2224
const Tab = createBottomTabNavigator();
2325

24-
function App() {
26+
function MyTabs() {
2527
return (
2628
<Tab.Navigator>
27-
<Tab.Screen name="Feed" component={Feed} />
28-
<Tab.Screen name="Article" component={Article} />
29+
<Tab.Screen name="Home" component={HomeScreen} />
30+
<Tab.Screen name="Settings" component={SettingsScreen} />
2931
</Tab.Navigator>
3032
);
3133
}
3234
```
3335

34-
> For a complete usage guide please visit [Tab Navigation](https://reactnavigation.org/docs/tab-based-navigation.html)
36+
> For a complete usage guide please visit [Tab Navigation](tab-based-navigation.md)
3537
3638
### Props
3739

@@ -68,6 +70,8 @@ Function that returns a React element to display as the tab bar.
6870

6971
Example:
7072

73+
<samp id="custom-tab-bar" />
74+
7175
```js
7276
import { View, Text, TouchableOpacity } from 'react-native';
7377

@@ -196,7 +200,9 @@ This event is fired when the user presses the tab button for the current screen
196200
- If the screen for the tab renders a scroll view, scroll to top is performed by `useScrollToTop`
197201
- If the screen for the tab renders a stack navigator, a `popToTop` action is performed on the stack
198202

199-
To prevent the default behavior, you can call `eventPreventDefault`:
203+
To prevent the default behavior, you can call `event.preventDefault`:
204+
205+
<samp id="bottom-tab-prevent-default">
200206

201207
```js
202208
navigation.addListener('tabPress', e => {
@@ -225,19 +231,23 @@ Navigates to an existing screen in the tab navigator. The method accepts followi
225231
- `name` - _string_ - Name of the route to jump to.
226232
- `params` - _object_ - Screen params to merge into the destination route (found in the pushed screen through `route.params`).
227233

234+
<samp id="tab-jump-to">
235+
228236
```js
229-
navigation.jumpTo('Profile', { name: 'Michaś' });
237+
navigation.jumpTo('Profile', { owner: 'Michaś' });
230238
```
231239

232240
## Example
233241

242+
<samp id="bottom-tab-example">
243+
234244
```js
235245
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
236246
import { MaterialCommunityIcons } from 'react-native-vector-icons';
237247

238248
const Tab = createBottomTabNavigator();
239249

240-
function App() {
250+
function MyTabs() {
241251
return (
242252
<Tab.Navigator
243253
initialRouteName="Feed"

docs/custom-navigators.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ We include some commonly needed navigators such as:
1414

1515
- [`createStackNavigator`](stack-navigator.html) - Renders one screen at a time and provides transitions between screens. When a new screen is opened it is placed on top of the stack.
1616
- [`createNativeStackNavigator`](native-stack-navigator.html) - Similar to `createStackNavigator`, but implemented using native navigation primitives such as `UINavigationController` on iOS and `Fragment` on Android.
17-
- [`createDrawerNavigator`](drawer-navigator.html) - Provides a drawer that slides in from the left of the screen.
17+
- [`createDrawerNavigator`](drawer-navigator.html) - Provides a drawer that slides in from the left of the screen by default.
1818
- [`createBottomTabNavigator`](bottom-tab-navigator.html) - Renders a tab bar that lets the user switch between several screens.
1919
- [`createMaterialTopTabNavigator`](material-top-tab-navigator.html) - Renders tab view which lets the user switch between several screens using swipe gesture or the tab bar.
2020
- [`createMaterialBottomTabNavigator`](material-bottom-tab-navigator.html) - Renders tab view which lets the user switch between several screens using swipe gesture or the tab bar.
@@ -288,6 +288,5 @@ const { state, descriptors, navigation } = useNavigationBuilder(MyRouter, {
288288
screenOptions,
289289
});
290290

291-
292291
// ...
293292
```

docs/drawer-actions.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ The following actions are supported:
1212

1313
The `openDrawer` action can be used to open the drawer pane.
1414

15+
<samp id="drawer-actions">
16+
1517
```js
1618
import { DrawerActions } from '@react-navigation/routers';
1719

@@ -20,7 +22,9 @@ navigation.dispatch(DrawerActions.openDrawer());
2022

2123
### closeDrawer
2224

23-
The `openDrawer` action can be used to close the drawer pane.
25+
The `closeDrawer` action can be used to close the drawer pane.
26+
27+
<samp id="drawer-actions">
2428

2529
```js
2630
import { DrawerActions } from '@react-navigation/routers';
@@ -32,6 +36,8 @@ navigation.dispatch(DrawerActions.closeDrawer());
3236

3337
The `toggleDrawer` action can be used to open the drawer pane if closed, or close if open.
3438

39+
<samp id="drawer-actions">
40+
3541
```js
3642
import { DrawerActions } from '@react-navigation/routers';
3743

@@ -45,6 +51,8 @@ The `jumpTo` action can be used to jump to an existing route in the drawer navig
4551
- `name` - _string_ - Name of the route to jump to.
4652
- `params` - _object_ - Screen params to merge into the destination route (found in the pushed screen through `route.params`).
4753

54+
<samp id="drawer-actions">
55+
4856
```js
4957
import { DrawerActions } from '@react-navigation/routers';
5058

docs/drawer-based-navigation.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,25 @@ export default function App() {
6060

6161
To open and close drawer, use the following helpers:
6262

63+
<samp id="drawer-open-close-toggle">
64+
6365
```js
6466
navigation.openDrawer();
6567
navigation.closeDrawer();
6668
```
6769

6870
If you would like to toggle the drawer you call the following:
6971

72+
<samp id="drawer-open-close-toggle">
73+
7074
```js
7175
navigation.toggleDrawer();
7276
```
7377

7478
Each of these functions, behind the scenes, are simply dispatching actions:
7579

80+
<samp id="drawer-dispatch">
81+
7682
```js
7783
navigation.dispatch(DrawerActions.openDrawer());
7884
navigation.dispatch(DrawerActions.closeDrawer());

docs/drawer-navigator.md

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ yarn add @react-navigation/drawer@next
1616

1717
To use this drawer navigator, import it from `@react-navigation/drawer`:
1818

19+
<samp id="simple-drawer">
20+
1921
```js
2022
import { createDrawerNavigator } from '@react-navigation/drawer';
2123

2224
const Drawer = createDrawerNavigator();
2325

24-
function App() {
26+
function MyDrawer() {
2527
return (
2628
<Drawer.Navigator>
2729
<Drawer.Screen name="Feed" component={Feed} />
@@ -31,7 +33,7 @@ function App() {
3133
}
3234
```
3335

34-
> For a complete usage guide please visit [Drawer Navigation](https://reactnavigation.org/docs/drawer-based-navigation.html).
36+
> For a complete usage guide please visit [Drawer Navigation](drawer-based-navigation.md).
3537
3638
### Props
3739

@@ -110,6 +112,8 @@ Style object for the component wrapping the screen content.
110112

111113
Style object for the drawer component. You can pass a custom background color for a drawer or a custom width here.
112114

115+
<samp id="drawer-with-style">
116+
113117
```js
114118
<Drawer.Navigator
115119
drawerStyle={{
@@ -139,7 +143,10 @@ The default component for the drawer is scrollable and only contains links for t
139143
By default the drawer is scrollable and supports devices with notches. If you customize the content, you can use `DrawerContentScrollView` to handle this automatically:
140144

141145
```js
142-
import { DrawerContentScrollView, DrawerItemList } from '@react-navigation/drawer';
146+
import {
147+
DrawerContentScrollView,
148+
DrawerItemList,
149+
} from '@react-navigation/drawer';
143150

144151
function CustomDrawerContent(props) {
145152
return (
@@ -152,6 +159,8 @@ function CustomDrawerContent(props) {
152159

153160
To add additional items in the drawer, you can use the `DrawerItem` component:
154161

162+
<samp id="custom-drawer-content">
163+
155164
```js
156165
function CustomDrawerContent(props) {
157166
return (
@@ -181,6 +190,8 @@ The `DrawerItem` component accepts the following props:
181190

182191
The `progress` node can be used to do interesting animations in your `drawerContent`, such as parallax motion of the drawer contents:
183192

193+
<samp id="animated-drawer-content">
194+
184195
```js
185196
function CustomDrawerContent({ progress, ...rest }) {
186197
const translateX = Animated.interpolate(progress, {
@@ -242,11 +253,13 @@ Style object for the wrapper view.
242253

243254
Example:
244255

256+
<samp id="drawer-content-options">
257+
245258
```js
246259
<Drawer.Navigator
247260
drawerContentOptions={{
248261
activeTintColor: '#e91e63',
249-
itemStyle: { marginVertical: 0 },
262+
itemStyle: { marginVertical: 30 },
250263
}}
251264
>
252265
{/* screens */}
@@ -293,6 +306,8 @@ The drawer navigator adds the following methods to the navigation prop:
293306

294307
Opens the drawer pane.
295308

309+
<samp id="drawer-open-close-toggle">
310+
296311
```js
297312
navigation.openDrawer();
298313
```
@@ -301,6 +316,8 @@ navigation.openDrawer();
301316

302317
Closes the drawer pane.
303318

319+
<samp id="drawer-open-close-toggle">
320+
304321
```js
305322
navigation.closeDrawer();
306323
```
@@ -309,6 +326,8 @@ navigation.closeDrawer();
309326

310327
Opens the drawer pane if closed, closes the drawer pane if opened.
311328

329+
<samp id="drawer-open-close-toggle">
330+
312331
```js
313332
navigation.toggleDrawer();
314333
```
@@ -320,18 +339,22 @@ Navigates to an existing screen in the drawer navigator. The method accepts foll
320339
- `name` - _string_ - Name of the route to jump to.
321340
- `params` - _object_ - Screen params to merge into the destination route (found in the pushed screen through `route.params`).
322341

342+
<samp id="drawer-example">
343+
323344
```js
324-
navigation.jumpTo('Profile', { name: 'Satya' });
345+
navigation.jumpTo('Profile', { owner: 'Satya' });
325346
```
326347

327348
## Example
328349

350+
<samp id="drawer-example">
351+
329352
```js
330353
import { createDrawerNavigator } from '@react-navigation/drawer';
331354

332355
const Drawer = createDrawerNavigator();
333356

334-
function App() {
357+
function MyDrawer() {
335358
return (
336359
<Drawer.Navigator initialRouteName="Feed">
337360
<Drawer.Screen

docs/material-bottom-tab-navigator.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,24 @@ To use this tab navigator, import it from `@react-navigation/material-bottom-tab
2424

2525
To use this tab navigator, import it from `@react-navigation/material-bottom-tabs`:
2626

27+
<samp id="material-tab-based-navigation-minimal" />
28+
2729
```js
2830
import { createMaterialBottomTabNavigator } from '@react-navigation/material-bottom-tabs';
2931

3032
const Tab = createMaterialBottomTabNavigator();
3133

32-
function App() {
34+
function MyTabs() {
3335
return (
3436
<Tab.Navigator>
35-
<Tab.Screen name="Feed" component={Feed} />
36-
<Tab.Screen name="Article" component={Article} />
37+
<Tab.Screen name="Home" component={HomeScreen} />
38+
<Tab.Screen name="Settings" component={SettingsScreen} />
3739
</Tab.Navigator>
3840
);
3941
}
4042
```
4143

42-
> For a complete usage guide please visit [Tab Navigation](https://reactnavigation.org/docs/tab-based-navigation.html)
44+
> For a complete usage guide please visit [Tab Navigation](tab-based-navigation.md)
4345
4446
## RouteConfigs
4547

@@ -88,9 +90,11 @@ Style for the bottom navigation bar. You can set a bottom padding here if you ha
8890

8991
Example:
9092

93+
<samp id="material-bottom-tab-styled">
94+
9195
```js
9296
<Tab.Navigator
93-
initialRouteName="Album"
97+
initialRouteName="Home"
9498
activeColor="#f0edf6"
9599
inactiveColor="#3e2465"
96100
barStyle={{ backgroundColor: '#694fad' }}
@@ -144,13 +148,14 @@ This event is fired when the user presses the tab button for the current screen
144148
- If the screen for the tab renders a scroll view, scroll to top is performed by `useScrollToTop`
145149
- If the screen for the tab renders a stack navigator, a `popToTop` action is performed on the stack
146150

147-
To prevent the scroll to top/`popToTop` behavior, you can call `eventPreventDefault`:
151+
To prevent the default behavior, you can call `event.preventDefault`:
152+
153+
<samp id="material-bottom-tab-prevent-default">
148154

149155
```js
150156
navigation.addListener('tabPress', e => {
151157
// Prevent default behavior
152158
e.preventDefault();
153-
154159
// Do something manually
155160
// ...
156161
});
@@ -167,19 +172,23 @@ Navigates to an existing screen in the tab navigator. The method accepts followi
167172
- `name` - _string_ - Name of the route to jump to.
168173
- `params` - _object_ - Screen params to merge into the destination route (found in the pushed screen through `route.params`).
169174

175+
<samp id="material-tab-jump-to">
176+
170177
```js
171178
navigation.jumpTo('Profile', { name: 'Michaś' });
172179
```
173180

174181
## Example
175182

183+
<samp id="material-bottom-tab-example">
184+
176185
```js
177186
import { createMaterialBottomTabNavigator } from '@react-navigation/material-bottom-tabs';
178187
import { MaterialCommunityIcons } from 'react-native-vector-icons';
179188

180189
const Tab = createMaterialBottomTabNavigator();
181190

182-
function App() {
191+
function MyTabs() {
183192
return (
184193
<Tab.Navigator
185194
initialRouteName="Feed"

0 commit comments

Comments
 (0)