Skip to content

Commit 9ccb085

Browse files
jarvisluongbrentvatne
authored andcommitted
Add docs for tabBarOnLongPress and animated switch navigator (react-navigation#404)
* chore: add doc for tabBarOnLongPress * update docs on v3 branch * docs about animated switch navigator * Update wording for docs/animated-switch-navigator.md Co-Authored-By: jarvisluong <jarvisluong@users.noreply.github.com> * document the transition option for animated switch navigator
1 parent 14bd59b commit 9ccb085

15 files changed

+259
-17
lines changed

docs/animated-switch-navigator.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
id: animated-switch-navigator
3+
title: createAnimatedSwitchNavigator
4+
sidebar_label: createAnimatedSwitchNavigator
5+
---
6+
7+
A switch navigator with the ability to animate transitions between screens.
8+
9+
To use this navigator, you need to install `react-native-reanimated >= 1.0.0`. If you have a managed Expo project, you need to use >= SDK 33 to have the correct version of Reanimated.
10+
11+
## API Definition
12+
13+
```js
14+
import createAnimatedSwitchNavigator from 'react-navigation-animated-switch';
15+
16+
createAnimatedSwitchNavigator(RouteConfigs, SwitchNavigatorConfig);
17+
```
18+
19+
The route configs and navigator configs are identical to [createSwitchNavigator](switch-navigator.html)

docs/bottom-tab-navigator.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,12 @@ Callback to handle press events; the argument is an object containing:
111111
* `navigation`: navigation prop for the screen
112112
* `defaultHandler`: the default handler for tab press
113113

114-
Useful for adding a custom logic before the transition to the next scene (the tapped one) starts.
114+
Useful for adding a custom logic before the transition to the next scene (the
115+
tapped one) starts.
116+
117+
#### `tabBarOnLongPress`
118+
119+
Callback to handle long press events; the argument is an object containing:
120+
121+
- `navigation`: navigation prop for the screen
122+
- `defaultHandler`: the default handler for tab press

docs/material-bottom-tab-navigator.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,15 @@ npm install react-navigation-material-bottom-tabs react-native-paper
1616

1717
This API also requires that you install `react-native-vector-icons`! If you are using Expo, it will just work out of the box. Otherwise, [follow these installation instructions](https://github.com/oblador/react-native-vector-icons#installation).
1818

19+
To use this tab navigator, import it from `react-navigation-material-bottom-tabs`
20+
1921
```js
20-
createMaterialBottomTabNavigator(RouteConfigs, MaterialBottomTabNavigatorConfig);
22+
import { createMaterialBottomTabNavigator } from "react-navigation-material-bottom-tabs";
23+
24+
createMaterialBottomTabNavigator(
25+
RouteConfigs,
26+
MaterialBottomTabNavigatorConfig
27+
);
2128
```
2229

2330
This library uses the [`BottomNavigation` component from `react-native-paper`](https://callstack.github.io/react-native-paper/bottom-navigation.html). It doesn't include the whole `react-native-paper` library in your bundle, so you don't need to worry about it.

docs/material-top-tab-navigator.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,12 @@ Callback to handle press events; the argument is an object containing:
9494
* `navigation`: navigation prop for the screen
9595
* `defaultHandler`: the default handler for tab press
9696

97-
Useful for adding a custom logic before the transition to the next scene (the tapped one) starts.
97+
Useful for adding a custom logic before the transition to the next scene (the
98+
tapped one) starts.
99+
100+
#### `tabBarOnLongPress`
101+
102+
Callback to handle long press events; the argument is an object containing:
103+
104+
- `navigation`: navigation prop for the screen
105+
- `defaultHandler`: the default handler for tab press

docs/tab-navigator.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: createTabNavigator
44
sidebar_label: createTabNavigator
55
---
66

7-
> Note: `createTabNavigator` is deprecated. Please use `createBottomTabNavigator` and/or `createMaterialTopTabNavigator` instead.
7+
> Note: `createTabNavigator` is deprecated and removed in `react-navigation@3.x`. Please use `createBottomTabNavigator` and/or `createMaterialTopTabNavigator` instead.
88
99
```js
1010
createTabNavigator(RouteConfigs, TabNavigatorConfig);

website/i18n/en.json

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
"title": "Alternative libraries",
1010
"sidebar_label": "Alternative libraries"
1111
},
12+
"animated-switch-navigator": {
13+
"title": "createAnimatedSwitchNavigator",
14+
"sidebar_label": "createAnimatedSwitchNavigator"
15+
},
1216
"anti-pitch": {
1317
"title": "anti-pitch"
1418
},
@@ -24,9 +28,6 @@
2428
"title": "Authentication flows",
2529
"sidebar_label": "Authentication flows"
2630
},
27-
"bottom-sheet": {
28-
"title": "bottom-sheet"
29-
},
3031
"bottom-tab-navigator": {
3132
"title": "createBottomTabNavigator",
3233
"sidebar_label": "createBottomTabNavigator"
@@ -89,9 +90,6 @@
8990
"title": "createDrawerNavigator",
9091
"sidebar_label": "createDrawerNavigator"
9192
},
92-
"dynamic-routes": {
93-
"title": "dynamic-routes"
94-
},
9593
"function-after-focusing-screen": {
9694
"title": "Call a function when focused screen changes",
9795
"sidebar_label": "Call a function when focused screen changes"
@@ -134,9 +132,6 @@
134132
"title": "Know when a screen is focused and blurred",
135133
"sidebar_label": "Know when a screen is focused and blurred"
136134
},
137-
"localization": {
138-
"title": "localization"
139-
},
140135
"material-bottom-tab-navigator": {
141136
"title": "createMaterialBottomTabNavigator",
142137
"sidebar_label": "createMaterialBottomTabNavigator"
@@ -666,6 +661,10 @@
666661
"title": "withNavigation",
667662
"sidebar_label": "withNavigation"
668663
},
664+
"version-3.x-animated-switch-navigator": {
665+
"title": "createAnimatedSwitchNavigator",
666+
"sidebar_label": "createAnimatedSwitchNavigator"
667+
},
669668
"version-3.x-auth-flow": {
670669
"title": "Authentication flows",
671670
"sidebar_label": "Authentication flows"
@@ -734,6 +733,10 @@
734733
"title": "Limitations",
735734
"sidebar_label": "Limitations"
736735
},
736+
"version-3.x-material-bottom-tab-navigator": {
737+
"title": "createMaterialBottomTabNavigator",
738+
"sidebar_label": "createMaterialBottomTabNavigator"
739+
},
737740
"version-3.x-material-top-tab-navigator": {
738741
"title": "createMaterialTopTabNavigator",
739742
"sidebar_label": "createMaterialTopTabNavigator"
@@ -762,6 +765,10 @@
762765
"title": "Navigation options resolution",
763766
"sidebar_label": "Navigation options resolution"
764767
},
768+
"version-3.x-navigation-views": {
769+
"title": "Navigation views",
770+
"sidebar_label": "Navigation views"
771+
},
765772
"version-3.x-params": {
766773
"title": "Passing parameters to routes",
767774
"sidebar_label": "Passing parameters to routes"
@@ -806,10 +813,18 @@
806813
"title": "Tab navigation",
807814
"sidebar_label": "Tab navigation"
808815
},
816+
"version-3.x-tab-navigator": {
817+
"title": "createTabNavigator",
818+
"sidebar_label": "createTabNavigator"
819+
},
809820
"version-3.x-themes": {
810821
"title": "Themes",
811822
"sidebar_label": "Themes"
812823
},
824+
"version-3.x-transitioner": {
825+
"title": "Transitioner",
826+
"sidebar_label": "Transitioner"
827+
},
813828
"version-3.x-web-support": {
814829
"title": "React Navigation on the Web",
815830
"sidebar_label": "Web support"

website/sidebars.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"drawer-actions",
6060
"stack-navigator",
6161
"switch-navigator",
62+
"animated-switch-navigator",
6263
"drawer-navigator",
6364
"tab-navigator",
6465
"bottom-tab-navigator",
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
id: version-3.x-animated-switch-navigator
3+
title: createAnimatedSwitchNavigator
4+
sidebar_label: createAnimatedSwitchNavigator
5+
original_id: animated-switch-navigator
6+
---
7+
8+
An SwitchNavigator with animation support.
9+
10+
To use this navigator, you need to install `react-native-reanimated >= 1.0.0`. If you have a managed Expo project, you need to use >= SDK 33 to have the correct version of Reanimated.
11+
12+
## API Definition
13+
14+
```js
15+
import createAnimatedSwitchNavigator from 'react-navigation-animated-switch';
16+
17+
createAnimatedSwitchNavigator(RouteConfigs, SwitchNavigatorConfig);
18+
```
19+
20+
## RouteConfigs
21+
22+
The route configs are identical to [createSwitchNavigator](switch-navigator.html)
23+
24+
## SwitchNavigatorConfig
25+
26+
The switch navigator configs are identical to [createSwitchNavigator](switch-navigator.html).
27+
28+
By default, the transition between screens is a cross-fade. You can customize the transition with an additional option `transition`:
29+
30+
```jsx
31+
import createAnimatedSwitchNavigator from 'react-navigation-animated-switch';
32+
import { Transition } from 'react-native-reanimated';
33+
34+
const MySwitch = createAnimatedSwitchNavigator(
35+
{
36+
Home: HomeScreen,
37+
Other: OtherScreen,
38+
},
39+
{
40+
// The previous screen will slide to the bottom while the next screen will fade in
41+
transition: (
42+
<Transition.Together>
43+
<Transition.Out
44+
type="slide-bottom"
45+
durationMs={400}
46+
interpolation="easeIn"
47+
/>
48+
<Transition.In type="fade" durationMs={500} />
49+
</Transition.Together>
50+
),
51+
}
52+
);
53+
```
54+
55+
Since the transition are possible thanks to the `Transition` API from `react-native-reanimated`, you can learn more about it [here](https://github.com/kmagiera/react-native-reanimated).

website/versioned_docs/version-3.x/auth-flow.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,5 @@ class HomeScreen extends React.Component {
134134
```
135135
<a href="https://snack.expo.io/@react-navigation/auth-flow-v3" target="blank" class="run-code-button">&rarr; Run this code</a>
136136

137-
That's about all there is to it. At the moment, `createSwitchNavigator` doesn't support animating between screens. Let us know if this is important to you [on Canny](https://react-navigation.canny.io/feature-requests).
137+
That's about all there is to it. To enable animation, you need to use
138+
[createAnimatedSwitchNavigator](animated-switch-navigator.html) instead.

website/versioned_docs/version-3.x/bottom-tab-navigator.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,12 @@ Callback to handle press events; the argument is an object containing:
112112
* `navigation`: navigation prop for the screen
113113
* `defaultHandler`: the default handler for tab press
114114

115-
Useful for adding a custom logic before the transition to the next scene (the tapped one) starts.
115+
Useful for adding a custom logic before the transition to the next scene (the
116+
tapped one) starts.
117+
118+
#### `tabBarOnLongPress`
119+
120+
Callback to handle long press events; the argument is an object containing:
121+
122+
- `navigation`: navigation prop for the screen
123+
- `defaultHandler`: the default handler for tab press
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
id: version-3.x-material-bottom-tab-navigator
3+
title: createMaterialBottomTabNavigator
4+
sidebar_label: createMaterialBottomTabNavigator
5+
original_id: material-bottom-tab-navigator
6+
---
7+
8+
A material-design themed tab bar on the bottom of the screen that lets you switch between different routes. Routes are lazily initialized -- their screen components are not mounted until they are first focused.
9+
10+
<img src="/docs/assets/navigators/bottom-navigation.gif" style="width: 420px; max-width: 100%">
11+
12+
To use this navigator, you need to install `react-navigation-material-bottom-tabs`
13+
14+
```
15+
npm install react-navigation-material-bottom-tabs react-native-paper
16+
```
17+
18+
This API also requires that you install `react-native-vector-icons`! If you are using Expo, it will just work out of the box. Otherwise, [follow these installation instructions](https://github.com/oblador/react-native-vector-icons#installation).
19+
20+
To use this tab navigator, import it from `react-navigation-material-bottom-tabs`
21+
22+
```js
23+
import { createMaterialBottomTabNavigator } from "react-navigation-material-bottom-tabs";
24+
25+
createMaterialBottomTabNavigator(
26+
RouteConfigs,
27+
MaterialBottomTabNavigatorConfig
28+
);
29+
```
30+
31+
This library uses the [`BottomNavigation` component from `react-native-paper`](https://callstack.github.io/react-native-paper/bottom-navigation.html). It doesn't include the whole `react-native-paper` library in your bundle, so you don't need to worry about it.
32+
33+
## RouteConfigs
34+
35+
The route configs object is a mapping from route name to a route config.
36+
37+
## MaterialBottomTabNavigatorConfig
38+
39+
* `shifting` - Whether the shifting style is used, the active tab appears wider and the inactive tabs won't have a label. By default, this is `true` when you have more than 3 tabs.
40+
* `labeled` - Whether to show labels in tabs. When `false`, only icons will be displayed.
41+
* `activeColor` - Custom color for icon and label in the active tab.
42+
* `inactiveColor` - Custom color for icon and label in the inactive tab.
43+
* `barStyle` - Style for the bottom navigation bar. You can set a bottom padding here if you have a translucent navigation bar on Android: `barStyle={{ paddingBottom: 48 }}`.
44+
* `initialRouteName` - The routeName for the initial tab route when first loading.
45+
* `order` - Array of routeNames which defines the order of the tabs.
46+
* `paths` - Provide a mapping of routeName to path config, which overrides the paths set in the routeConfigs.
47+
* `backBehavior` - `initialRoute` to return to initial tab, `order` to return to previous tab, `history` to return to last visited tab, or `none`.
48+
49+
Example:
50+
51+
```js
52+
export default createMaterialBottomTabNavigator({
53+
Album: { screen: Album },
54+
Library: { screen: Library },
55+
History: { screen: History },
56+
Cart: { screen: Cart },
57+
}, {
58+
initialRouteName: 'Album',
59+
activeColor: '#f0edf6',
60+
inactiveColor: '#3e2465',
61+
barStyle: { backgroundColor: '#694fad' },
62+
});
63+
```
64+
65+
## `navigationOptions` for screens inside of the navigator
66+
67+
#### `title`
68+
69+
Generic title that can be used as a fallback for `headerTitle` and `tabBarLabel`.
70+
71+
#### `tabBarIcon`
72+
73+
React Element or a function that given `{ focused: boolean, horizontal: boolean, tintColor: string }` returns a React.Node, to display in the tab bar. `horizontal` is `true` when the device is in landscape and `false` when portrait. The icon is re-rendered whenever the device orientation changes.
74+
75+
#### `tabBarColor`
76+
77+
Color for the tab bar when the tab corresponding to the screen is active. Used for the ripple effect. This is only supported when `shifting` is `true`.
78+
79+
#### `tabBarLabel`
80+
81+
Title string of a tab displayed in the tab bar. When undefined, scene `title` is used. To hide, see `labeled` option in the previous section.
82+
83+
#### `tabBarAccessibilityLabel`
84+
85+
Accessibility label for the tab button. This is read by the screen reader when the user taps the tab. It's recommended to set this if you don't have a label for the tab.
86+
87+
#### `tabBarTestID`
88+
89+
ID to locate this tab button in tests.
90+
91+
#### `tabBarOnPress`
92+
93+
Callback to handle press events; the argument is an object containing:
94+
95+
* `navigation`: navigation prop for the screen
96+
* `defaultHandler`: the default handler for tab press
97+
98+
Useful for adding a custom logic before the transition to the next scene (the tapped one) starts.
99+
100+
## Using with `react-native-paper` (optional)
101+
102+
You can use the theming support in `react-native-paper` to customize the material bottom navigation by wrapping your app in [`Provider` from `react-native-paper`](https://callstack.github.io/react-native-paper/getting-started.html). A common use case for this can be to customize the background color for the screens when your app has a dark theme. Follow the [instructions on `react-native-paper`'s documentation](https://callstack.github.io/react-native-paper/theming.html) to learn how to customize the theme.

website/versioned_docs/version-3.x/material-top-tab-navigator.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,12 @@ Callback to handle press events; the argument is an object containing:
9595
* `navigation`: navigation prop for the screen
9696
* `defaultHandler`: the default handler for tab press
9797

98-
Useful for adding a custom logic before the transition to the next scene (the tapped one) starts.
98+
Useful for adding a custom logic before the transition to the next scene (the
99+
tapped one) starts.
100+
101+
#### `tabBarOnLongPress`
102+
103+
Callback to handle long press events; the argument is an object containing:
104+
105+
- `navigation`: navigation prop for the screen
106+
- `defaultHandler`: the default handler for tab press
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
id: version-3.x-tab-navigator
3+
title: createTabNavigator
4+
sidebar_label: createTabNavigator
5+
original_id: tab-navigator
6+
---
7+
8+
> Note: `createTabNavigator` is removed in `react-navigation@3.x`. Please use `createBottomTabNavigator` and/or `createMaterialTopTabNavigator` instead.
9+

website/versioned_docs/version-3.x/transitioner.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
id: version-3.x-transitioner
3-
original_id: transitioner
43
title: Transitioner
54
sidebar_label: Transitioner
5+
original_id: transitioner
66
---
77

88
`Transitioner` is a React component that helps manage transitions for complex animated components. It manages the timing of animations and keeps track of various screens as they enter and leave, but it doesn't know what anything looks like, because rendering is entirely deferred to the developer.

website/versioned_sidebars/version-3.x-sidebars.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"version-3.x-drawer-actions",
6464
"version-3.x-stack-navigator",
6565
"version-3.x-switch-navigator",
66+
"version-3.x-animated-switch-navigator",
6667
"version-3.x-drawer-navigator",
6768
"version-3.x-tab-navigator",
6869
"version-3.x-bottom-tab-navigator",

0 commit comments

Comments
 (0)