mirror of
https://github.com/status-im/react-navigation.git
synced 2025-02-24 17:18:09 +00:00
98 lines
2.1 KiB
JavaScript
98 lines
2.1 KiB
JavaScript
/**
|
|
* @flow
|
|
*/
|
|
|
|
import React from 'react';
|
|
import {
|
|
Button,
|
|
ScrollView,
|
|
Text,
|
|
} 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('HeaderTest')}
|
|
title="Go to a header toggle screen"
|
|
/>
|
|
{navigation.state.routeName === 'HeaderTest' && <Button
|
|
title="Toggle Header"
|
|
onPress={() => navigation.setParams({ header: (!navigation.state.params || navigation.state.params.header === 'visible') ? 'none' : 'visible' })}
|
|
/>}
|
|
<Button
|
|
onPress={() => navigation.goBack(null)}
|
|
title="Go back"
|
|
/>
|
|
</ScrollView>
|
|
);
|
|
|
|
const MyHomeScreen = ({ navigation }) => (
|
|
<MyNavScreen
|
|
banner="Home Screen"
|
|
navigation={navigation}
|
|
/>
|
|
);
|
|
MyHomeScreen.navigationOptions = {
|
|
title: 'Welcome',
|
|
};
|
|
|
|
const MyProfileScreen = ({ navigation }) => (
|
|
<MyNavScreen
|
|
banner={`${navigation.state.params.name}'s Profile`}
|
|
navigation={navigation}
|
|
/>
|
|
);
|
|
MyProfileScreen.navigationOptions = ({ navigation }) => ({
|
|
title: `${navigation.state.params.name}'s Profile!`,
|
|
});
|
|
|
|
const ProfileNavigator = StackNavigator({
|
|
Home: {
|
|
screen: MyHomeScreen,
|
|
},
|
|
Profile: {
|
|
path: 'people/:name',
|
|
screen: MyProfileScreen,
|
|
},
|
|
}, {
|
|
navigationOptions: {headerVisible: false},
|
|
});
|
|
|
|
const MyHeaderTestScreen = ({ navigation }) => (
|
|
<MyNavScreen
|
|
banner={`Full screen view`}
|
|
navigation={navigation}
|
|
/>
|
|
);
|
|
MyHeaderTestScreen.navigationOptions = ({navigation}) => {
|
|
const header = navigation.state.params && navigation.state.params.header;
|
|
const headerVisible = !header || header === 'visible';
|
|
return {
|
|
headerVisible,
|
|
title: 'Now you see me',
|
|
};
|
|
};
|
|
|
|
const ModalStack = StackNavigator({
|
|
Home: {
|
|
screen: MyHomeScreen,
|
|
},
|
|
ProfileNavigator: {
|
|
screen: ProfileNavigator,
|
|
},
|
|
HeaderTest: {screen: MyHeaderTestScreen},
|
|
}, {
|
|
mode: 'modal',
|
|
});
|
|
|
|
export default ModalStack;
|