我已经开始学习 React Native。
我有一个简单的应用程序并开始添加导航。
我正在尝试创建一个游戏,并且想在屏幕之间导航。代码可以运行,但是应用程序顶部有一个栏。
App.js
import React from 'react';
import { NavigationContainer } from '@react-navigation/native'; // Only here
import { createStackNavigator } from '@react-navigation/stack';
import MenuScreen from './MenuScreen';
import GameScreen from './GameScreen';
import SettingsScreen from './SettingsScreen';
const Stack = createStackNavigator();
const App = () => {
return (
<Stack.Navigator initialRouteName="Menu">
<Stack.Screen name="Menu" component={MenuScreen} />
<Stack.Screen name="GameScreen" component={GameScreen} />
<Stack.Screen name="SettingsScreen" component={SettingsScreen} />
</Stack.Navigator>
);
};
export default App;
菜单屏幕
import React from 'react';
import { View, Text, Button, StyleSheet } from 'react-native';
const MenuScreen = ({ navigation }) => {
return (
<View style={styles.container}>
<Text style={styles.title}>Game Menu</Text>
<Button title="Play" onPress={() => navigation.navigate('GameScreen')} />
<Button title="Settings" onPress={() => navigation.navigate('SettingsScreen')} />
<Button title="Exit" onPress={() => console.log('Exit Game')} />
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#282c34',
},
title: {
fontSize: 30,
color: '#ffffff',
marginBottom: 20,
fontWeight: 'bold',
},
});
export default MenuScreen;
我该如何删除它?
如果不可能,我应该用什么来替代?