【发布时间】:2020-07-30 08:19:20
【问题描述】:
如果有人可以帮助我。 我确定我错过了一些东西,但我看不到它。我正在尝试在 3 个组件之间进行导航,并使用 react-navigation 页面中的文档创建它,我尝试了很多不同的方法来做它,但总是收到相同的答案,所以如果有人能看到我做的错误,请告诉我。
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import Header from './app/components/header/header'
import Main from './app/components/main/main';
import Data from './app/components/data/data';
import Grafic from './app/components/grafic/grafic';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import ButtonImage from './app/components/buttonImag/buttonImg'
import 'react-native-gesture-handler';
const Stack = createStackNavigator();
function MainScreen({ navigation }) {
return (
<ButtonImage onPress={() => navigation.navigate('Main')} heightV={40} widthV={40} itemImage={require('./app/resourse/home.png')} heightI={33} widthI={33} ></ButtonImage>
);
};
function DataScreen({ navigation }) {
return (
<ButtonImage onPress={() => navigation.navigate('Data')} heightV={40} widthV={40} itemImage={require('./app/resourse/datalist.png')} heightI={33} widthI={33} ></ButtonImage>
);
};
function GraficScreen({ navigation }) {
return (
<ButtonImage onPress={() => navigation.navigate('Grafic')} heightV={40} widthV={40} itemImage={require('./app/resourse/grafic.png')} heightI={33} widthI={33} ></ButtonImage>
);
};
const Footer = ({ navigation }) => {
return (
<View style={styles.header}>
<View style={styles.buttonPos}>
<MainScreen />
<DataScreen />
<GraficScreen />
</View>
</View>
)
};
function MyStack() {
return (
<Stack.Navigator>
<Stack.Screen name="Main" component={() => <Main />} />
<Stack.Screen name="Data" component={() => <Data />} />
<Stack.Screen name="Grafic" component={() => <Grafic />} />
</Stack.Navigator>
);
}
const App = () => {
return (
<View style={{ flex: 1 }}>
<Header />
<NavigationContainer>
<MyStack />
</NavigationContainer>
<Footer />
</View>
);
}
const styles = StyleSheet.create({
header: {
backgroundColor: "#00BFFF",
height: 55
},
buttonPos: {
flex: 1,
flexDirection: 'row',
alignItems: "center",
justifyContent: "space-between",
padding: 7
},
conection: {
flex: 1,
flexDirection: 'row',
alignItems: "center",
justifyContent: "space-between",
padding: 7
}
});
export default App
【问题讨论】:
-
欢迎,@Maksym Paranchych 加入 StackOverflow,我建议您将代码放在 ` ` ` 之后的下一行。另外,如果您使用 ` ` 提及您的代码语言,那就太好了。 (应该没有空格)。它将突出显示您的关键字。很高兴为 StackOverflow 做出贡献。
标签: react-native components react-navigation expo react-navigation-v5