11import React , { Text } from 'react-native'
22import NavBarBackButton from './NavBarBackButton'
33
4- export const defaultRouteMapper = {
5- LeftButton : ( route , navigator , index , navState ) => {
6- if ( index === 0 ) {
7- return null
4+ export function leftButtonRouteMapperGenerator ( BackComponent , styles , tintColor , topNavigator ) {
5+ return {
6+ LeftButton : ( route , navigator , index , navState ) => {
7+ if ( index === 0 ) {
8+ return null
9+ }
10+ const previousRoute = navState . routeStack [ index - 1 ]
11+ return (
12+ < BackComponent
13+ onPress = { ( ) => navigator . pop ( ) }
14+ style = { styles }
15+ tintColor = { tintColor } >
16+ { previousRoute . title }
17+ </ BackComponent >
18+ )
819 }
9- const previousRoute = navState . routeStack [ index - 1 ]
10- return (
11- < NavBarBackButton onPress = { ( ) => navigator . pop ( ) }
12- style = { [ styles . navFont , styles . back ] } >
13- { previousRoute . title }
14- </ NavBarBackButton >
15- )
16- } ,
17- RightButton : ( route , navigator , index , navState ) => {
18- if ( route . rightElement ) {
20+ }
21+ }
22+
23+ export function rightButtonRouteMapperGenerator ( RightComponent , topNavigator ) {
24+ return {
25+ RightButton : ( route , navigator , index , navState ) => {
26+ if ( RightComponent ) {
27+ return < RightComponent navigator = { navigator } topNavigator = { topNavigator } />
28+ }
1929 return route . rightElement
2030 }
21- } ,
22- Title : ( route , navigator , index , navState ) => {
23- const title = route . title || ''
24- return (
25- < Text style = { [ styles . navFont , styles . navText ] } numberOfLines = { 1 } >
26- { title }
27- </ Text >
28- )
2931 }
3032}
3133
32- const styles = React . StyleSheet . create ( {
34+ export function titleRouteMapperGenerator ( TitleComponent , styles , topNavigator ) {
35+ return {
36+ Title : ( route , navigator , index , navState ) => {
37+ const title = route . title || ''
38+ const Component = TitleComponent || Text
39+ return (
40+ < Component style = { styles }
41+ numberOfLines = { 1 } >
42+ { title }
43+ </ Component >
44+ )
45+ }
46+ }
47+ }
48+
49+ const defaultStyles = React . StyleSheet . create ( {
3350 back : {
3451 flex : 1 ,
3552 color : 'black' ,
@@ -44,3 +61,11 @@ const styles = React.StyleSheet.create({
4461 width : 200 ,
4562 } ,
4663} )
64+
65+ export function defaultRouteMapper ( ) {
66+ return {
67+ ...leftButtonRouteMapperGenerator ( NavBarBackButton , [ defaultStyles . navFont , defaultStyles . back ] , 'black' ) ,
68+ ...rightButtonRouteMapperGenerator ( ) ,
69+ ...titleRouteMapperGenerator ( Text , [ defaultStyles . navFont , defaultStyles . navText ] )
70+ }
71+ }
0 commit comments