Skip to content

Commit 4d49e54

Browse files
committed
Inline snack code snippets into docs
1 parent 7f37948 commit 4d49e54

File tree

4 files changed

+329
-19
lines changed

4 files changed

+329
-19
lines changed

versioned_docs/version-7.x/drawer-layout.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ A cross-platform Drawer component for React Native implemented using [`react-nat
1010
<source src="/assets/libraries/drawer-layout/drawer-layout.mp4" />
1111
</video>
1212

13-
This package doesn't integrate with React Navigation. If you want to integrate the drawer layout with React Navigation's navigation system, e.g. want to show screens in the drawer and be able to navigate between them using `navigation.navigate` etc, use [Drawer Navigator](drawer-navigator.md) instead.
13+
If you need React Navigation integration, e.g. show screens in the drawer and be able to navigate between them using `navigation.navigate` etc, use [Drawer Navigator](drawer-navigator.md) instead.
1414

1515
## Installation
1616

versioned_docs/version-7.x/tab-view.md

Lines changed: 163 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ It follows material design guidelines by default, but you can also use your own
1212
<source src="/assets/libraries/tab-view/tab-view.mp4" />
1313
</video>
1414

15-
This package doesn't integrate with React Navigation. If you want to integrate the tab view with React Navigation's navigation system, e.g. want to show screens in the tab bar and be able to navigate between them using `navigation.navigate` etc, use [Material Top Tab Navigator](material-top-tab-navigator.md) instead.
15+
If you need React Navigation integration, e.g. show screens in the tab bar and be able to navigate between them using `navigation.navigate` etc, use [Material Top Tab Navigator](material-top-tab-navigator.md) instead.
1616

1717
## Installation
1818

@@ -79,7 +79,7 @@ const routes = [
7979
{ key: 'second', title: 'Second' },
8080
];
8181

82-
export default function TabViewExample() {
82+
export default function App() {
8383
const layout = useWindowDimensions();
8484
const [index, setIndex] = React.useState(0);
8585

@@ -95,11 +95,6 @@ export default function TabViewExample() {
9595
// codeblock-focus-end
9696
```
9797

98-
## More examples on Snack
99-
100-
- [Custom Tab Bar](https://snack.expo.io/@satya164/react-native-tab-view-custom-tabbar)
101-
- [Lazy Load](https://snack.expo.io/@satya164/react-native-tab-view-lazy-load)
102-
10398
## API reference
10499

105100
The package exports a `TabView` component which is the one you'd use to render the tab view, and a `TabBar` component which is the default tab bar implementation.
@@ -255,6 +250,102 @@ If this is not specified, the default tab bar is rendered. You pass this props t
255250
/>
256251
```
257252

253+
Example:
254+
255+
```js
256+
import * as React from 'react';
257+
import {
258+
Animated,
259+
StyleSheet,
260+
TouchableOpacity,
261+
View,
262+
useWindowDimensions,
263+
} from 'react-native';
264+
import { SceneMap, TabView } from 'react-native-tab-view';
265+
266+
const FirstRoute = () => (
267+
<View style={[styles.scene, { backgroundColor: '#ff4081' }]} />
268+
);
269+
270+
const SecondRoute = () => (
271+
<View style={[styles.scene, { backgroundColor: '#673ab7' }]} />
272+
);
273+
274+
const renderScene = SceneMap({
275+
first: FirstRoute,
276+
second: SecondRoute,
277+
});
278+
279+
const routes = [
280+
{ key: 'first', title: 'First' },
281+
{ key: 'second', title: 'Second' },
282+
];
283+
284+
// codeblock-focus-start
285+
const renderTabBar = ({ navigationState, position, jumpTo }) => {
286+
const inputRange = navigationState.routes.map((_, index) => index);
287+
288+
return (
289+
<View style={styles.tabBar}>
290+
{navigationState.routes.map((route, index) => {
291+
const opacity = position.interpolate({
292+
inputRange,
293+
outputRange: inputRange.map((inputIndex) =>
294+
inputIndex === index ? 1 : 0.5
295+
),
296+
});
297+
298+
return (
299+
<TouchableOpacity
300+
key={route.key}
301+
style={styles.tabItem}
302+
onPress={() => jumpTo(route.key)}
303+
>
304+
<Animated.Text style={[styles.label, { opacity }]}>
305+
{route.title}
306+
</Animated.Text>
307+
</TouchableOpacity>
308+
);
309+
})}
310+
</View>
311+
);
312+
};
313+
314+
export default function App() {
315+
const layout = useWindowDimensions();
316+
const [index, setIndex] = React.useState(0);
317+
318+
return (
319+
<TabView
320+
navigationState={{ index, routes }}
321+
renderScene={renderScene}
322+
// highlight-next-line
323+
renderTabBar={renderTabBar}
324+
onIndexChange={setIndex}
325+
initialLayout={{ width: layout.width }}
326+
/>
327+
);
328+
}
329+
// codeblock-focus-end
330+
331+
const styles = StyleSheet.create({
332+
scene: {
333+
flex: 1,
334+
},
335+
tabBar: {
336+
flexDirection: 'row',
337+
},
338+
tabItem: {
339+
alignItems: 'center',
340+
flex: 1,
341+
padding: 16,
342+
},
343+
label: {
344+
color: '#000',
345+
},
346+
});
347+
```
348+
258349
##### `tabBarPosition`
259350

260351
Position of the tab bar in the tab view. Possible values are `'top'` and `'bottom'`. Defaults to `'top'`.
@@ -267,7 +358,7 @@ By default all scenes are rendered to provide a smoother swipe experience. But y
267358

268359
```js
269360
<TabView
270-
lazy={({ route }) => route.name === 'Albums'}
361+
lazy={({ route }) => route.key === 'albums'}
271362
...
272363
/>
273364
```
@@ -280,6 +371,70 @@ You can also pass a boolean to enable lazy for all of the scenes:
280371
<TabView lazy />
281372
```
282373

374+
Example:
375+
376+
```js
377+
import * as React from 'react';
378+
import { StyleSheet, Text, View, useWindowDimensions } from 'react-native';
379+
import { SceneMap, TabView } from 'react-native-tab-view';
380+
381+
const FirstRoute = () => (
382+
<View style={[styles.scene, { backgroundColor: '#ff4081' }]} />
383+
);
384+
385+
const SecondRoute = () => (
386+
<View style={[styles.scene, { backgroundColor: '#673ab7' }]} />
387+
);
388+
389+
// codeblock-focus-start
390+
const renderLazyPlaceholder = ({ route }) => {
391+
return (
392+
<View style={styles.scene}>
393+
<Text>Loading {route.title}...</Text>
394+
</View>
395+
);
396+
};
397+
398+
// codeblock-focus-end
399+
const renderScene = SceneMap({
400+
first: FirstRoute,
401+
second: SecondRoute,
402+
});
403+
404+
const routes = [
405+
{ key: 'first', title: 'First' },
406+
{ key: 'second', title: 'Second' },
407+
];
408+
409+
// codeblock-focus-start
410+
export default function App() {
411+
const layout = useWindowDimensions();
412+
const [index, setIndex] = React.useState(0);
413+
414+
return (
415+
<TabView
416+
// highlight-next-line
417+
lazy
418+
navigationState={{ index, routes }}
419+
renderScene={renderScene}
420+
// highlight-next-line
421+
renderLazyPlaceholder={renderLazyPlaceholder}
422+
onIndexChange={setIndex}
423+
initialLayout={{ width: layout.width }}
424+
/>
425+
);
426+
}
427+
// codeblock-focus-end
428+
429+
const styles = StyleSheet.create({
430+
scene: {
431+
alignItems: 'center',
432+
flex: 1,
433+
justifyContent: 'center',
434+
},
435+
});
436+
```
437+
283438
##### `lazyPreloadDistance`
284439

285440
When `lazy` is enabled, you can specify how many adjacent routes should be preloaded with this prop. This value defaults to `0` which means lazy pages are loaded as they come into the viewport.

versioned_docs/version-8.x/drawer-layout.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ A cross-platform Drawer component for React Native implemented using [`react-nat
1010
<source src="/assets/libraries/drawer-layout/drawer-layout.mp4" />
1111
</video>
1212

13-
This package doesn't integrate with React Navigation. If you want to integrate the drawer layout with React Navigation's navigation system, e.g. want to show screens in the drawer and be able to navigate between them using `navigation.navigate` etc, use [Drawer Navigator](drawer-navigator.md) instead.
13+
If you need React Navigation integration, e.g. show screens in the drawer and be able to navigate between them using `navigation.navigate` etc, use [Drawer Navigator](drawer-navigator.md) instead.
1414

1515
## Installation
1616

0 commit comments

Comments
 (0)