-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTopNavigatorWrapper.js
More file actions
92 lines (81 loc) · 2.76 KB
/
TopNavigatorWrapper.js
File metadata and controls
92 lines (81 loc) · 2.76 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* @flow */
import React from 'react'
import PropTypes from 'prop-types'
import { View, Platform } from 'react-native'
import NavigatorWrapper from './NavigatorWrapper'
import { defaultRouteMapper } from './RouteMapper'
import CustomComponents from 'react-native-deprecated-custom-components'
class TopNavigatorWrapper extends React.Component {
static isAndroid = Platform.OS !== 'ios';
_renderScene (route: Object, navigator: Object) {
// Render the inner component or the modal. This is basically a container
// that can handle anything, usually a TabBarIOS with more NavigatorWrappers
// inside.
if (route.id === 'mainComponent') {
// Inject the top navigator into the inner component in order to be able
// to open a modal from anywhere
const children = React.cloneElement(this.props.children, {
topNavigator: navigator
})
return (
<View style={[{flex: 1}, this.props.containerStyle]}>
{children}
</View>
)
}
// Render the modal component. This component serves as a FloatFromBottom
// Navigator. Can have another navigator inside. ``passProps`` is sent into
// the NavigatorWrapper in order to send props to the component pushed.
//
// By generating the routeMapper from a function, we can pass the outer
// modal navigator into the route mapper.
const modalRouteMapper = this.props.modalRouteMapper || defaultRouteMapper
return (
<NavigatorWrapper
initialRoute={{
handleBackAndroid: true,
...route,
}}
topNavigator={navigator}
navBarStyle={this.props.modalNavBarStyle}
routeMapper={modalRouteMapper(navigator)}
hideNavBar={this.props.hideNavBar}
/>
)
}
render () {
const modalAnimation = (TopNavigatorWrapper.isAndroid) ? CustomComponents.Navigator.SceneConfigs.FloatFromBottomAndroid : CustomComponents.Navigator.SceneConfigs.FloatFromBottom
return (
<CustomComponents.Navigator
ref='topNavigator'
renderScene={(route, navigator) => (this._renderScene(route, navigator))}
initialRoute={{id: 'mainComponent'}}
configureScene={(route, routeStack) => modalAnimation}
style={this.props.modalStyle}
/>
)
}
}
TopNavigatorWrapper.propTypes = {
/**
* Optional style for the default modal navigation bar.
*/
modalNavBarStyle: View.propTypes.style,
/**
* Route mapper for the modal component
*/
modalRouteMapper: PropTypes.func,
/**
* The style of the inner container
*/
containerStyle: View.propTypes.style,
/**
* The style of the modal transition
*/
modalStyle: View.propTypes.style,
/**
* Hides the modal navigation bar
*/
hideNavBar: PropTypes.bool,
}
export default TopNavigatorWrapper