mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-02-09 17:23:18 +08:00
121 lines
3.3 KiB
TypeScript
121 lines
3.3 KiB
TypeScript
import * as React from 'react';
|
|
import { Button, StatusBar, StyleProp, ViewStyle } from 'react-native';
|
|
import { SafeAreaView } from 'react-navigation';
|
|
import {
|
|
createStackNavigator,
|
|
TransitionPresets,
|
|
HeaderStyleInterpolators,
|
|
NavigationStackScreenProps,
|
|
} from 'react-navigation-stack';
|
|
|
|
class HomeScreen extends React.Component<NavigationStackScreenProps> {
|
|
static navigationOptions = {
|
|
title: 'Welcome',
|
|
};
|
|
|
|
render() {
|
|
const { navigation } = this.props;
|
|
const { push } = navigation;
|
|
|
|
return (
|
|
<SafeAreaView style={{ paddingTop: 30 }}>
|
|
<Button onPress={() => push('Other')} title="Push another screen" />
|
|
<Button
|
|
onPress={() => push('ScreenWithNoHeader')}
|
|
title="Push screen with no header"
|
|
/>
|
|
<Button onPress={() => navigation.goBack(null)} title="Go Home" />
|
|
<StatusBar barStyle="default" />
|
|
</SafeAreaView>
|
|
);
|
|
}
|
|
}
|
|
|
|
class OtherScreen extends React.Component<NavigationStackScreenProps> {
|
|
static navigationOptions = {
|
|
title: 'Your title here',
|
|
};
|
|
|
|
render() {
|
|
const { navigation } = this.props;
|
|
const { push, pop } = navigation;
|
|
|
|
return (
|
|
<SafeAreaView style={{ paddingTop: 30 }}>
|
|
<Button
|
|
onPress={() => push('ScreenWithLongTitle')}
|
|
title="Push another screen"
|
|
/>
|
|
<Button
|
|
onPress={() => push('ScreenWithNoHeader')}
|
|
title="Push screen with no header"
|
|
/>
|
|
<Button onPress={() => pop()} title="Pop" />
|
|
<Button onPress={() => navigation.goBack(null)} title="Go back" />
|
|
<StatusBar barStyle="default" />
|
|
</SafeAreaView>
|
|
);
|
|
}
|
|
}
|
|
|
|
class ScreenWithLongTitle extends React.Component<NavigationStackScreenProps> {
|
|
static navigationOptions = {
|
|
title: "Another title that's kind of long",
|
|
};
|
|
|
|
render() {
|
|
const { navigation } = this.props;
|
|
const { pop } = navigation;
|
|
|
|
return (
|
|
<SafeAreaView style={{ paddingTop: 30 }}>
|
|
<Button onPress={() => pop()} title="Pop" />
|
|
<Button onPress={() => navigation.goBack(null)} title="Go back" />
|
|
<StatusBar barStyle="default" />
|
|
</SafeAreaView>
|
|
);
|
|
}
|
|
}
|
|
|
|
class ScreenWithNoHeader extends React.Component<NavigationStackScreenProps> {
|
|
static navigationOptions = {
|
|
title: 'No Header',
|
|
headerShown: false,
|
|
};
|
|
|
|
render() {
|
|
const { navigation } = this.props;
|
|
const { push, pop } = navigation;
|
|
|
|
return (
|
|
<SafeAreaView style={{ paddingTop: 30 }}>
|
|
<Button onPress={() => push('Other')} title="Push another screen" />
|
|
<Button onPress={() => pop()} title="Pop" />
|
|
<Button onPress={() => navigation.goBack(null)} title="Go back" />
|
|
<StatusBar barStyle="default" />
|
|
</SafeAreaView>
|
|
);
|
|
}
|
|
}
|
|
|
|
const StackWithHeaderPreset = createStackNavigator(
|
|
{
|
|
Home: HomeScreen,
|
|
Other: OtherScreen,
|
|
ScreenWithNoHeader: ScreenWithNoHeader,
|
|
ScreenWithLongTitle: ScreenWithLongTitle,
|
|
},
|
|
{
|
|
headerMode: 'float',
|
|
defaultNavigationOptions: {
|
|
...TransitionPresets.SlideFromRightIOS,
|
|
headerStyleInterpolator: HeaderStyleInterpolators.forUIKit,
|
|
// @ts-ignore
|
|
headerTitleContainerStyle: { left: null } as StyleProp<ViewStyle>,
|
|
gestureEnabled: true,
|
|
},
|
|
}
|
|
);
|
|
|
|
export default StackWithHeaderPreset;
|