2017-01-26 11:49:39 -08:00
|
|
|
/**
|
|
|
|
* @flow
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
2017-05-14 12:14:12 -07:00
|
|
|
import { Button, ScrollView } from 'react-native';
|
|
|
|
import { StackNavigator } from 'react-navigation';
|
2017-01-26 11:49:39 -08:00
|
|
|
import SampleText from './SampleText';
|
|
|
|
|
|
|
|
const MyNavScreen = ({ navigation, banner }) => (
|
|
|
|
<ScrollView>
|
|
|
|
<SampleText>{banner}</SampleText>
|
|
|
|
<Button
|
|
|
|
onPress={() => navigation.navigate('Profile', { name: 'Jane' })}
|
|
|
|
title="Go to a profile screen"
|
|
|
|
/>
|
2017-02-13 06:05:12 +00:00
|
|
|
<Button
|
|
|
|
onPress={() => navigation.navigate('Photos', { name: 'Jane' })}
|
|
|
|
title="Go to a photos screen"
|
|
|
|
/>
|
2017-05-14 12:14:12 -07:00
|
|
|
<Button onPress={() => navigation.goBack(null)} title="Go back" />
|
2017-01-26 11:49:39 -08:00
|
|
|
</ScrollView>
|
|
|
|
);
|
|
|
|
|
|
|
|
const MyHomeScreen = ({ navigation }) => (
|
2017-05-14 12:14:12 -07:00
|
|
|
<MyNavScreen banner="Home Screen" navigation={navigation} />
|
2017-01-26 11:49:39 -08:00
|
|
|
);
|
|
|
|
MyHomeScreen.navigationOptions = {
|
|
|
|
title: 'Welcome',
|
|
|
|
};
|
|
|
|
|
|
|
|
const MyPhotosScreen = ({ navigation }) => (
|
|
|
|
<MyNavScreen
|
|
|
|
banner={`${navigation.state.params.name}'s Photos`}
|
|
|
|
navigation={navigation}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
MyPhotosScreen.navigationOptions = {
|
|
|
|
title: 'Photos',
|
|
|
|
};
|
|
|
|
|
|
|
|
const MyProfileScreen = ({ navigation }) => (
|
|
|
|
<MyNavScreen
|
2017-05-14 12:14:12 -07:00
|
|
|
banner={`${navigation.state.params.mode === 'edit' ? 'Now Editing ' : ''}${navigation.state.params.name}'s Profile`}
|
2017-01-26 11:49:39 -08:00
|
|
|
navigation={navigation}
|
|
|
|
/>
|
|
|
|
);
|
2017-04-13 00:49:08 +02:00
|
|
|
|
|
|
|
MyProfileScreen.navigationOptions = props => {
|
2017-05-14 12:14:12 -07:00
|
|
|
const { navigation } = props;
|
|
|
|
const { state, setParams } = navigation;
|
|
|
|
const { params } = state;
|
2017-04-13 00:49:08 +02:00
|
|
|
return {
|
|
|
|
headerTitle: `${params.name}'s Profile!`,
|
2017-01-26 11:49:39 -08:00
|
|
|
// Render a button on the right side of the header.
|
|
|
|
// When pressed switches the screen to edit mode.
|
2017-04-13 00:49:08 +02:00
|
|
|
headerRight: (
|
2017-01-26 11:49:39 -08:00
|
|
|
<Button
|
2017-04-13 00:49:08 +02:00
|
|
|
title={params.mode === 'edit' ? 'Done' : 'Edit'}
|
2017-05-14 12:14:12 -07:00
|
|
|
onPress={() =>
|
|
|
|
setParams({ mode: params.mode === 'edit' ? '' : 'edit' })}
|
2017-01-26 11:49:39 -08:00
|
|
|
/>
|
|
|
|
),
|
2017-04-13 00:49:08 +02:00
|
|
|
};
|
2017-01-26 11:49:39 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
const SimpleStack = StackNavigator({
|
|
|
|
Home: {
|
|
|
|
screen: MyHomeScreen,
|
|
|
|
},
|
|
|
|
Profile: {
|
|
|
|
path: 'people/:name',
|
|
|
|
screen: MyProfileScreen,
|
|
|
|
},
|
|
|
|
Photos: {
|
|
|
|
path: 'photos/:name',
|
|
|
|
screen: MyPhotosScreen,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
export default SimpleStack;
|