createNavigator.js
1.59 KB
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
56
57
58
/* @flow */
import * as React from 'react';
import type {
NavigationRouter,
NavigationNavigator,
NavigationNavigatorProps,
NavigationRouteConfigMap,
NavigationState,
NavigationScreenProp,
} from '../TypeDefinition';
import type { NavigatorType } from './NavigatorTypes';
// Props we want createNavigator to Inject
type RouterProp<S: NavigationState, O: {}> = {
router: NavigationRouter<S, O>,
};
// NavigatorCreator type
type _NavigatorCreator<NavigationViewProps: {}, S: NavigationState, O: {}> = (
NavigationView: React.ComponentType<RouterProp<S, O> & NavigationViewProps>
) => NavigationNavigator<S, O, NavigationViewProps>;
/**
* Creates a navigator based on a router and a view that renders the screens.
*/
export default function createNavigator<
S: NavigationState,
O: {},
NavigatorConfig: {},
NavigationViewProps: NavigationNavigatorProps<O, S>
>(
router: NavigationRouter<S, O>,
routeConfigs?: NavigationRouteConfigMap,
navigatorConfig?: NavigatorConfig,
navigatorType?: NavigatorType
): _NavigatorCreator<NavigationViewProps, S, O> {
return (
NavigationView: React.ComponentType<RouterProp<S, O> & NavigationViewProps>
): NavigationNavigator<S, O, NavigationViewProps> => {
class Navigator extends React.Component<NavigationViewProps> {
static router = router;
static routeConfigs = routeConfigs;
static navigatorConfig = navigatorConfig;
static navigatorType = navigatorType;
static navigationOptions = null;
render() {
return <NavigationView {...this.props} router={router} />;
}
}
return Navigator;
};
}