[Minor] Update Stacks examples for better clarity (#1341)

* Update Stacks{In,Over}Tabs example for better clarity

* Remove redundant navigationOptions in stack examples

* Update text in ReduxExample to clarify which route is being used
This commit is contained in:
Kevin Cooper 2017-05-12 18:27:53 -04:00 committed by Eric Vicenti
parent 625fc5b109
commit f575d90986
3 changed files with 19 additions and 26 deletions

View File

@ -20,15 +20,15 @@ const MyNavScreen = ({ navigation, banner }) => (
<SampleText>{banner}</SampleText> <SampleText>{banner}</SampleText>
<Button <Button
onPress={() => navigation.navigate('Profile', { name: 'Jordan' })} onPress={() => navigation.navigate('Profile', { name: 'Jordan' })}
title="Go to a profile screen" title="Open profile screen"
/> />
<Button <Button
onPress={() => navigation.navigate('NotifSettings')} onPress={() => navigation.navigate('NotifSettings')}
title="Go to notification settings" title="Open notifications screen"
/> />
<Button <Button
onPress={() => navigation.navigate('SettingsTab')} onPress={() => navigation.navigate('SettingsTab')}
title="Go to settings" title="Go to settings tab"
/> />
<Button <Button
onPress={() => navigation.goBack(null)} onPress={() => navigation.goBack(null)}
@ -50,20 +50,17 @@ const MyProfileScreen = ({ navigation }) => (
navigation={navigation} navigation={navigation}
/> />
); );
MyProfileScreen.navigationOptions = ({ navigation }) => ({
title: `${navigation.state.params.name}'s Profile!`,
});
const MyNotificationsSettingsScreen = ({ navigation }) => ( const MyNotificationsSettingsScreen = ({ navigation }) => (
<MyNavScreen <MyNavScreen
banner="Notification Settings" banner="Notifications Screen"
navigation={navigation} navigation={navigation}
/> />
); );
const MySettingsScreen = ({ navigation }) => ( const MySettingsScreen = ({ navigation }) => (
<MyNavScreen <MyNavScreen
banner="Settings" banner="Settings Screen"
navigation={navigation} navigation={navigation}
/> />
); );
@ -96,7 +93,7 @@ const SettingsTab = StackNavigator({
NotifSettings: { NotifSettings: {
screen: MyNotificationsSettingsScreen, screen: MyNotificationsSettingsScreen,
navigationOptions: { navigationOptions: {
title: 'Notification Settings', title: 'Notifications',
}, },
}, },
}); });

View File

@ -20,15 +20,15 @@ const MyNavScreen = ({ navigation, banner }) => (
<SampleText>{banner}</SampleText> <SampleText>{banner}</SampleText>
<Button <Button
onPress={() => navigation.navigate('Profile', { name: 'Jordan' })} onPress={() => navigation.navigate('Profile', { name: 'Jordan' })}
title="Go to a profile screen" title="Open profile screen"
/> />
<Button <Button
onPress={() => navigation.navigate('NotifSettings')} onPress={() => navigation.navigate('NotifSettings')}
title="Go to notification settings" title="Open notifications screen"
/> />
<Button <Button
onPress={() => navigation.navigate('SettingsTab')} onPress={() => navigation.navigate('SettingsTab')}
title="Go to settings" title="Go to settings tab"
/> />
<Button <Button
onPress={() => navigation.goBack(null)} onPress={() => navigation.goBack(null)}
@ -50,20 +50,17 @@ const MyProfileScreen = ({ navigation }) => (
navigation={navigation} navigation={navigation}
/> />
); );
MyProfileScreen.navigationOptions = ({ navigation }) => {
title: `${navigation.state.params.name}'s Profile!`
};
const MyNotificationsSettingsScreen = ({ navigation }) => ( const MyNotificationsSettingsScreen = ({ navigation }) => (
<MyNavScreen <MyNavScreen
banner="Notification Settings" banner="Notifications Screen"
navigation={navigation} navigation={navigation}
/> />
); );
const MySettingsScreen = ({ navigation }) => ( const MySettingsScreen = ({ navigation }) => (
<MyNavScreen <MyNavScreen
banner="Settings" banner="Settings Screen"
navigation={navigation} navigation={navigation}
/> />
); );
@ -73,6 +70,7 @@ const TabNav = TabNavigator({
screen: MyHomeScreen, screen: MyHomeScreen,
path: '/', path: '/',
navigationOptions: { navigationOptions: {
title: 'Welcome',
tabBarLabel: 'Home', tabBarLabel: 'Home',
tabBarIcon: ({ tintColor, focused }) => ( tabBarIcon: ({ tintColor, focused }) => (
<Ionicons <Ionicons
@ -87,7 +85,7 @@ const TabNav = TabNavigator({
screen: MySettingsScreen, screen: MySettingsScreen,
path: '/settings', path: '/settings',
navigationOptions: { navigationOptions: {
tabBarLabel: 'Settings', title: 'Settings',
tabBarIcon: ({ tintColor, focused }) => ( tabBarIcon: ({ tintColor, focused }) => (
<Ionicons <Ionicons
name={focused ? 'ios-settings' : 'ios-settings-outline'} name={focused ? 'ios-settings' : 'ios-settings-outline'}
@ -110,7 +108,7 @@ const StacksOverTabs = StackNavigator({
NotifSettings: { NotifSettings: {
screen: MyNotificationsSettingsScreen, screen: MyNotificationsSettingsScreen,
navigationOptions: { navigationOptions: {
title: 'Notification Settings', title: 'Notifications',
}, },
}, },
Profile: { Profile: {
@ -120,8 +118,6 @@ const StacksOverTabs = StackNavigator({
title: `${navigation.state.params.name}'s Profile!` title: `${navigation.state.params.name}'s Profile!`
}, },
}, },
}, {
headerMode: 'none',
}); });
export default StacksOverTabs; export default StacksOverTabs;

View File

@ -3,17 +3,17 @@ import { connect } from 'react-redux';
import { Button } from 'react-native'; import { Button } from 'react-native';
import { NavigationActions } from 'react-navigation'; import { NavigationActions } from 'react-navigation';
const AuthButton = ({ logout, login, isLoggedIn }) => ( const AuthButton = ({ logout, loginScreen, isLoggedIn }) => (
<Button <Button
title={isLoggedIn ? 'Log Out' : 'Log In'} title={isLoggedIn ? 'Log Out' : 'Open Login Screen'}
onPress={isLoggedIn ? logout : login} onPress={isLoggedIn ? logout : loginScreen}
/> />
); );
AuthButton.propTypes = { AuthButton.propTypes = {
isLoggedIn: PropTypes.bool.isRequired, isLoggedIn: PropTypes.bool.isRequired,
logout: PropTypes.func.isRequired, logout: PropTypes.func.isRequired,
login: PropTypes.func.isRequired, loginScreen: PropTypes.func.isRequired,
}; };
const mapStateToProps = state => ({ const mapStateToProps = state => ({
@ -22,7 +22,7 @@ const mapStateToProps = state => ({
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = dispatch => ({
logout: () => dispatch({ type: 'Logout' }), logout: () => dispatch({ type: 'Logout' }),
login: () => dispatch(NavigationActions.navigate({ routeName: 'Login' })), loginScreen: () => dispatch(NavigationActions.navigate({ routeName: 'Login' })),
}); });
export default connect(mapStateToProps, mapDispatchToProps)(AuthButton); export default connect(mapStateToProps, mapDispatchToProps)(AuthButton);