我完全按照教程https://reactnavigation.org/docs/intro/ 但是标题没有显示。这是代码和结果
import Expo from 'expo';
import React from 'react';
import { StyleSheet, Text, View, Button } from 'react-native';
import {StackNavigator} from 'react-navigation';
class HomeScreen extends React.Component {
static navigationOptions = {
title: 'Welcome',
}
render() {
const {navigate} = this.props.navigation;
return (
<View style={styles.container}>
<Text>Open up main.js to start working on your app!</Text>
<Button onPress={()=>navigate('Chat',{user:'Lucy'})} title = 'Chat with Lucy'></Button>
</View>
);
}
}
class ChatScreen extends React.Component {
// Nav options can be defined as a function of the screen's props:
static navigationOptions = ({ navigation }) => ({
title: `Chat with ${navigation.state.params.user}`,
});
render() {
// The screen's current route is passed in to `props.navigation.state`:
const { params } = this.props.navigation.state;
return (
<View>
<Text>Chat with {params.user}</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
const SimpleApp = StackNavigator({
Home: {screen: HomeScreen},
Chat: {screen: ChatScreen}
})
Expo.registerRootComponent(SimpleApp);
另一个问题是,如果我只使用
static navigationOptions = {
title: 'Chat with Lucy',
};
然后,“欢迎”仍然在标记“<”旁边,这与教程不同。