-
Notifications
You must be signed in to change notification settings - Fork 441
/
Copy pathTabViewInsideScrollViewExample.tsx
55 lines (48 loc) · 1.33 KB
/
TabViewInsideScrollViewExample.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import * as React from 'react';
import { View, useWindowDimensions, Text, ScrollView } from 'react-native';
import { TabView, SceneMap } from 'react-native-tab-view';
import { Header } from 'react-native/Libraries/NewAppScreen';
function FirstRoute() {
return (
<View style={{ flex: 1, padding: 20, backgroundColor: 'blue' }}>
<Text style={{color: 'white'}}>First Route</Text>
</View>
);
}
function SecondRoute() {
return (
<View style={{ flex: 1, padding: 20, backgroundColor: 'purple' }}>
<Text style={{color: 'white'}}>Second Route</Text>
</View>
);
}
const renderScene = SceneMap({
first: FirstRoute,
second: SecondRoute,
});
const routes = [
{ key: 'first', title: 'First' },
{ key: 'second', title: 'Second' },
];
export function TabViewInsideScrollViewExample() {
const layout = useWindowDimensions();
const [index, setIndex] = React.useState(0);
return (
<ScrollView
contentContainerStyle={{flexGrow: 1, backgroundColor: 'red'}}
nestedScrollEnabled={false}
scrollEnabled={true}
>
<Header />
<View>
<TabView
style={{height: 1200}}
navigationState={{ index, routes }}
renderScene={renderScene}
onIndexChange={setIndex}
initialLayout={{ width: layout.width }}
/>
</View>
</ScrollView>
);
}