forked from callstack/react-native-paper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRootNavigator.native.tsx
48 lines (44 loc) · 1.26 KB
/
RootNavigator.native.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
import * as React from 'react';
import { createStackNavigator } from 'react-navigation';
import { Appbar } from 'react-native-paper';
import ExampleList, { examples } from './ExampleList';
const routes = Object.keys(examples)
.map(id => ({ id, item: examples[id] }))
.reduce((acc, { id, item }) => {
const Comp = item;
const Screen = (props: any) => <Comp {...props} />;
Screen.navigationOptions = (props: any) => ({
header: (
<Appbar.Header>
<Appbar.BackAction onPress={() => props.navigation.goBack()} />
<Appbar.Content title={(Comp as any).title} />
</Appbar.Header>
),
...(typeof Comp.navigationOptions === 'function'
? Comp.navigationOptions(props)
: Comp.navigationOptions),
});
return {
...acc,
[id]: { screen: Screen },
};
}, {});
export default createStackNavigator(
{
home: { screen: ExampleList },
...routes,
},
{
navigationOptions: ({ navigation }: any) => ({
gestureResponseDistance: {
horizontal: 45,
},
header: (
<Appbar.Header>
<Appbar.Action icon="menu" onPress={() => navigation.openDrawer()} />
<Appbar.Content title="Examples" />
</Appbar.Header>
),
}),
}
);