mirror of
https://github.com/status-im/react-navigation.git
synced 2025-02-24 17:18:09 +00:00
* Initial commit * Remove HybridExample (#985) * Remove HybridExample * Remove last mention of HelloHybrid * Remove console log * Fix flow and example * Fix routers api docs * Keep options in single place * chore * Fix styling * Organise miscs * Better flow type for screen options * Flow test website and add more types to options * navigationOptions instead of prevOptions makes more sense * Fixes * Fix up docs * Fix * Update route decl * Provide error when removed API is used * Remove lock * Add validators * Make StacksOverTabs config valid again * Do not return * Fix redbox
95 lines
2.0 KiB
JavaScript
95 lines
2.0 KiB
JavaScript
/**
|
|
* @flow
|
|
*/
|
|
|
|
import React from 'react';
|
|
import {
|
|
Button,
|
|
ScrollView,
|
|
} from 'react-native';
|
|
import {
|
|
StackNavigator,
|
|
} from 'react-navigation';
|
|
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"
|
|
/>
|
|
<Button
|
|
onPress={() => navigation.navigate('Photos', { name: 'Jane' })}
|
|
title="Go to a photos screen"
|
|
/>
|
|
<Button
|
|
onPress={() => navigation.goBack(null)}
|
|
title="Go back"
|
|
/>
|
|
</ScrollView>
|
|
);
|
|
|
|
const MyHomeScreen = ({ navigation }) => (
|
|
<MyNavScreen
|
|
banner="Home Screen"
|
|
navigation={navigation}
|
|
/>
|
|
);
|
|
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
|
|
banner={
|
|
`${navigation.state.params.mode === 'edit' ? 'Now Editing ' : ''
|
|
}${navigation.state.params.name}'s Profile`
|
|
}
|
|
navigation={navigation}
|
|
/>
|
|
);
|
|
|
|
MyProfileScreen.navigationOptions = props => {
|
|
const {navigation} = props;
|
|
const {state, setParams} = navigation;
|
|
const {params} = state;
|
|
return {
|
|
headerTitle: `${params.name}'s Profile!`,
|
|
// Render a button on the right side of the header.
|
|
// When pressed switches the screen to edit mode.
|
|
headerRight: (
|
|
<Button
|
|
title={params.mode === 'edit' ? 'Done' : 'Edit'}
|
|
onPress={() => setParams({ mode: params.mode === 'edit' ? '' : 'edit' })}
|
|
/>
|
|
),
|
|
};
|
|
};
|
|
|
|
const SimpleStack = StackNavigator({
|
|
Home: {
|
|
screen: MyHomeScreen,
|
|
},
|
|
Profile: {
|
|
path: 'people/:name',
|
|
screen: MyProfileScreen,
|
|
},
|
|
Photos: {
|
|
path: 'photos/:name',
|
|
screen: MyPhotosScreen,
|
|
},
|
|
});
|
|
|
|
export default SimpleStack;
|