Last active
November 11, 2016 15:10
-
-
Save jrmcdona/a46a22131a35032efa77212849635fd2 to your computer and use it in GitHub Desktop.
Code snippet from my route set up and a ProfileScreen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @providesModule Router | |
* @flow | |
*/ | |
import { | |
createRouter, | |
} from '@exponent/ex-navigation'; | |
import LeaderboardScreen from 'LeaderboardScreen'; | |
import ProfileScreen from 'ProfileScreen'; | |
import NotificationScreen from 'NotificationsScreen'; | |
export default createRouter(() => ({ | |
notifications: () => NotificationsScreen, | |
profile: () => ProfileScreen, | |
leaderboard: () => LeaderboardScreen | |
})); | |
/** | |
* @providesModule ProfileScreen | |
* @flow | |
*/ | |
import React from 'react'; | |
import { | |
StyleSheet, | |
Text, | |
View, | |
} from 'react-native'; | |
export default class ProfileScreen extends React.Component { | |
/** | |
* This is where we can define any route configuration for this | |
* screen. For example, in addition to the navigationBar title we | |
* could add backgroundColor. | |
*/ | |
static route = { | |
navigationBar: { | |
title: 'Profile', | |
} | |
} | |
render() { | |
return ( | |
<View style={{alignItems: 'center', justifyContent: 'center', flex: 1}}> | |
<Text>ProfileScreen!</Text> | |
</View> | |
) | |
} | |
_goBackHome = () => { | |
this.props.navigator.pop(); | |
} | |
} | |
In my app.js file here is the navigation: | |
/** | |
* @providesModule App | |
* @flow | |
*/ | |
import React from 'react'; | |
import { | |
StyleSheet, | |
Text, | |
View, | |
} from 'react-native'; | |
import { | |
StackNavigation, | |
TabNavigation, | |
TabNavigationItem, | |
} from '@exponent/ex-navigation'; | |
//import { Ionicons } from '@exponent/vector-icons'; | |
import Icon from 'react-native-vector-icons/Ionicons'; | |
//import { Font } from 'exponent'; | |
import Colors from 'Colors'; | |
import Router from 'Router'; | |
const defaultRouteConfig = { | |
navigationBar: { | |
tintColor: Colors.navigationBarTintColor, | |
backgroundColor: Colors.navigationBarBackgroundColor, | |
titleStyle: 'Arial', | |
}, | |
}; | |
type TabRenderFunction = (isSelected: bool) => ReactElement<any>; | |
export default class App extends React.Component { | |
render() { | |
return ( | |
<TabNavigation | |
tabBarColor={Colors.tabBar} | |
tabBarHeight={56} | |
initialTab="profile"> | |
<TabNavigationItem | |
id="profile" | |
renderIcon={isSelected => this._renderIcon('Profile', 'ios-compass-outline', isSelected)}> | |
<StackNavigation | |
defaultRouteConfig={defaultRouteConfig} | |
initialRoute={Router.getRoute('profile')} | |
/> | |
</TabNavigationItem> | |
<TabNavigationItem | |
id="leaderboard" | |
renderIcon={isSelected => this._renderIcon('Leaderboard', 'ios-person-outline', isSelected)}> | |
<StackNavigation | |
defaultRouteConfig={defaultRouteConfig} | |
initialRoute={Router.getRoute('leaderboard')} | |
/> | |
</TabNavigationItem> | |
<TabNavigationItem | |
id="notifications" | |
renderIcon={isSelected => this._renderIcon('Notifications', 'ios-clock-outline', isSelected)}> | |
<StackNavigation | |
defaultRouteConfig={defaultRouteConfig} | |
initialRoute={Router.getRoute('notifications')} | |
/> | |
</TabNavigationItem> | |
</TabNavigation> | |
); | |
} | |
_renderIcon(title: string, iconName: string, isSelected: bool): ReactElement<any> { | |
let color = isSelected ? Colors.tabIconSelected : Colors.tabIconDefault; | |
return ( | |
<View style={styles.tabItemContainer}> | |
<Ionicons name={iconName} size={32} color={color} /> | |
<Text style={[styles.tabTitleText, {color}]} numberOfLines={1}> | |
{title} | |
</Text> | |
</View> | |
); | |
} | |
} | |
const styles = StyleSheet.create({ | |
container: { | |
flex: 1, | |
backgroundColor: '#fff', | |
}, | |
tabItemContainer: { | |
alignItems: 'center', | |
justifyContent: 'center', | |
}, | |
tabTitleText: { | |
fontSize: 11, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment