2018-02-16 12:41:59 -08:00
|
|
|
/**
|
|
|
|
* @flow
|
|
|
|
*/
|
|
|
|
import type { NavigationScreenProp } from 'react-navigation';
|
|
|
|
|
|
|
|
import * as React from 'react';
|
2018-03-13 21:13:19 +01:00
|
|
|
import { ScrollView, StatusBar } from 'react-native';
|
2018-03-14 15:21:38 -07:00
|
|
|
import { createStackNavigator, SafeAreaView } from 'react-navigation';
|
2018-05-23 13:18:35 -04:00
|
|
|
import invariant from 'invariant';
|
|
|
|
|
2018-03-13 21:13:19 +01:00
|
|
|
import { Button } from './commonComponents/ButtonWithMargin';
|
2018-02-16 12:41:59 -08:00
|
|
|
|
|
|
|
type NavScreenProps = {
|
|
|
|
navigation: NavigationScreenProp<*>,
|
|
|
|
};
|
|
|
|
|
|
|
|
class HomeScreen extends React.Component<NavScreenProps> {
|
|
|
|
static navigationOptions = {
|
|
|
|
title: 'Welcome',
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { navigation } = this.props;
|
2018-05-23 13:18:35 -04:00
|
|
|
const { push } = navigation;
|
|
|
|
invariant(push, 'missing `push` action creator for StackNavigator');
|
2018-02-16 12:41:59 -08:00
|
|
|
|
|
|
|
return (
|
2018-02-16 12:42:44 -08:00
|
|
|
<SafeAreaView style={{ paddingTop: 30 }}>
|
2018-05-23 13:18:35 -04:00
|
|
|
<Button onPress={() => push('Other')} title="Push another screen" />
|
2018-02-16 12:41:59 -08:00
|
|
|
<Button
|
2018-05-23 13:18:35 -04:00
|
|
|
onPress={() => push('ScreenWithNoHeader')}
|
2018-03-25 10:27:59 -07:00
|
|
|
title="Push screen with no header"
|
|
|
|
/>
|
|
|
|
<Button onPress={() => navigation.goBack(null)} title="Go Home" />
|
2018-02-16 12:41:59 -08:00
|
|
|
<StatusBar barStyle="default" />
|
|
|
|
</SafeAreaView>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class OtherScreen extends React.Component<NavScreenProps> {
|
|
|
|
static navigationOptions = {
|
|
|
|
title: 'Your title here',
|
|
|
|
};
|
|
|
|
|
2018-03-25 10:27:59 -07:00
|
|
|
render() {
|
|
|
|
const { navigation } = this.props;
|
2018-05-23 13:18:35 -04:00
|
|
|
const { push, pop } = navigation;
|
|
|
|
invariant(push && pop, 'missing action creators for StackNavigator');
|
2018-03-25 10:27:59 -07:00
|
|
|
|
|
|
|
return (
|
|
|
|
<SafeAreaView style={{ paddingTop: 30 }}>
|
|
|
|
<Button
|
2018-05-23 13:18:35 -04:00
|
|
|
onPress={() => push('ScreenWithLongTitle')}
|
2018-03-25 10:27:59 -07:00
|
|
|
title="Push another screen"
|
|
|
|
/>
|
|
|
|
<Button
|
2018-05-23 13:18:35 -04:00
|
|
|
onPress={() => push('ScreenWithNoHeader')}
|
2018-03-25 10:27:59 -07:00
|
|
|
title="Push screen with no header"
|
|
|
|
/>
|
2018-05-23 13:18:35 -04:00
|
|
|
<Button onPress={() => pop()} title="Pop" />
|
2018-03-25 10:27:59 -07:00
|
|
|
<Button onPress={() => navigation.goBack(null)} title="Go back" />
|
|
|
|
<StatusBar barStyle="default" />
|
|
|
|
</SafeAreaView>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ScreenWithLongTitle extends React.Component<NavScreenProps> {
|
|
|
|
static navigationOptions = {
|
|
|
|
title: "Another title that's kind of long",
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { navigation } = this.props;
|
2018-05-23 13:18:35 -04:00
|
|
|
const { pop } = navigation;
|
|
|
|
invariant(pop, 'missing `pop` action creator for StackNavigator');
|
2018-03-25 10:27:59 -07:00
|
|
|
|
|
|
|
return (
|
|
|
|
<SafeAreaView style={{ paddingTop: 30 }}>
|
2018-05-23 13:18:35 -04:00
|
|
|
<Button onPress={() => pop()} title="Pop" />
|
2018-03-25 10:27:59 -07:00
|
|
|
<Button onPress={() => navigation.goBack(null)} title="Go back" />
|
|
|
|
<StatusBar barStyle="default" />
|
|
|
|
</SafeAreaView>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ScreenWithNoHeader extends React.Component<NavScreenProps> {
|
|
|
|
static navigationOptions = {
|
|
|
|
header: null,
|
|
|
|
title: 'No Header',
|
|
|
|
};
|
|
|
|
|
2018-02-16 12:41:59 -08:00
|
|
|
render() {
|
|
|
|
const { navigation } = this.props;
|
2018-05-23 13:18:35 -04:00
|
|
|
const { push, pop } = navigation;
|
|
|
|
invariant(push && pop, 'missing action creators for StackNavigator');
|
2018-02-16 12:41:59 -08:00
|
|
|
|
|
|
|
return (
|
2018-02-16 12:42:44 -08:00
|
|
|
<SafeAreaView style={{ paddingTop: 30 }}>
|
2018-05-23 13:18:35 -04:00
|
|
|
<Button onPress={() => push('Other')} title="Push another screen" />
|
|
|
|
<Button onPress={() => pop()} title="Pop" />
|
2018-02-16 12:41:59 -08:00
|
|
|
<Button onPress={() => navigation.goBack(null)} title="Go back" />
|
|
|
|
<StatusBar barStyle="default" />
|
|
|
|
</SafeAreaView>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-14 15:21:38 -07:00
|
|
|
const StackWithHeaderPreset = createStackNavigator(
|
2018-02-16 12:41:59 -08:00
|
|
|
{
|
|
|
|
Home: HomeScreen,
|
|
|
|
Other: OtherScreen,
|
2018-03-25 10:27:59 -07:00
|
|
|
ScreenWithNoHeader: ScreenWithNoHeader,
|
|
|
|
ScreenWithLongTitle: ScreenWithLongTitle,
|
2018-02-16 12:41:59 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
headerTransitionPreset: 'uikit',
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
export default StackWithHeaderPreset;
|