class .....
static navigationOptions = {
header: null,
};
.....
}
https://stackoverflow.com/questions/44701245/hide-header-in-stack-navigator-react-navigation
<Stack.Navigator
screenOptions={{
headerShown: false,
}}
...
使用createStackNavigator來初始化該路由,然後用createBottomTabNavigator建立底部導航
const Login = ({ navigation }) => {
navigation.navigate('Main');
}
import React from 'react';
import { Button, View, Text } from 'react-native';
import { StackNavigator } from 'react-navigation'; // Version can be specified in package.json
class HomeScreen extends React.Component {
render() {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Home Screen</Text>
<Button
title="Go to Details"
onPress={() => this.props.navigation.navigate('Details')}
/>
</View>
);
}
}
class DetailsScreen extends React.Component {
render() {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Details Screen</Text>
<Button
title="Go to Details... again"
onPress={() => this.props.navigation.push('Details')}
/>
<Button
title="Go to Home"
onPress={() => this.props.navigation.navigate('Home')}
/>
<Button
title="Go back"
onPress={() => this.props.navigation.goBack()}
/>
</View>
);
}
}
const RootStack = StackNavigator(
{
Home: {
screen: HomeScreen,
},
Details: {
screen: DetailsScreen,
},
},
{
initialRouteName: 'Home',
}
);
export default class App extends React.Component {
render() {
return <RootStack />;
}
}
react-navigation listen on router change
1.
import { NavigationEvents } from "react-navigation";
render() {
return (
<View>
<NavigationEvents
onWillFocus={payload => console.log("will focus", payload)}
onDidFocus={payload => console.log("did focus", payload)}
onWillBlur={payload => console.log("will blur", payload)}
onDidBlur={payload => console.log("did blur", payload)}
/>
..........
onWillFocus={payload => console.log("will focus", payload)}
onDidFocus={payload => console.log("did focus", payload)}
這兩個有時要同時加才有反應