forked from aksonov/react-native-router-flux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReactRouter.js
37 lines (32 loc) · 1.27 KB
/
ReactRouter.js
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
/**
* Copyright (c) 2015-present, Pavel Aksonov
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import React from 'react-native'
import Router from './Router';
import ExRouter from './ExRouter';
const {StyleSheet, View} = React;
import Actions from './Actions';
export default class extends React.Component {
constructor(props){
super(props);
const createRouter = props.createRouter || this.createRouter;
this.router = createRouter(props);
}
createRouter(props){
const schemas = React.Children.map(props.children, child=>child).filter(child=>child.type.prototype.className() === "Schema").map(child=>child.props);
const routes = React.Children.map(props.children, child=>child).filter(child=>child.type.prototype.className() === "Route").map(child=>child.props);
return new Router(routes, schemas, props.initialRoutes || (props.initial && [props.initial]), props);
}
componentDidMount(){
this.router.delegate = this.refs.router;
}
render(){
const Component = this.props.router || ExRouter;
return (<Component ref="router" {...this.props} router={this.router} />);
}
}