Skip to content

Commit 5591868

Browse files
authored
docs: add standalone usage (#121)
1 parent b39cfaa commit 5591868

File tree

1 file changed

+185
-17
lines changed

1 file changed

+185
-17
lines changed

docs/docs/docs/guides/standalone-usage.md

Lines changed: 185 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,202 @@
22

33
If you don't use React Navigation, you can use the `TabView` component directly.
44

5+
## Basic Example
6+
57
```tsx
6-
import TabView, { SceneMap } from 'react-native-bottom-tabs';
8+
import * as React from 'react';
9+
import { View, Text } from 'react-native';
10+
import TabView from 'react-native-bottom-tabs';
11+
12+
const HomeScreen = () => (
13+
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
14+
<Text>Home Screen</Text>
15+
</View>
16+
);
17+
18+
const SettingsScreen = () => (
19+
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
20+
<Text>Settings Screen</Text>
21+
</View>
22+
);
723

8-
export default function ThreeTabs() {
9-
const [index, setIndex] = useState(0);
10-
const [routes] = useState([
11-
{ key: 'article', title: 'Article', focusedIcon: require('article.png'), badge: '!' },
24+
const renderScene = SceneMap({
25+
home: HomeScreen,
26+
settings: SettingsScreen,
27+
});
28+
29+
export default function TabViewExample() {
30+
const [index, setIndex] = React.useState(0);
31+
const [routes] = React.useState([
1232
{
13-
key: 'albums',
14-
title: 'Albums',
15-
focusedIcon: require('grid.png'),
16-
badge: '5',
33+
key: 'home',
34+
title: 'Home',
35+
focusedIcon: { sfSymbol: 'house' }
36+
},
37+
{
38+
key: 'settings',
39+
title: 'Settings',
40+
focusedIcon: { sfSymbol: 'gear' }
1741
},
18-
{ key: 'contacts', title: 'Contacts', focusedIcon: require('person.png') },
1942
]);
2043

21-
const renderScene = SceneMap({
22-
article: Article,
23-
albums: Albums,
24-
contacts: Contacts,
25-
});
26-
2744
return (
2845
<TabView
2946
navigationState={{ index, routes }}
30-
onIndexChange={setIndex}
3147
renderScene={renderScene}
48+
onIndexChange={setIndex}
49+
labeled
3250
/>
3351
);
3452
}
3553
```
54+
55+
## Scene Components
56+
57+
Each scene in the tab view is a separate component that represents a screen. You can define these components independently:
58+
59+
```tsx
60+
// HomeScreen.tsx
61+
export const HomeScreen = () => (
62+
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
63+
<Text>Home Screen</Text>
64+
</View>
65+
);
66+
67+
// SettingsScreen.tsx
68+
export const SettingsScreen = () => (
69+
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
70+
<Text>Settings Screen</Text>
71+
</View>
72+
);
73+
```
74+
75+
Then use `SceneMap` to map route keys to scene components:
76+
77+
```tsx
78+
import { SceneMap } from 'react-native-bottom-tabs';
79+
80+
const renderScene = SceneMap({
81+
home: HomeScreen,
82+
settings: SettingsScreen,
83+
});
84+
```
85+
86+
## Props
87+
88+
### Required Props
89+
90+
#### `navigationState`
91+
92+
State for the tab view. The state should contain:
93+
- `routes`: Array of route objects containing `key` and `title` props
94+
- `index`: Current selected tab index
95+
96+
#### `renderScene`
97+
98+
Function that returns a React element to render for the screen. Can be created using `SceneMap` or custom render function.
99+
100+
#### `onIndexChange`
101+
102+
Callback that is called when the tab index changes.
103+
104+
### Optional Props
105+
106+
#### `labeled`
107+
108+
Whether to show labels in tabs. When `false`, only icons will be displayed.
109+
- Type: `boolean`
110+
- Default: `true`
111+
112+
#### `sidebarAdaptable` <Badge text="iOS" type="info" />
113+
114+
A tab bar style that adapts to each platform:
115+
- iPadOS: Top tab bar that can adapt into a sidebar
116+
- iOS: Bottom tab bar
117+
- macOS/tvOS: Sidebar
118+
- visionOS: Ornament with sidebar for secondary tabs
119+
120+
#### `ignoresTopSafeArea` <Badge text="iOS" type="info" />
121+
122+
Whether to ignore the top safe area.
123+
- Type: `boolean`
124+
125+
#### `disablePageAnimations` <Badge text="iOS" type="info" />
126+
127+
Whether to disable animations between tabs.
128+
- Type: `boolean`
129+
130+
#### `hapticFeedbackEnabled`
131+
132+
Whether to enable haptic feedback on tab press.
133+
- Type: `boolean`
134+
- Default: `true`
135+
136+
#### `scrollEdgeAppearance` <Badge text="iOS" type="info" />
137+
138+
Appearance attributes for the tab bar when a scroll view is at the bottom.
139+
- Type: `'default' | 'opaque' | 'transparent'`
140+
141+
#### `tabBarActiveTintColor`
142+
143+
Color for the active tab.
144+
- Type: `ColorValue`
145+
146+
#### `tabBarInactiveTintColor`
147+
148+
Color for inactive tabs.
149+
- Type: `ColorValue`
150+
151+
#### `barTintColor`
152+
153+
Background color of the tab bar.
154+
- Type: `ColorValue`
155+
156+
#### `translucent` <Badge text="iOS" type="info" />
157+
158+
Whether the tab bar is translucent.
159+
- Type: `boolean`
160+
161+
#### `activeIndicatorColor` <Badge text="Android" type="info" />
162+
163+
Color of tab indicator.
164+
- Type: `ColorValue`
165+
166+
### Route Configuration
167+
168+
Each route in the `routes` array can have the following properties:
169+
170+
- `key`: Unique identifier for the route
171+
- `title`: Display title for the tab
172+
- `focusedIcon`: Icon to show when tab is active
173+
- `unfocusedIcon`: Icon to show when tab is inactive (optional)
174+
- `badge`: Badge text to display on the tab
175+
- `activeTintColor`: Custom active tint color for this specific tab
176+
- `lazy`: Whether to lazy load this tab's content
177+
178+
### Helper Props
179+
180+
#### `getLazy`
181+
182+
Function to determine if a screen should be lazy loaded.
183+
- Default: Uses `route.lazy`
184+
185+
#### `getLabelText`
186+
187+
Function to get the label text for a tab.
188+
- Default: Uses `route.title`
189+
190+
#### `getBadge`
191+
192+
Function to get the badge text for a tab.
193+
- Default: Uses `route.badge`
194+
195+
#### `getActiveTintColor`
196+
197+
Function to get the active tint color for a tab.
198+
- Default: Uses `route.activeTintColor`
199+
200+
#### `getIcon`
201+
202+
Function to get the icon for a tab.
203+
- Default: Uses `route.focusedIcon` and `route.unfocusedIcon`

0 commit comments

Comments
 (0)